Skip to content

Commit 229253c

Browse files
committed
Type pmap using pyrsistent's typing.
Dealing with mypy is <insert 4 letter word here>.
1 parent edba224 commit 229253c

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

jsonschema/_types.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import typing
55

66
from pyrsistent import pmap
7+
from pyrsistent.typing import PMap
78
import attr
89

910
from jsonschema.exceptions import UndefinedTypeCheck
@@ -18,14 +19,8 @@ def _typed_pmap_converter(
1819
str,
1920
typing.Callable[["TypeChecker", typing.Any], bool],
2021
],
21-
) -> typing.Mapping[str, typing.Callable[["TypeChecker", typing.Any], bool]]:
22-
return typing.cast(
23-
typing.Mapping[
24-
str,
25-
typing.Callable[["TypeChecker", typing.Any], bool],
26-
],
27-
pmap(init_val),
28-
)
22+
) -> PMap[str, typing.Callable[["TypeChecker", typing.Any], bool]]:
23+
return pmap(init_val)
2924

3025

3126
def is_array(checker, instance):
@@ -83,7 +78,7 @@ class TypeChecker:
8378
The initial mapping of types to their checking functions.
8479
"""
8580

86-
_type_checkers: typing.Mapping[
81+
_type_checkers: PMap[
8782
str, typing.Callable[["TypeChecker", typing.Any], bool],
8883
] = attr.ib(
8984
default=pmap(),
@@ -159,9 +154,8 @@ def redefine_many(self, definitions=()):
159154
160155
A new `TypeChecker` instance.
161156
"""
162-
return attr.evolve(
163-
self, type_checkers=self._type_checkers.update(definitions),
164-
)
157+
type_checkers = self._type_checkers.update(definitions)
158+
return attr.evolve(self, type_checkers=type_checkers)
165159

166160
def remove(self, *types):
167161
"""
@@ -184,13 +178,13 @@ def remove(self, *types):
184178
if any given type is unknown to this object
185179
"""
186180

187-
checkers = self._type_checkers
181+
type_checkers = self._type_checkers
188182
for each in types:
189183
try:
190-
checkers = checkers.remove(each)
184+
type_checkers = type_checkers.remove(each)
191185
except KeyError:
192186
raise UndefinedTypeCheck(each)
193-
return attr.evolve(self, type_checkers=checkers)
187+
return attr.evolve(self, type_checkers=type_checkers)
194188

195189

196190
draft3_type_checker = TypeChecker(

0 commit comments

Comments
 (0)