-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Crash when using type comments inside a generic class with constrained type variables. #16649
Comments
I am having the same issue but with the package: |
I'll update my PR to check if the patch also works for your case. Can you give me an example of function that fails? |
Trying to track down the exact line that fails as it is kind of a function as a file/function as a whole that fails. As you mention above there a lot of edge cases I will post when I find it Unfortunately my traceback is the same but it only gives me the line of the function and not the argument that is failing |
Closes #16649 It's the first time I am contributing to mypy so I am not very familiar with how it works entirely behind the scene. The issue that I had is that a crash happens when using tuple type comments inside functions/classes that depend on a *constrained* type variable. After investigation, the reason is that the type checker generates all possible definitions (since constraints are known) and expands the functions definitions and bodies accordingly. However, by doing so, a tuple type comment ('# type: (int, float)') would have a FakeInfo, so `ExpandTypeVisitor` would fail since it queries `t.type.fullname`. By the way, feel free to change where my test should lie.
I've encountered something really weird which is quite close to all issues related to
AttributeError: attribute '_fullname' of 'TypeInfo' undefined
but where I could reproduce the bug.More precisely, the following crashes
with a "AttributeError: attribute '_fullname' of 'TypeInfo' undefined". Obviously, the following succeeds:
So I thought that the issue was because of the type comment. However (!), I was surprised to see that the following also doesn't crash:
Or even the following is fine:
Now, we could have thought that the issue stems from "constrained
TypeVar
" + "type comment with more than 2 objects". But actually, it's not entirely the case because the following actually works (!!):Also, if I do not inherit from
Generic
, then the original bug disappears. So I think the issue stems from the fact that I inherit fromGeneric
, uses a constraintedTypeVar
(although I don't understand why the type comment outside a method wouldn't produce a bug as well) and a type comment for two objects (note that this is allowed according to PEP 484).Full traceback
Environment
Here "$code" is a string containing any of the above programs, e.g.,
The text was updated successfully, but these errors were encountered: