-
Notifications
You must be signed in to change notification settings - Fork 52
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 and function has the focus #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.79% 92.85% +0.05%
==========================================
Files 47 47
Lines 8468 8588 +120
Branches 1550 1578 +28
==========================================
+ Hits 7858 7974 +116
- Misses 350 353 +3
- Partials 260 261 +1 ☔ View full report in Codecov by Sentry. |
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.
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.
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.
According to pydoctor_primer, this change doesn't affect pydoctor warnings on a corpus of open source code. ✅ |
@@ -997,7 +976,7 @@ def colorized_pyval_fallback(_: List[ParseError], doc:ParsedDocstring, __:model. | |||
""" |
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.
Looks like this docstring is wrong
|
||
if param.default is not _empty: | ||
if param.annotation is not _empty: | ||
# TODO: should we keep these two different manners ? |
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
According to pydoctor_primer, this change doesn't affect pydoctor warnings on a corpus of open source code. ✅ |
This would need a review. I don’t know how to get this done other than asking you directly @glyph. It’s been a while that I’m waiting… |
@tristanlatr sorry for the delay, it'll probably be a few more days (pydoctor reviews are extra hard, in addition to having limited time!) but these are on my to-do list. |
Thanks for your message @glyph, please take your time. It's good to see that it's in the todo list of someone somewhere already. I'm sorry if this PR comes with rather a few refactors... I could try to split it up... Tell me if that would help you. Thanks |
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 do wish I understood this code a bit better, but the type checker is doing some good heavy lifting assuaging my concerns :). The new style looks great, and I look forward to deploying this. Thanks!
@@ -297,4 +297,4 @@ class ExamplePEP526Class: | |||
""" | |||
|
|||
attr1: str | |||
attr2: int | |||
attr2: int |
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.
Is this change intentional?
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.
No I don’t think so…
|
||
@property | ||
def has_body(self) -> bool: | ||
return any(e.has_body for e in self._elements) |
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.
Huh, why the coverage gap on these properties?
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.
Because has_body is only used at one place: in the properties documentation processing. And properties don’t have this kind of parsed docstring. But I can always add a small test to cover that branch.
def colorize_pyval(pyval: Any, linelen:Optional[int], maxlines:int, | ||
linebreakok:bool=True, refmap:Optional[Dict[str, str]]=None, | ||
is_annotation: bool = False) -> ColorizedPyvalRepr: |
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.
should we be adopting Black so that this sort of style change doesn't require discretion? :)
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.
""" | ||
#TODO: Fix this soon |
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.
Link to an issue?
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.
# some ParsedDocstring subclass raises NotImplementedError on calling to_node() | ||
# Like ParsedPlaintextDocstring. | ||
doc = source.docstring | ||
doc = ob.parsed_docstring.to_text() |
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.
lovely to see an ugly too-broad try
like this go away :)
Co-authored-by: Glyph <[email protected]>
According to pydoctor_primer, this change doesn't affect pydoctor warnings on a corpus of open source code. ✅ |
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.
@@ -253,8 +253,15 @@ ul ul ul ul ul ul ul { | |||
|
|||
/* Argument name + type column table */ | |||
.fieldTable tr td.fieldArgContainer { |
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.
.fieldTable tr td.fieldArgContainer { | |
.fieldTable tr td.fieldArgContainer { | |
width: 325px; |
/* It not seems to work with percentage values | ||
so I used px values, these are just indications for the | ||
CSS auto layout table algo not to create tables | ||
with rather unbalanced columns width. */ | ||
max-width: 400px; | ||
} | ||
.fieldTable tr td.fieldArgDesc { | ||
max-width: 600px; |
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 not seems to work with percentage values | |
so I used px values, these are just indications for the | |
CSS auto layout table algo not to create tables | |
with rather unbalanced columns width. */ | |
max-width: 400px; | |
} | |
.fieldTable tr td.fieldArgDesc { | |
max-width: 600px; |
.fieldTable{ | ||
table-layout: fixed; | ||
} | ||
/* Argument name + type column table */ | ||
.fieldTable tr td.fieldArgContainer { | ||
width: 34%; | ||
} |
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.
.fieldTable{ | |
table-layout: fixed; | |
} | |
/* Argument name + type column table */ | |
.fieldTable tr td.fieldArgContainer { | |
width: 34%; | |
} |
#childList a:target ~ .functionBody{ | ||
background-color: transparent; | ||
box-shadow: none; | ||
box-shadow: 7px 1px 0px 3px rgb(253 255 223), -36px 1px 0px 3px rgb(253 255 223); |
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.
box-shadow: 7px 1px 0px 3px rgb(253 255 223), -36px 1px 0px 3px rgb(253 255 223); | |
background-color: transparent; | |
box-shadow: none; |
@@ -320,24 +333,13 @@ ul ul ul ul ul ul ul { | |||
#splitTables > table tr td:nth-child(2) { | |||
width: 160px; | |||
} |
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.
} | |
} | |
/* Argument name + type column table */ | |
.fieldTable tr td.fieldArgContainer { | |
width: 170px; | |
} | |
.fieldTable { | |
table-layout: fixed; | |
} |
@@ -328,6 +420,20 @@ def switch_context(self, ob:Optional['Documentable']) -> ContextManager[None]: | |||
in this case error will NOT be reported at all. | |||
""" | |||
|
|||
class NotFoundLinker(DocstringLinker): |
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 NotFoundLinker is already present in linker.py no need to have it here
@@ -297,4 +297,4 @@ class ExamplePEP526Class: | |||
""" | |||
|
|||
attr1: str | |||
attr2: int | |||
attr2: int |
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.
No I don’t think so…
""" | ||
#TODO: Fix this soon |
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.
def colorize_pyval(pyval: Any, linelen:Optional[int], maxlines:int, | ||
linebreakok:bool=True, refmap:Optional[Dict[str, str]]=None, | ||
is_annotation: bool = False) -> ColorizedPyvalRepr: |
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.
|
||
@property | ||
def has_body(self) -> bool: | ||
return any(e.has_body for e in self._elements) |
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.
Because has_body is only used at one place: in the properties documentation processing. And properties don’t have this kind of parsed docstring. But I can always add a small test to cover that branch.
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:
The way to get the old behaviour back is to use the following custom css: