{{{
def test():
"""test tests something.
"""
}}}
and this cause an error:
{{{
Error in "default-role" directive:
no content permitted.
.. default-role:: cmsreference
}}}
The culprit is this code in `trim_docstring`:
{{{
indent = min(len(line) - len(line.lstrip()) for line in lines if
line.lstrip())
}}}
The problem is that the indentation of the first line is 0.
The solution is to skip the first line:
{{{
indent = min(len(line) - len(line.lstrip()) for line in lines[1:] if
line.lstrip())
}}}
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/30255>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
Confirmed the patch fixes the issue, although it crashes for some tests
with `ValueError: min() arg is an empty sequence`.
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:1>
Comment (by Simon Charette):
We should probably just switch to `inspect.cleandoc` as
[https://docs.python.org/3/library/inspect.html#inspect.cleandoc it
implements] the algorithm [https://www.python.org/dev/peps/pep-0257
/#handling-docstring-indentation defined in PEP257].
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:2>
Comment (by Manlio Perillo):
Replying to [comment:1 Tim Graham]:
> Confirmed the patch fixes the issue, although it crashes for some tests
with `ValueError: min() arg is an empty sequence`.
Yes, I also found it yesterday. The simple solution is:
{{{
indent = min((len(line) - len(line.lstrip()) for line in lines[1:] if
line.lstrip()), default=0)
}}}
The `default` argument was added in Python 3.4, so it is safe to use in
Django.
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:3>
Comment (by tapaswenipathak):
Hello folks: Can I PR?
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:4>
* owner: nobody => Hasan Ramezani
* status: new => assigned
Comment:
I can not reproduce on:
* Python=3.7
* django=master
* docutils=0.15.2
@Manlio Perillo, Could you please help me? I am wrong?
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:5>
* cc: Markus Zapke-Gründemann (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:6>
Comment (by Hasan Ramezani):
@Manlio Perillo,
I couldn't reproduce this bug.
Could you please provide more information about this bug?
Python version, docutils version?
It would be good to have a model definition or test case.
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:7>
* has_patch: 0 => 1
* version: 2.1 => 3.0
Comment:
After a bit of trial and error, I finally managed to reproduce the issue
on current master with an up-to-date version of `docutils`.
The trick was to use a docstring like this: `"firstline\n\n second
line"` and not the one mentioned in the original report.
I took Simon's suggestion from comment 2 and removed `trim_docstring` in
favor of `inspect.cleandoc` and it fixes the issue.
[https://github.com/django/django/pull/12155 PR here]
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:8>
* owner: Hasan Ramezani => Baptiste Mispelon
* version: 3.0 => master
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:9>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"f47ba7e78033f39742c3bf491e9b15365cefd0db" f47ba7e]:
{{{
#!CommitTicketReference repository=""
revision="f47ba7e78033f39742c3bf491e9b15365cefd0db"
Fixed #30255 -- Fixed admindocs errors when rendering docstrings without
leading newlines.
Used inspect.cleandoc() which implements PEP-257 instead of an internal
hook.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30255#comment:10>