Regression with `UnionType` as arg from 1.18.2 to 1.19.0
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Regression with UnionType from 1.18.2 to 1.19.0, get an error when a union is directly used as an argument typed as UnionType, but not when stored in a variable.
To Reproduce
Playground gist: https://gist.github.com/mypy-play/cd116c86100702e51bc18fe78f0de638
Im below example, foo(example) is fine but foo(int | str) raises an error
from types import UnionType
def foo(t: UnionType) -> None:
pass
example = int | str
foo(example)
foo(int | str)
Expected Behavior
No errors
Actual Behavior
example.py:11: error: Argument 1 to "foo" has incompatible type "UnionType | type[int]"; expected "UnionType" [arg-type]
Your Environment
- Mypy version used: 1.19.0
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini(and other config files):
[mypy]
plugins = pydantic.mypy
ignore_missing_imports = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
warn_unused_ignores = True
warn_no_return = True
warn_return_any = True
warn_redundant_casts = True
strict_equality = True
- Python version used: 3.13.2
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 the minimal reproduction in the issue or its linked playground gist and compare its behavior under mypy 1.18.2 and 1.19.0. Trace how a direct int | str argument is inferred versus the example variable, then add a regression test covering both calls; done means mypy reports no errors for the reproduction.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100