Skip to content

Commit 17e7cc7

Browse files
sirosensrittau
andauthored
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 <[email protected]>
1 parent 8f33ff9 commit 17e7cc7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

stubs/jsonschema/jsonschema/_format.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from collections.abc import Callable, Iterable
2-
from typing import Any, TypeVar
2+
from typing import Any, TypeVar, Union
3+
from typing_extensions import TypeAlias
34

45
_F = TypeVar("_F", bound=Callable[..., Any])
6+
_RaisesType: TypeAlias = Union[type[Exception], tuple[type[Exception], ...]]
57

68
class FormatChecker:
7-
checkers: dict[str, tuple[Callable[[Any], bool], Exception | tuple[Exception, ...]]]
9+
checkers: dict[str, tuple[Callable[[Any], bool], _RaisesType]]
810

911
def __init__(self, formats: Iterable[str] | None = ...) -> None: ...
10-
def checks(self, format: str, raises: Exception | tuple[Exception, ...] = ...) -> Callable[[_F], _F]: ...
12+
def checks(self, format: str, raises: _RaisesType = ...) -> Callable[[_F], _F]: ...
1113
@classmethod
12-
def cls_checks(cls, format: str, raises: Exception | tuple[Exception, ...] = ...) -> Callable[[_F], _F]: ...
14+
def cls_checks(cls, format: str, raises: _RaisesType = ...) -> Callable[[_F], _F]: ...
1315
def check(self, instance: Any, format: str) -> None: ...
1416
def conforms(self, instance: Any, format: str) -> bool: ...
1517

0 commit comments

Comments
 (0)