-
Notifications
You must be signed in to change notification settings - Fork 51
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
Wrap signatures onto several lines when function len is over a treshold #831
base: master
Are you sure you want to change the base?
Conversation
…ill help to construct one parsed docstring from several parts.
We mimic the Signature.__str__ method for the implementation but instead of returning a str we return a ParsedDocstring, which is far more convenient. This change fixes #801: - Parameters html are divided into .sig-param spans. - When the function is long enought an extra CSS class .expand-signature is added to the parent function-signature. - The first parameter 'cls' or 'self' of (class) methods is marked with the 'undocumented' CSS class, this way it's clearly not part of the API. - Add some CSS to expand the signature of long functions when they have the focus only.
This comment has been minimized.
This comment has been minimized.
…miza a little the _colorize_signature() function.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #831 +/- ##
==========================================
+ Coverage 92.29% 92.35% +0.05%
==========================================
Files 47 47
Lines 8514 8629 +115
Branches 1695 1725 +30
==========================================
+ Hits 7858 7969 +111
- Misses 385 387 +2
- Partials 271 273 +2 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
This comment has been minimized.
This comment has been minimized.
… docstrings they only update the local to_stan() method dynamically.
…w parsed docstrings they only update the local to_stan() method dynamically." This reverts commit eca5ced.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…class. Introduce ParsedDocstring.to_text().
…s when overloads are overwhelming... This probably requires some more tweaks but it's still better than showing everything at once.
This comment has been minimized.
This comment has been minimized.
…t try to do such things either...
This comment has been minimized.
This comment has been minimized.
Fix some cyclic imports issue as a drive-by change: model.Documentable was uncessarly runtime imported inside restructuredtext and epydoc parsers.
also remove the summary caching on the parsed docstring side, this is unnecessary because it's already cahed in the documentable.
This comment has been minimized.
This comment has been minimized.
…of a string. A some annotation.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…nnotation is ambiguous (pydoctor is not a checker). Get rid of ParsedDocstring.with_linker() this API did not make sens and was rather an anti-pattern. Replace that with a new parameter of colorize_pyval(is_annotation: bool). obj_reference nodes can now be created with the attribute 'is_annotation' in which case they will be resolved a little bit differently.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…o 801-signature-spans
This comment has been minimized.
This comment has been minimized.
According to pydoctor_primer, this change doesn't affect pydoctor warnings on a corpus of open source code. ✅ |
pydoctor/test/test_astbuilder.py
Outdated
doc = get_parsed_signature(func) | ||
assert doc | ||
fromhtml = flatten_text(format_signature(func)) | ||
fromdocutils = ''.join(node2stan.gettext(doc.to_node())) |
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.
fromdocutils = ''.join(node2stan.gettext(doc.to_node())) | |
fromdocutils = doc.to_text() |
pydoctor/epydoc/markup/__init__.py
Outdated
stan(e.to_stan(linker).children) | ||
return stan | ||
|
||
class WrappedParsedDocstring(ParsedDocstring): |
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.
class WrappedParsedDocstring(ParsedDocstring): | |
class _WrappedParsedDocstring(ParsedDocstring): |
self._doc = self._generate_document(self._elements) | ||
return self._doc | ||
|
||
def to_stan(self, linker: DocstringLinker) -> Tag: |
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.
Maybe cache the stan here as well.
word-break: break-word; | ||
/* It not seems to work with percentage values | ||
so I used px values, these are just indications for the | ||
CSS auto layour table algo not to create tables |
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.
CSS auto layour table algo not to create tables | |
CSS auto layout table algo not to create tables |
#childList a:target ~ .functionHeader .function-signature.long-signature .sig-param, | ||
#childList a:target ~ .functionHeader .function-signature.long-signature .sig-symbol { | ||
display: block; | ||
margin-left: 1.5em; | ||
padding-left: 1.5em; | ||
text-indent: -1.5em; | ||
} | ||
/* Except the 'self' or 'cls' params, which are rendered on the same line as the function def */ | ||
#childList a:target ~ .functionHeader .function-signature.long-signature .sig-param:has(.undocumented) { | ||
display: initial; | ||
margin-left: 0; | ||
padding-left: 0; | ||
} |
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 way to get the old behaviour back is to use the following custom css:
.sig-param, .sig-symbol {
display: initial !important;
margin-left: 0 !important;
padding-left: 0 !important;
}
""" | ||
Format a link to a Python identifier. | ||
This will resolve the identifier like Python itself would. | ||
|
||
@param target: The name of the Python identifier that | ||
should be linked to. | ||
@param label: The label to show for the link. | ||
@param is_annotation: Generated links will give precedence to the module | ||
defined varaible rather the nested definitions when there are name colisions. |
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.
defined varaible rather the nested definitions when there are name colisions. | |
defined variables rather the nested definitions when there are name collisions. |
set_node_attributes(document, children=[txt_node]) | ||
return ParsedRstDocstring(document, ()) | ||
|
||
# not using cache here because we need new span tag for every call |
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.
# not using cache here because we need new span tag for every call |
return ParsedRstDocstring(document, ()) | ||
|
||
# not using cache here because we need new span tag for every call | ||
# othewise it messes-up everything. |
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.
# othewise it messes-up everything. |
has_next: bool, | ||
is_first: bool, ) -> ParsedDocstring: | ||
""" | ||
One parameter is converted to a series of ParsedDocstrings. |
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 docstring is untrue and should be rephrased and put as a comment instead. This is arguably an implementation detail.
fallback=epydoc2stan.colorized_pyval_fallback, | ||
section='rendering of class signature') | ||
r.extend(stan.children) | ||
|
||
r.append(')') | ||
return r | ||
|
||
LONG_SIGNATURE = 120 # this doesn't acount for the 'def ' and the ending ':' |
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 question is should we provide yet another CLI option to customize the threshold from which a function def is considered long?
120 chars might sounds like a good heuristic. But what if the function is overloaded and has 15 parameters for each overload? This behavior suddenly becomes worse than before since users will have to scroll down a lot more to get to the core of the docstring… an idea would be to yet have a third presentation when the function def length it’s more than, say, 8 times a long function (960 chars): in this scenario, the signatures are not wrapped into separate lines automatically and a button is added to toofle the line wrapping
This change fixes #801 as well as introduce a rather a lot of refactoring and new ParsedDocstring features.
Signature.__str__()
, which we don't need anymore because we're computing the representation ourselve.Examples: