Skip to content

Commit c4a758c

Browse files
committed
Add typing to some basic methods in the exceptions module
1 parent 6043703 commit c4a758c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

jsonschema/exceptions.py

+13-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,11 @@ def json_path(self):
140140
path += "." + elem
141141
return path
142142

143-
def _set(self, type_checker=None, **kwargs):
143+
def _set(
144+
self,
145+
type_checker: _types.TypeChecker | None = None,
146+
**kwargs: Any,
147+
) -> None:
144148
if type_checker is not None and self._type_checker is _unset:
145149
self._type_checker = type_checker
146150

@@ -202,7 +206,7 @@ class RefResolutionError(Exception):
202206

203207
_cause = attr.ib()
204208

205-
def __str__(self):
209+
def __str__(self) -> str:
206210
return str(self._cause)
207211

208212

@@ -211,10 +215,10 @@ class UndefinedTypeCheck(Exception):
211215
A type checker was asked to check a type it did not have registered.
212216
"""
213217

214-
def __init__(self, type):
218+
def __init__(self, type: str) -> None:
215219
self.type = type
216220

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

220224

0 commit comments

Comments
 (0)