New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Fix autosummary of members with a trailing underscore #3585
Conversation
@@ -194,7 +194,8 @@ The following variables available in the templates: | |||
|
|||
.. data:: underline | |||
|
|||
A string containing ``len(full_name) * '='``. | |||
A string containing ``len(full_name) * '='``. Use the ``underline`` filter | |||
instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to stay here for backwards-compatibility, but it's useless when using | escape
@@ -1,5 +1,4 @@ | |||
{{ fullname }} | |||
{{ underline }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The takeaway here is that all user code that overrides these templates will need to make this change too in order to actually fix the bug. But that's unavoidable.
Either way, this PR will not change how old code behaves.
|
||
title = etree_parse(docpage).find('section/title') | ||
|
||
assert str_content(title) == 'underscore_module_' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this patch, this would lose the trailing underscore.
sphinx/ext/autosummary/generate.py
Outdated
def _underline(title, line='='): | ||
if '\n' in title: | ||
raise ValueError('Can only underline single lines') | ||
return title + '\n' + line*len(title) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use docutils.utils.column_width()
instead of len()
?
It supports east asian width. They can use character having multiple widths for module name. So it's important for asian users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't use that in apidoc
either. Fixing it there, here, and elsewhere sounds like something for a separate PR, that also adds tests for these things.
Note that we already just use len
in the underscore
variable, so doing the same here isn't a regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can python modules have names containing these characters, or is that forbidden? If so, someone who knows more about using asian characters should patch this and apidoc
, and add a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you can use east asian characters for python modules.
# main.py
import テスト
テスト.関数('Sphinx')
# テスト.py
def 関数(名前):
print('Hello ' + 名前)
Okay, I will do it in another ticket.
|
||
# replace the builtin html filters | ||
template_env.filters['escape'] = rst_escape | ||
template_env.filters['e'] = rst_escape |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this is secret (undocumented) feature now. So please remove this or add document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the {{ | e}}
filter? That's native to Jinja, and is documented there as an alias of {{ | escape}}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a link to the jinja docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
It seems Mr. flake8 warns to us. Could you check them please?
|
flake8 fixed, despite not really agree with the |
@tk0miya: Does this need anything else? |
Thanks! |
Follows on from #3581. It turns out that lots of different code generates rst files.
This PR includes a test that previously failed, and is causing problems in numpy/numpy#6769