-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Consider:
from dataclasses import is_dataclass
def f(X: type) -> None:
if is_dataclass(X):
reveal_type(X) # information: Type of "X" is "type"
Ideally, X
would have type type[DataclassInstance]
. It doesn't because is_dataclass
is defined:
@overload
def is_dataclass(obj: DataclassInstance | type[DataclassInstance]) -> Literal[True]: ...
@overload
def is_dataclass(obj: type) -> TypeGuard[type[DataclassInstance]]: ...
@overload
def is_dataclass(obj: object) -> TypeGuard[DataclassInstance | type[DataclassInstance]]: ...
And the argument of type type
matches the first overload, which does not incorporate a TypeGuard
. Eric Traut recommends erasing the first overload of is_dataclass
.
tmke8
Metadata
Metadata
Assignees
Labels
No labels