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

Closes #9418: Fix missing bracket for empty Callable annotations. #9427

Closed

Conversation

thjungers
Copy link

Subject: Fix missing bracket for empty Callable annotations. This solves issue #9418

Feature or Bugfix

  • Bugfix

Purpose

  • When rendering a Callable type annotation, the output is missing a bracket if the Callable requires no parameters (the first element is empty): Callable[[], None] is rendered as Callable[], None].

Detail

When unparsing a parsed annotation containing an ast.List object, the following pseudo-code is run:

result.append('[')
for elem in node.elts:
    result.append(elem)
    result.append(', ')
result.pop()
result.append(']')

The last element (the extra comma) is popped. However, if the ast.List object is empty, the for-loop is skipped and the popped element is the opening [.
An if-condition was added to check whether node.elts is empty before popping the last element of result.

Relates

tk0miya added a commit that referenced this pull request Jul 10, 2021
@tk0miya tk0miya added this to the 4.1.0 milestone Jul 10, 2021
@tk0miya
Copy link
Member

tk0miya commented Jul 10, 2021

Merge this manually into the 4.x branch now.
Thank you for your contribution!

@tk0miya tk0miya closed this Jul 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
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.

None yet

2 participants