Skip to content

Commit b69b295

Browse files
committed
Add typing to some basic methods in the exceptions module
1 parent 829430e commit b69b295

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

jsonschema/exceptions.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(
6767
for error in context:
6868
error.parent = self
6969

70-
def __repr__(self):
70+
def __repr__(self) -> str:
7171
return f"<{self.__class__.__name__}: {self.message!r}>"
7272

7373
def __str__(self) -> str:
@@ -104,11 +104,11 @@ def __str__(self) -> str:
104104
)
105105

106106
@classmethod
107-
def create_from(cls, other):
107+
def create_from(cls, other: _Error):
108108
return cls(**other._contents())
109109

110110
@property
111-
def absolute_path(self):
111+
def absolute_path(self) -> deque[str]:
112112
parent = self.parent
113113
if parent is None:
114114
return self.relative_path
@@ -118,7 +118,7 @@ def absolute_path(self):
118118
return path
119119

120120
@property
121-
def absolute_schema_path(self):
121+
def absolute_schema_path(self) -> deque[str]:
122122
parent = self.parent
123123
if parent is None:
124124
return self.relative_schema_path
@@ -128,7 +128,7 @@ def absolute_schema_path(self):
128128
return path
129129

130130
@property
131-
def json_path(self):
131+
def json_path(self) -> str:
132132
path = "$"
133133
for elem in self.absolute_path:
134134
if isinstance(elem, int):
@@ -137,7 +137,9 @@ def json_path(self):
137137
path += "." + elem
138138
return path
139139

140-
def _set(self, type_checker=None, **kwargs):
140+
def _set(
141+
self, type_checker: _types.TypeChecker | None = None, **kwargs: Any
142+
) -> None:
141143
if type_checker is not None and self._type_checker is _unset:
142144
self._type_checker = type_checker
143145

@@ -199,7 +201,7 @@ class RefResolutionError(Exception):
199201

200202
_cause = attr.ib()
201203

202-
def __str__(self):
204+
def __str__(self) -> str:
203205
return str(self._cause)
204206

205207

@@ -208,10 +210,10 @@ class UndefinedTypeCheck(Exception):
208210
A type checker was asked to check a type it did not have registered.
209211
"""
210212

211-
def __init__(self, type):
213+
def __init__(self, type: str) -> None:
212214
self.type = type
213215

214-
def __str__(self):
216+
def __str__(self) -> str:
215217
return f"Type {self.type!r} is unknown to this type checker"
216218

217219

0 commit comments

Comments
 (0)