From 5e2e24f22c75ee72a7e04b4603129fe5025f73e2 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Mon, 30 May 2022 15:22:17 +0000 Subject: [PATCH 1/4] Fix exception types for jsonschema._format The annotated type for the `raises` argument on format checkers was Exception | tuple[Exception, ...] when it should read type[Exception] | tuple[type[Exception], ...] --- stubs/jsonschema/jsonschema/_format.pyi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index 36fa5dcf7e54..b415bcdf90f4 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -2,14 +2,15 @@ from collections.abc import Callable, Iterable from typing import Any, TypeVar _F = TypeVar("_F", bound=Callable[..., Any]) +_RaisesType = type[Exception] | tuple[type[Exception], ...] class FormatChecker: - checkers: dict[str, tuple[Callable[[Any], bool], Exception | tuple[Exception, ...]]] + checkers: dict[str, tuple[Callable[[Any], bool], _RaisesType]] def __init__(self, formats: Iterable[str] | None = ...) -> None: ... - def checks(self, format: str, raises: Exception | tuple[Exception, ...] = ...) -> Callable[[_F], _F]: ... + def checks(self, format: str, raises: _RaisesType = ...) -> Callable[[_F], _F]: ... @classmethod - def cls_checks(cls, format: str, raises: Exception | tuple[Exception, ...] = ...) -> Callable[[_F], _F]: ... + def cls_checks(cls, format: str, raises: _RaisesType = ...) -> Callable[[_F], _F]: ... def check(self, instance: Any, format: str) -> None: ... def conforms(self, instance: Any, format: str) -> bool: ... From 79bad4694cb9dd606487e514ba950ce30d83eb18 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Mon, 30 May 2022 15:44:30 +0000 Subject: [PATCH 2/4] Switch to old-style Union for type alias --- stubs/jsonschema/jsonschema/_format.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index b415bcdf90f4..a0b206bd967c 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -1,8 +1,8 @@ from collections.abc import Callable, Iterable -from typing import Any, TypeVar +from typing import Any, TypeVar, Union _F = TypeVar("_F", bound=Callable[..., Any]) -_RaisesType = type[Exception] | tuple[type[Exception], ...] +_RaisesType = Union[type[Exception], tuple[type[Exception], ...]] class FormatChecker: checkers: dict[str, tuple[Callable[[Any], bool], _RaisesType]] From e7f582880e1f6981ee0d46f70612b2d56fced021 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Mon, 30 May 2022 12:03:28 -0400 Subject: [PATCH 3/4] Update stubs/jsonschema/jsonschema/_format.pyi Co-authored-by: Sebastian Rittau --- stubs/jsonschema/jsonschema/_format.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index a0b206bd967c..febd1152fcc4 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -1,8 +1,8 @@ from collections.abc import Callable, Iterable -from typing import Any, TypeVar, Union +from typing import Any, TypeAlias, TypeVar, Union _F = TypeVar("_F", bound=Callable[..., Any]) -_RaisesType = Union[type[Exception], tuple[type[Exception], ...]] +_RaisesType: TypeAlias = Union[type[Exception], tuple[type[Exception], ...]] class FormatChecker: checkers: dict[str, tuple[Callable[[Any], bool], _RaisesType]] From 49172f8e212c4a44b0842063365e73eea9fbc4c2 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Mon, 30 May 2022 16:05:48 +0000 Subject: [PATCH 4/4] Move TypeAlias import to 'typing_extensions' --- stubs/jsonschema/jsonschema/_format.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index febd1152fcc4..377c2b494819 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -1,5 +1,6 @@ from collections.abc import Callable, Iterable -from typing import Any, TypeAlias, TypeVar, Union +from typing import Any, TypeVar, Union +from typing_extensions import TypeAlias _F = TypeVar("_F", bound=Callable[..., Any]) _RaisesType: TypeAlias = Union[type[Exception], tuple[type[Exception], ...]]