-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
e4b038f
to
f3556bb
Compare
f3556bb
to
8e2b7b0
Compare
What observable behavior does this change? I'm worried it'll just lead to more crashes with an inconsistent AST (though maybe those are crashes we want to happen). |
Not 100 percent sure, but when python is >= 3.8 it's behaving differently. Lines 6468 to 6473 in 8e2b7b0
|
That makes it look like this PR just makes us parse type comments we're ignoring anyway. |
If type comments are ignored, why does python 3 - 3.7 use typed-ast? Why not just use normal ast? I'm assuming that typed-ast is required for parsing python2 code. |
If type comments are ignored then we should refactor the code that uses typed_ast for Python3 to use ast module instead. |
One such refactoring of the parsing code is currently going on in #2304. Got to say, I'm not so sure why |
So okay, looks like this PR is stuck.
Because unfortunately the built-in
https://docs.python.org/3/library/ast.html#ast.parse
True, but also needed below 3.8 to maintain compatibility with more grammars than the one of the runtime. So unless the safety checks stop ignoring TypeIgnore instances, I don't think there's anything actionable here. Although I don't have much context on why we ignore those TypeIgnore in the first place. |
I think if we want to be safer with type comments, this could be an option. But then again, we have no such guarantees for other special comments. I'm quite indifferent about this, but personally now that the reasons for using typed vs. builtin ast are laid out, I'd rather have nice-looking code than correctly-typed code. Especially now that there is much more support for other types of annotations than comments. And brainstorming: maybe we could warn when we move a type comment 🤔 |
Sounds like there is no clear rationale for this change, so I'm going to default to not changing anything. |
ast.parse
doesn't parse type comments by default. This PR enables this option.reference