-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Added parsing of ignore annotation for import statements. #503
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
Conversation
return None | ||
try: | ||
annotation, index = parse_annotation(tokens, 0) | ||
except TypeParseError as e: |
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.
Should this refer to AnnotationParseError?
Cool, thanks for implementing this! A few notes:
I'm going to consider this as an experimental feature, since this feature hasn't received much discussion yet. However, a feature like this is probably going to be almost essential. |
@@ -33,7 +33,8 @@ | |||
from mypy.parsetype import ( | |||
parse_type, parse_types, parse_signature, TypeParseError | |||
) | |||
|
|||
from mypy.annotations import Annotation, IgnoreAnnotation | |||
from mypy.parseannotation import parse_annotation | |||
|
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.
Missing empty line
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.
Good to see that I'm not the only one who cares about theses things 😄
I'd forgotten about |
Actually, it doesn't seem necessary to define those imported symbols with type There still an open issue. Annotations after all other statements are ignored. That doesn't seem like a big deal to me since, but it might be confusing. Since this is indeed an experimental feature, I propose to leave that for what it is. |
Yeah, we should definitely complain about annotations in unsupported contexts. We can address that later. I'm going to play around with this a little and think this through before merging, but this is probably okay as long we clearly document that this is an experimental feature that hasn't been fully implemented and that may be changed in the future. |
Let's wait and see if PEP 484 will pick a notation for this: python/typing#16 |
I did a more general implementation of this functionality (the magic comment is |
This implements @JukkaL's suggestion of adding
# mypy: ignore
annotations in #500.In this PR, only ignore annotations on import statements are allowed, but I think it would be easily extendable to other statements as well. Every statement
Node
could have anannotations
field that could be used during semantic analysis or type checking.