-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Checking of starred expressions #483
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
…d within the index of for-statements.
…de (possibly a tuple) instead of a list. Updated tests accordingly.
What is currently missing are type annotations for starred expressions. I propose to follow the same syntax as used for the starred expressions themselves, like: a, *b = lijst # type: int, *List[int]
# b has type List[int]
*(p, q), r = rij # type: *(int, int), int
# p and q have type int This would introduce a new type node In addition: Type inference of rvalues from the lvalue is probably not working correctly for nested starred expressions. However, if don't know how to test this. Input is welcome. |
…es (e.g. of for-stmts)
… is present in a tuple
… number in type annotation error message.
I've implemented the starred type annotations I proposed in the previous comment. |
Thanks for implementing this! I did a first review pass and it looks excellent. I'm going to play around with it a bit a look at the diff in more detail. |
else: # index lvalue | ||
# TODO Figure out more precise type context, probably | ||
# based on the type signature of the _set method. | ||
type_parameters.extend(star_rv_types) |
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.
This fails in case of nested star expressions, like a, *(b, *c) = x
. I'd like to fix it, but I have trouble coming up with a test case for type inference from lvalues.
I guess it is not very common, though, and not very useful.
Apologies for the delay, we have my parents visiting from Finland and I haven't been able to keep up with code reviews. Sorry! |
Take your time. |
I updated the documentation update to reflect the new documentation structure. Once more, thanks for adding this feature! |
This PR brings type checking of starred expressions in assignments (
*rest, last = 1,2,3
) and as index of for-statements ([head for head, *tail in L]
).In 9986cef, I have replaced the index of for-statements and generator expressions from being a list of
Node
s to a singleNode
(which will be a tuple, of course, when the list would have had more than one element before the change). Consequently, several testcases have changed in that commit, because the AST/parse tree changed a bit.