Union changes in Python 3.14 crash mypy
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Crash Report
typeshed PR python/typeshed#13740, which adapts the changes to Union in Python 3.14 for typeshed crash mypy. (When running the tests with Python 3.14 or 3.15. Older Python versions are fine.)
The changes
Traceback
python tests/stubtest_stdlib.py
shell: /usr/bin/bash -e {0}
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
FORCE_COLOR: 1
TERM: xterm-256color
pythonLocation: /opt/hostedtoolcache/Python/3.15.0-beta.2/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.15.0-beta.2/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.15.0-beta.2/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.15.0-beta.2/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib
/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/bin/python -m mypy.stubtest --check-typeshed --show-traceback --strict-type-check-only --custom-typeshed-dir . --allowlist stdlib/@tests/stubtest_allowlists/common.txt --allowlist stdlib/@tests/stubtest_allowlists/linux.txt --allowlist stdlib/@tests/stubtest_allowlists/py315.txt --allowlist stdlib/@tests/stubtest_allowlists/linux-py315.txt
/home/runner/work/typeshed/typeshed/stdlib/typing.pyi:1002: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 2.1.0
/home/runner/work/typeshed/typeshed/stdlib/typing.pyi:1002: note: use --pdb to drop into pdb
stdlib/typing_extensions.pyi:287: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [overload-overlap]
Traceback (most recent call last):
File "<frozen runpy>", line 201, in _run_module_as_main
File "<frozen runpy>", line 87, in _run_code
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/stubtest.py", line 2593, in <module>
sys.exit(main())
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/stubtest.py", line 2589, in main
return test_stubs(parse_options(sys.argv[1:]))
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/stubtest.py", line 2419, in test_stubs
modules = build_stubs(modules, options, find_submodules=not args.check_typeshed)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/stubtest.py", line 2215, in build_stubs
res = mypy.build.build(sources=sources, options=options)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/build.py", line 422, in build
result = build_inner(
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/build.py", line 537, in build_inner
graph = dispatch(sources, manager, stdout, connect_threads)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/build.py", line 4150, in dispatch
process_graph(graph, manager)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/build.py", line 4618, in process_graph
done, still_working, results = manager.wait_for_done(graph)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/build.py", line 1492, in wait_for_done
process_stale_scc(graph, next_scc, self)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/build.py", line 4792, in process_stale_scc
graph[id].type_check_first_pass()
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/build.py", line 3414, in type_check_first_pass
self.type_checker().check_first_pass(recurse_into_functions=recurse_into_functions)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checker.py", line 618, in check_first_pass
self.accept(d)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checker.py", line 765, in accept
stmt.accept(self)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/nodes.py", line 1907, in accept
return visitor.visit_assignment_stmt(self)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checker.py", line 3329, in visit_assignment_stmt
self.check_type_alias_rvalue(s)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checker.py", line 3370, in check_type_alias_rvalue
alias_type = self.expr_checker.accept(s.rvalue)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checkexpr.py", line 6176, in accept
typ = self.accept_maybe_cache(node, type_context=type_context)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checkexpr.py", line 6211, in accept_maybe_cache
typ = node.accept(self)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/nodes.py", line 2697, in accept
return visitor.visit_op_expr(self)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checkexpr.py", line 3559, in visit_op_expr
return self.accept(e.analyzed)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checkexpr.py", line 6178, in accept
typ = node.accept(self) # r-value type, when interpreted as a value expression
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/nodes.py", line 3420, in accept
return visitor.visit_type_alias_expr(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checkexpr.py", line 4967, in visit_type_alias_expr
return self.alias_type_in_runtime_context(alias.node, ctx=alias, alias_definition=True)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checkexpr.py", line 5024, in alias_type_in_runtime_context
return self.chk.named_generic_type("types.UnionType", item.items)
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checker.py", line 7788, in named_generic_type
info = self.lookup_typeinfo(name)
File "/opt/hostedtoolcache/Python/3.15.0-beta.2/x64/lib/python3.15/site-packages/mypy/checker.py", line 7797, in lookup_typeinfo
assert isinstance(node, TypeInfo), node
~~~~~~~~~~^^^^^^^^^^^^^^^^
AssertionError: TypeAlias:723(
UnionType
Never
False)
Your Environment
Command run was: /opt/hostedtoolcache/Python/3.15.0-beta.2/x64/bin/python -m mypy.stubtest --check-typeshed --show-traceback --strict-type-check-only --custom-typeshed-dir . --allowlist stdlib/@tests/stubtest_allowlists/common.txt --allowlist stdlib/@tests/stubtest_allowlists/linux.txt --allowlist stdlib/@tests/stubtest_allowlists/py315.txt --allowlist stdlib/@tests/stubtest_allowlists/linux-py315.txt
- Mypy version used: 2.1.0
- Python version used: 3.14.5/3.15.0b2
- Operating system and version: Crashed on Ubuntu, Windows, MacOS
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with alias_type_in_runtime_context in mypy/checkexpr.py and the lookup_typeinfo path in mypy/checker.py, using the traceback as the entry point. Reproduce with the provided python -m mypy.stubtest command on Python 3.14 or 3.15, then verify that the typeshed stubtest run completes without the internal error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100