Closed sassanh closed 1 month ago
This behavior is correct, so I don't consider this a bug. Pyright's behavior here is in conformance with the typing spec.
The type of UnionType
when used in a value expression is types.UnionType
.
U = SubclassOne | SubclassTwo
reveal_type(U) # UnionType
When it's used in a type expression, it acts as a type alias for the type SubclassOne | SubclassTwo
.
In your case, you're using it in a value expression (an argument for a function call), and its type is not compatible with type[OriginalType]
.
For comparison, all othe other major type checkers including mypy also generate an error here. This behavior is conformant with the typing spec. For details, refer to this section.
You may be interested in draft PEP 747 that provides a way to annotate "type forms".
Describe the bug In this code the last line causes a
reportArgumentType
pyright error.Code or Screenshots