Fix mypyc crash with enum type aliases by svalentin · Pull Request #18725 · python/mypy (original) (raw)
Literal[<...>] | None didn't seem to work:
[...]
File "/home/svalentin/src/mypy-svalentin/mypy/checkexpr.py", line 4890, in alias_type_in_runtime_context
return self.chk.named_generic_type("types.UnionType", item.items)
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/svalentin/src/mypy-svalentin/mypy/checker.py", line 7285, in named_generic_type
info = self.lookup_typeinfo(name)
File "/home/svalentin/src/mypy-svalentin/mypy/checker.py", line 7292, in lookup_typeinfo
sym = self.lookup_qualified(fullname)
File "/home/svalentin/src/mypy-svalentin/mypy/checker.py", line 7370, in lookup_qualified
n = self.modules[parts[0]]
~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'types'
Even with [typing fixtures/typing-full.pyi].
I haven't seen any other test use the X | Y form of type definition. I think we should leave the supporting of X | Y types as a separate issue.
I'll add it in run-python312.test since it seems to be fine there.
Separately, is there any reason why we can't have Test_python3_12 tests and we must use run-python312.test?
I think we should update the testing README.md with the differences between Test_python3_12, run-python312.test and # flags: --python-version 3.12. I realize that the last one is just for mypy, not for mypyc, but might be worth documenting the differences in both set of tests.