Skip to content

Commit e48608a

Browse files
committed
Use TypeIs in is_dataclass
1 parent e7daedd commit e48608a

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

requirements-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ flake8-noqa==1.4.0 # must match .pre-commit-config.yaml
77
flake8-pyi==24.4.1 # must match .pre-commit-config.yaml
88
mypy==1.10.0
99
pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml
10-
pyright==1.1.363
10+
pyright==1.1.364
1111
pytype==2024.4.11; platform_system != "Windows" and python_version < "3.12"
1212
ruff==0.3.7 # must match .pre-commit-config.yaml
1313

stdlib/dataclasses.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from _typeshed import DataclassInstance
55
from builtins import type as Type # alias to avoid name clashes with fields named "type"
66
from collections.abc import Callable, Iterable, Mapping
77
from typing import Any, Generic, Literal, Protocol, TypeVar, overload
8-
from typing_extensions import TypeAlias, TypeGuard
8+
from typing_extensions import TypeAlias, TypeIs
99

1010
if sys.version_info >= (3, 9):
1111
from types import GenericAlias
@@ -214,11 +214,9 @@ else:
214214

215215
def fields(class_or_instance: DataclassInstance | type[DataclassInstance]) -> tuple[Field[Any], ...]: ...
216216
@overload
217-
def is_dataclass(obj: DataclassInstance) -> Literal[True]: ...
217+
def is_dataclass(obj: type) -> TypeIs[type[DataclassInstance]]: ...
218218
@overload
219-
def is_dataclass(obj: type) -> TypeGuard[type[DataclassInstance]]: ...
220-
@overload
221-
def is_dataclass(obj: object) -> TypeGuard[DataclassInstance | type[DataclassInstance]]: ...
219+
def is_dataclass(obj: object) -> TypeIs[DataclassInstance | type[DataclassInstance]]: ...
222220

223221
class FrozenInstanceError(AttributeError): ...
224222

0 commit comments

Comments
 (0)