-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
INTERNAL ERROR RuntimeError visiting partial-type of imported variable with follow_imports=skip #12109
Labels
Comments
This was referenced Mar 26, 2022
Michael0x2a
added a commit
to Michael0x2a/mypy
that referenced
this issue
Nov 6, 2022
Fixes python#12109. The original issue reported that the bug had to do with the use of the `--follow-imports=skip` flag. However, it turned out this was a red herring after closer inspection: I was able to trigger a more minimal repro both with and without this flag: ```python from enum import Enum class Foo(Enum): a = [] # E: Need type annotation for "a" (hint: "a: List[<type>] = ...") b = None def check(self) -> None: reveal_type(Foo.a.value) # N: Revealed type is "<partial list[?]>" reveal_type(Foo.b.value) # N: Revealed type is "<partial None>" ``` The first two `reveal_types` demonstrate the crux of the bug: the enum plugin does not correctly handle and convert partial types into regular types when inferring the type of the `.value` field. This can then cause any number of downstream problems. For example, suppose we modify `def check(...)` so it runs `reveal_type(self.value)`. Doing this will trigger a crash in mypy because it makes the enum plugin eventually try running `is_equivalent(...)` on the two partial types. But `is_equivalent` does not support partial types, so we crash. I opted to solve this problem by: 1. Making the enum plugin explicitly call the `fixup_partial_types` function on all field types. This prevents the code from crashing. 2. Modifies mypy so that Final vars are never marked as being PartialTypes. Without this, `reveal_type(Foo.b.value)` would report a type of `Union[Any, None]` instead of just `None`. (Note that all enum fields are implicitly final).
JukkaL
pushed a commit
that referenced
this issue
Nov 7, 2022
Fixes #12109. The original issue reported that the bug had to do with the use of the `--follow-imports=skip` flag. However, it turned out this was a red herring after closer inspection: I was able to trigger a more minimal repro both with and without this flag: ```python from enum import Enum class Foo(Enum): a = [] # E: Need type annotation for "a" (hint: "a: List[<type>] = ...") b = None def check(self) -> None: reveal_type(Foo.a.value) # N: Revealed type is "<partial list[?]>" reveal_type(Foo.b.value) # N: Revealed type is "<partial None>" ``` The first two `reveal_types` demonstrate the crux of the bug: the enum plugin does not correctly handle and convert partial types into regular types when inferring the type of the `.value` field. This can then cause any number of downstream problems. For example, suppose we modify `def check(...)` so it runs `reveal_type(self.value)`. Doing this will trigger a crash in mypy because it makes the enum plugin eventually try running `is_equivalent(...)` on the two partial types. But `is_equivalent` does not support partial types, so we crash. I opted to solve this problem by: 1. Making the enum plugin explicitly call the `fixup_partial_types` function on all field types. This prevents the code from crashing. 2. Modifies mypy so that Final vars are never marked as being PartialTypes. Without this, `reveal_type(Foo.b.value)` would report a type of `Union[Any, None]` instead of just `None`. (Note that all enum fields are implicitly final).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crash Report
mypy 0.931 crashes while checking sources when using follow_imports=skip. Issue not reproduced on mypy 0.910 or with follow_imports=normal.
Traceback
To Reproduce
Configuration - multiple files required to reproduce
__init__.py
tests/
**
__init__.py
**
test.py
**
imported.py
mypy.ini
__init__.py
: emptytests/__init__.py
: emptytests/test.py
:tests/imported.py
:mypy.ini
:Your Environment
mypy.ini
(and other config files):follow_imports=skip
The text was updated successfully, but these errors were encountered: