Skip to content

Commit

Permalink
use type_comments with ast.parse
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Apr 29, 2021
1 parent b39999d commit f3556bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit f3556bb

Please sign in to comment.