Skip to content

Regression with UnionType as arg from 1.18.2 to 1.19.0 #20426

@mmiller-max

Description

@mmiller-max

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions