Skip to content

Commit f809757

Browse files
committed
Add typing to some basic methods in the exceptions module
1 parent 9aee436 commit f809757

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
@@ -70,7 +70,7 @@ def __init__(
7070
for error in context:
7171
error.parent = self
7272

73-
def __repr__(self):
73+
def __repr__(self) -> str:
7474
return f"<{self.__class__.__name__}: {self.message!r}>"
7575

7676
def __str__(self) -> str:
@@ -107,11 +107,11 @@ def __str__(self) -> str:
107107
)
108108

109109
@classmethod
110-
def create_from(cls, other):
110+
def create_from(cls, other: _Error):
111111
return cls(**other._contents())
112112

113113
@property
114-
def absolute_path(self):
114+
def absolute_path(self) -> deque[str | int]:
115115
parent = self.parent
116116
if parent is None:
117117
return self.relative_path
@@ -121,7 +121,7 @@ def absolute_path(self):
121121
return path
122122

123123
@property
124-
def absolute_schema_path(self):
124+
def absolute_schema_path(self) -> deque[str | int]:
125125
parent = self.parent
126126
if parent is None:
127127
return self.relative_schema_path
@@ -131,7 +131,7 @@ def absolute_schema_path(self):
131131
return path
132132

133133
@property
134-
def json_path(self):
134+
def json_path(self) -> str:
135135
path = "$"
136136
for elem in self.absolute_path:
137137
if isinstance(elem, int):
@@ -140,7 +140,9 @@ def json_path(self):
140140
path += "." + elem
141141
return path
142142

143-
def _set(self, type_checker=None, **kwargs):
143+
def _set(
144+
self, type_checker: _types.TypeChecker | None = None, **kwargs: Any
145+
) -> None:
144146
if type_checker is not None and self._type_checker is _unset:
145147
self._type_checker = type_checker
146148

@@ -202,7 +204,7 @@ class RefResolutionError(Exception):
202204

203205
_cause = attr.ib()
204206

205-
def __str__(self):
207+
def __str__(self) -> str:
206208
return str(self._cause)
207209

208210

@@ -211,10 +213,10 @@ class UndefinedTypeCheck(Exception):
211213
A type checker was asked to check a type it did not have registered.
212214
"""
213215

214-
def __init__(self, type):
216+
def __init__(self, type: str) -> None:
215217
self.type = type
216218

217-
def __str__(self):
219+
def __str__(self) -> str:
218220
return f"Type {self.type!r} is unknown to this type checker"
219221

220222

0 commit comments

Comments
 (0)