Rewrite unparse to use ast.NodeVisitor#7497
Merged
tk0miya merged 2 commits intosphinx-doc:3.xfrom May 7, 2020
Merged
Conversation
e28a3ee to
5c0c289
Compare
eric-wieser
commented
Apr 17, 2020
| def visit_List(self, node): | ||
| return "[" + ", ".join(self.visit(e) for e in node.elts) + "]" | ||
|
|
||
| def unparse_arguments(node: ast.arguments) -> str: |
Contributor
Author
There was a problem hiding this comment.
Diff here is mostly just an extra level of indent, I'd recommend checking the "ignore whitespace" box to review.
e01d821 to
adb5a95
Compare
This should make it possible to reuse the same visitor to generate RST code.
This will make it easier to remove them all at once in future
adb5a95 to
11ff920
Compare
Contributor
Author
|
Had a bit of a fight with mypy, but CI now passes. |
tk0miya
requested changes
Apr 18, 2020
| else: | ||
| raise NotImplementedError('Unable to parse %s object' % type(node).__name__) | ||
|
|
||
| if sys.version_info < (3, 8): |
Member
There was a problem hiding this comment.
IMO, it would be better to move such online-patch codes to the bottom of the class definition. In addition, it would be better to sort methods alphabetically.
Contributor
Author
There was a problem hiding this comment.
I was trying to keep them in the same order as before. Happy to alphabetize though.
Member
|
Remind: I will merge this after 1) conflicts resolved and 2) methods are sorted. Not in a hurry. Please update if you have enough time. |
Contributor
Author
|
Thanks for taking over. I'll see if I can rebase my follow-up work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should make it possible to reuse the same visitor to generate RST code.
Follows on from #7494
This is just a refactoring, motivated by:
List[docutils.Node]instead ofstr(patch in the works)selfso as to keep track of the current precedence level (sphinx.pycode.ast.unparse does not understand operator precedence #7498)