From 17e7cc7d3cf37b98da84247332a4b7310e966665 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Mon, 30 May 2022 12:14:33 -0400 Subject: [PATCH] Fix exception types for jsonschema._format (#7990) The annotated type for the `raises` argument on format checkers was Exception | tuple[Exception, ...] when it should read type[Exception] | tuple[type[Exception], ...] Co-authored-by: Sebastian Rittau --- stubs/jsonschema/jsonschema/_format.pyi | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stubs/jsonschema/jsonschema/_format.pyi b/stubs/jsonschema/jsonschema/_format.pyi index 36fa5dcf7..377c2b494 100644 --- a/stubs/jsonschema/jsonschema/_format.pyi +++ b/stubs/jsonschema/jsonschema/_format.pyi @@ -1,15 +1,17 @@ from collections.abc import Callable, Iterable -from typing import Any, TypeVar +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], ...]] 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: ...