Fix inferred type of is_dataclass(Any) (#12517)

This commit is contained in:
Marti Raudsepp
2024-08-15 00:09:11 +03:00
committed by GitHub
parent c03f07abfb
commit 1ace5718de
2 changed files with 20 additions and 1 deletions

View File

@@ -41,6 +41,21 @@ if dc.is_dataclass(f):
assert_type(f, Foo)
def is_dataclass_any(arg: Any) -> None:
if dc.is_dataclass(arg):
assert_type(arg, Union["DataclassInstance", Type["DataclassInstance"]])
def is_dataclass_object(arg: object) -> None:
if dc.is_dataclass(arg):
assert_type(arg, Union["DataclassInstance", Type["DataclassInstance"]])
def is_dataclass_type(arg: type) -> None:
if dc.is_dataclass(arg):
assert_type(arg, Type["DataclassInstance"])
def check_other_isdataclass_overloads(x: type, y: object) -> None:
# TODO: pyright correctly emits an error on this, but mypy does not -- why?
# dc.fields(x)