-
-
Notifications
You must be signed in to change notification settings - Fork 3k
mypy cannot parse type comment of "with" and "for" statement in PEP 484 #892
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
Comments
Not supporting type comments of anything other than a function (is that even in the PEP?) or assignment is a known bug. I'm currently rewriting the parser (to track location information better and give better errors) but haven't gotten to type comments yet. Ugh, since when are tuples of types directly supported? I know it's given in an example in the PEP, but it doesn't specify this stuff at all. @gvanrossum What are we supposed to do about an unclear PEP? |
I ran into this today and have resorted to using with cast(BinaryIO, open(path, 'rb')) as fp:
# use fp... That makes the work-around nicely localized. |
Since this is specified in PEP 484, mypy should support it. But it's not high priority. |
The WIP fast parser (#1353) supports parsing types on |
Moving to 0.5.0 given we aren't very far with the fast parser yet and this feels pretty unimportant. |
(This is still TODO; we parse those type comments but don't use them.) |
How would type comments work with multiple targets in with X as (x, y), Z as (z, w): # type: ...? Would the type comment be of the form It's a bit complicated by the fact that when parsing, this is read as two distinct targets (each of which has a tuple type), so maybe |
Maybe like this: with X as (a, b): # type: Tuple[int, float]
...
with X as (a, b), Y as (c, d): # type Tuple[int, float], Tuple[str, str]
... This may be tricky because IIRC the |
I think this should work okay for the new parser, actually. |
I tried to check type comments, but it cannot parse "with" and "for" statement as below.
The text was updated successfully, but these errors were encountered: