-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Semantic analyzers do not correctly handle qualified type aliases #6667
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
This pull request adds in basic support for enum literals. Basically, you can construct them and use them as types, but not much else. (I originally said I was going to wait until the new semantic analyzer work was finished, but I'm bored.) Some notes: 1. I plan on submitting incremental and fine-grained-mode tests in a future PR. 2. I added two copies of each test -- one using the old semantic analyzer and one using the new one. Let me know if we prefer not doing this and if I should pick one over the other. 3. I wanted to add support for aliases to enums, but ran into some difficulty doing so. See python#6667 for some analysis on the root cause.
This is not a duplicate, and this is indeed about the TODO you mention. I am not sure if there is any "graceful" fix for this. Ideally, the fix should take care of all currently missing node cases (including I would also defer this until the fix of #4157 |
This pull request adds in basic support for enum literals. Basically, you can construct them and use them as types, but not much else. Some notes: 1. I plan on submitting incremental and fine-grained-mode tests in a future PR. 2. I wanted to add support for aliases to enums, but ran into some difficulty doing so. See #6667 for some analysis on the root cause.
Interestingly on master this now gives:
Which is probably a bit less bad. |
This was fixed by #8014 |
Consider the following program:
Mypy thinks that the type of
x
istest.Outer
instead oftest.Outer.Inner
. We get this behavior with both the new and old semantic analyzers.It seems the root cause has to do with the
lookup_qualified
function -- when the loop encounters a SymbolNode of type TypeAlias, it effectively stops processing theparts
variable, ignoring any subsequent information in that list. So, we drop everything to the right of the first type alias.There's actually a TODO about this in the code, though it points out the issue for only
Var
andFuncDef
. The new semantic analyzer'slookup_qualified
uses the same algorithm + has the same TODO.In order to fix this correctly, we'll maybe need to either transfer the unhandled parts back to the caller, or move the type alias expansion logic from
typeanal
into this function? I briefly experimented with both approaches, but they both seemed very clunky.Probably the right thing to do is to just fix this as a part of the long-awaited lookup-functions-refactor (#4157).
(Hopefully this isn't a dupe -- I'm mostly filing this so I can link to it in a PR I'm preparing.)
The text was updated successfully, but these errors were encountered: