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

Use type_comments when parsing AST #2165

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
@@ -1,5 +1,11 @@
## Change Log

### Unreleased

#### _Black_

- Parse type comments when using ast module (#2165)

### 21.4b2

#### _Black_
Expand Down
7 changes: 6 additions & 1 deletion src/black/__init__.py
Expand Up @@ -6416,7 +6416,12 @@ def parse_ast(src: str) -> Union[ast.AST, ast3.AST, ast27.AST]:
# TODO: support Python 4+ ;)
for minor_version in range(sys.version_info[1], 4, -1):
try:
return ast.parse(src, filename, feature_version=(3, minor_version))
return ast.parse(
src,
filename,
feature_version=(3, minor_version),
type_comments=True,
)
except SyntaxError:
continue
else:
Expand Down