Closes #9418: Fix missing bracket for empty Callable annotations. #9427
+11
−4
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.
Subject: Fix missing bracket for empty Callable annotations. This solves issue #9418
Feature or Bugfix
Purpose
Callable
type annotation, the output is missing a bracket if theCallable
requires no parameters (the first element is empty):Callable[[], None]
is rendered asCallable[], None]
.Detail
When unparsing a parsed annotation containing an
ast.List
object, the following pseudo-code is run: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 ofresult
.Relates