Skip to content

More helpful diagnostic when trying to use PEP 604 union types before 3.10 #437

@metaist

Description

@metaist

Summary

I believe this is distinct from #122 because even the most basic UnionType seems to fail.

# test.py
from typing import Union

A = Union[int, str]
B = int | str
$ uvx ty check test.py

error[unsupported-operator]: Operator `|` is unsupported between objects of type `<class 'int'>` and `<class 'str'>`
 --> test.py:4:5
  |
3 | A = Union[int, str]
4 | B = int | str
  |     ^^^^^^^^^
  |
info: rule `unsupported-operator` is enabled by default

Version

ty 0.0.1-alpha.5 and ty 0.0.1-alpha.5 (4ad13f2 2025-05-17)

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsRelated to reporting of diagnostics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions