typesentry icon indicating copy to clipboard operation
typesentry copied to clipboard

is_type method does not support modern Union syntax

Open Anhydrite opened this issue 7 months ago • 0 comments

Hello ! It appears the is_type method does not support the pipe separated Union from Python 3.10+.

# Legacy syntax 
User: TypeAlias = Union[Administrator, Standard, Guest]
std_u = Standard()
is_type = tc1.Config().is_type
is_type(std_u, User) # Working as expected

# Modern syntax
User: TypeAlias = Administrator | Standard | Guest
std_u = Standard()
is_type = tc1.Config().is_type
is_type(std_u, User) # Raise Unknown type XXX | XXX | XXX for type-checker

Anhydrite avatar May 06 '25 07:05 Anhydrite