@@ -64,16 +64,20 @@ def is_any(checker, instance):
64
64
@attr .s (frozen = True )
65
65
class TypeChecker :
66
66
"""
67
- A `` type` ` property checker.
67
+ A :kw:` type` property checker.
68
68
69
- A `TypeChecker` performs type checking for a `Validator`. Type
70
- checks to perform are updated using `TypeChecker.redefine` or
71
- `TypeChecker.redefine_many` and removed via `TypeChecker.remove`.
72
- Each of these return a new `TypeChecker` object.
69
+ A `TypeChecker` performs type checking for a `Validator`, converting
70
+ between the defined JSON Schema types and some associated Python types or
71
+ objects.
72
+
73
+ Modifying the behavior just mentioned by redefining which Python objects
74
+ are considered to be of which JSON Schema types can be done using
75
+ `TypeChecker.redefine` or `TypeChecker.redefine_many`, and types can be
76
+ removed via `TypeChecker.remove`. Each of these return a new `TypeChecker`.
73
77
74
78
Arguments:
75
79
76
- type_checkers (dict) :
80
+ type_checkers:
77
81
78
82
The initial mapping of types to their checking functions.
79
83
"""
@@ -85,25 +89,20 @@ class TypeChecker:
85
89
converter = _typed_pmap_converter ,
86
90
)
87
91
88
- def is_type (self , instance , type ) :
92
+ def is_type (self , instance , type : str ) -> bool :
89
93
"""
90
94
Check if the instance is of the appropriate type.
91
95
92
96
Arguments:
93
97
94
- instance (object) :
98
+ instance:
95
99
96
100
The instance to check
97
101
98
- type (str) :
102
+ type:
99
103
100
104
The name of the type that is expected.
101
105
102
- Returns:
103
-
104
- bool: Whether it conformed.
105
-
106
-
107
106
Raises:
108
107
109
108
`jsonschema.exceptions.UndefinedTypeCheck`:
@@ -117,30 +116,26 @@ def is_type(self, instance, type):
117
116
118
117
return fn (self , instance )
119
118
120
- def redefine (self , type , fn ):
119
+ def redefine (self , type : str , fn ) -> "TypeChecker" :
121
120
"""
122
121
Produce a new checker with the given type redefined.
123
122
124
123
Arguments:
125
124
126
- type (str) :
125
+ type:
127
126
128
127
The name of the type to check.
129
128
130
129
fn (collections.abc.Callable):
131
130
132
- A function taking exactly two parameters - the type
131
+ A callable taking exactly two parameters - the type
133
132
checker calling the function and the instance to check.
134
133
The function should return true if instance is of this
135
134
type and false otherwise.
136
-
137
- Returns:
138
-
139
- A new `TypeChecker` instance.
140
135
"""
141
136
return self .redefine_many ({type : fn })
142
137
143
- def redefine_many (self , definitions = ()):
138
+ def redefine_many (self , definitions = ()) -> "TypeChecker" :
144
139
"""
145
140
Produce a new checker with the given types redefined.
146
141
@@ -149,28 +144,20 @@ def redefine_many(self, definitions=()):
149
144
definitions (dict):
150
145
151
146
A dictionary mapping types to their checking functions.
152
-
153
- Returns:
154
-
155
- A new `TypeChecker` instance.
156
147
"""
157
148
type_checkers = self ._type_checkers .update (definitions )
158
149
return attr .evolve (self , type_checkers = type_checkers )
159
150
160
- def remove (self , * types ):
151
+ def remove (self , * types ) -> "TypeChecker" :
161
152
"""
162
153
Produce a new checker with the given types forgotten.
163
154
164
155
Arguments:
165
156
166
- types (~collections.abc.Iterable) :
157
+ types:
167
158
168
159
the names of the types to remove.
169
160
170
- Returns:
171
-
172
- A new `TypeChecker` instance
173
-
174
161
Raises:
175
162
176
163
`jsonschema.exceptions.UndefinedTypeCheck`:
0 commit comments