Skip to content

Repair is_dataclass definition? #9723

Description

@NeilGirdhar

Consider:

fromdataclassesimportis_dataclassdeff(X: type) ->None:
ifis_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:

@overloaddefis_dataclass(obj: DataclassInstance|type[DataclassInstance]) ->Literal[True]: ...
@overloaddefis_dataclass(obj: type) ->TypeGuard[type[DataclassInstance]]: ...
@overloaddefis_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions