Skip to content
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

Remove extra space from the unparser #10551

Merged
merged 9 commits into from Jun 16, 2022

Conversation

AA-Turner
Copy link
Member

Fixes #10550

@WarrenWeckesser / @choldgraf -- please would you be able to test this PR to check it works?

Feature or Bugfix

  • Bugfix

A

@AA-Turner AA-Turner self-assigned this Jun 14, 2022
@AA-Turner AA-Turner added this to the 5.1.0 milestone Jun 14, 2022
@AA-Turner AA-Turner requested a review from tk0miya June 14, 2022 09:27
sphinx/pycode/ast.py Outdated Show resolved Hide resolved
@WarrenWeckesser
Copy link

I won't be able to test this with any of the big projects listed in gh-10550, but I just tried it with a personal project, with the parameter foo=-1 added to a function. The problem occurs with the 5.x branch, and it is fixed with this PR. 👍

sphinx/pycode/ast.py Outdated Show resolved Hide resolved
Copy link
Member

@tk0miya tk0miya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits.

@AA-Turner
Copy link
Member Author

@tk0miya updated!

A

@@ -202,7 +202,10 @@ def is_simple_tuple(value: ast.AST) -> bool:
return "%s[%s]" % (self.visit(node.value), self.visit(node.slice))

def visit_UnaryOp(self, node: ast.UnaryOp) -> str:
return "%s %s" % (self.visit(node.op), self.visit(node.operand))
# UnaryOp is one of {UAdd, USub, Invert, Not}. Only Not needs a space.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding examples here makes the comment clearer:

Suggested change
# UnaryOp is one of {UAdd, USub, Invert, Not}. Only Not needs a space.
# UnaryOp is one of {UAdd, USub, Invert, Not}, which correspond
# respectively to `+x`, `-x`, `~x`, and `not x`. Only Not needs a space.

@choldgraf
Copy link
Contributor

Maybe @tupui would be willing to try re-building the SciPy docs with this PR branch to see if it fixes it there. The PyData Theme Docs don't have any API docs that use the -1 thing so I am not sure how to test it locally. The fix looks reasonable to me though! (assuming that it is true that "Only Not needs a space", I will take that for granted as you all know more about it than I do :-)

@AA-Turner
Copy link
Member Author

Thanks Ezio, added a test of :py:function: and expanded the comment.

A

@@ -141,6 +141,9 @@ def visit_Attribute(self, node: ast.Attribute) -> str:
return "%s.%s" % (self.visit(node.value), node.attr)

def visit_BinOp(self, node: ast.BinOp) -> str:
# Special case ``**`` to now have surrounding spaces.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Special case ``**`` to now have surrounding spaces.
# Special case ``**`` to not have surrounding spaces.

@tupui
Copy link

tupui commented Jun 15, 2022

I can confirm for SciPy, it would work. Thanks!

See -inf

Old:
old

New:
new

CHANGES Outdated Show resolved Hide resolved
Co-authored-by: Takeshi KOMIYA <i.tkomiya@gmail.com>
@tk0miya tk0miya merged commit 1031175 into sphinx-doc:5.x Jun 16, 2022
@tk0miya
Copy link
Member

tk0miya commented Jun 16, 2022

Thanks!

@AA-Turner AA-Turner deleted the fix-extra-whitespace branch June 16, 2022 22:22
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spurious space in default parameter values that are negative numbers in HTML output.
6 participants