Runtime Types

types.UnionType — runtime type

In Python 3.13, identifies a type expression combining alternatives with |, such as int | str. Union equality ignores member ordering and duplicates; isinstance can test unions of valid runtime classes. A union containing a parameterized generic can raise TypeError when that member is reached. Use typing.get_args for inspection; do not instantiate the union.

Formal Syntax & Structure

python syntaxpython
types.UnionType

Return Value

type

The class object types.UnionType; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
import typesvalue = int | strprint(isinstance(value, types.UnionType))
Python Reference