-
Notifications
You must be signed in to change notification settings - Fork 163
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
Parse mypy type comments #220
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to remove the command line option and simply parse the type comments if the ast module of the Python interpreter supports them. I'll do a detailed review once this is changed.
Now that I look around, I see flake8 complains about bad type comments by default, without any obvious option to disable that. I'll go ahead and make the proposed change. Originally, I decided to mirror the logic in https://bugs.python.org/issue35766 (the PR that added type_comments to ast.parse)
That said, I imagine vulture does not need to be as careful as the standard library with regards to backwards compatibility. |
Done! I've made it automatically gate on Python 3.8+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! I would have expected that we need much more code for this feature :-) I only have some small nitpicks.
This prevents type-only imports from being flagged as unused. Implementation decision note: As typed_ast will not be updated to support parsing Python 3.8+ syntax, I'm choosing not to use it. The downside of using Python's built-in type comment support is that it requires Python 3.8+. Someone more motivated than me could potentially make vulture use both, but I don't feel it's worth the complexity/effort given typed_ast seems likely to eventually die. Fixes jendrikseipp#152 See also jendrikseipp#153
Thanks a lot for your work on this! |
Apologies for being the PR necromancer; what was the rationale behind only enabling this for py3.8+? Especially given 3.6+ supports typing (and was introduced in the now EOL 3.5)? I didnt want to raise a new issue, if there was a good reason for it. Thanks! |
Please see the issue description for the reasoning. In short: we don't think that the extra work is worth it. |
Description
This prevents type-only imports from being flagged as unused.
Implementation decision note: As typed_ast will not be updated to support parsing Python 3.8+ syntax, I'm choosing not to use it. The downside of using Python's built-in type comment support is that it requires Python 3.8+. Someone more motivated than me could potentially make vulture use both, but I don't feel it's worth the complexity/effort given typed_ast seems likely to eventually die.
Related Issue
Fixes #152
See also #153
Checklist: