Skip to content

Commit db1e185

Browse files
committed
flake8 -> ruff, a mostly painless affair.
1 parent 61bd0b1 commit db1e185

13 files changed

+85
-67
lines changed

.flake8

Lines changed: 0 additions & 13 deletions
This file was deleted.

jsonschema/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
An implementation of JSON Schema for Python
2+
An implementation of JSON Schema for Python.
33
44
The main functionality is provided by the validator classes for each of the
55
supported JSON Schema versions.
@@ -98,3 +98,19 @@ def __getattr__(name):
9898
return ValidatorForFormat.FORMAT_CHECKER
9999

100100
raise AttributeError(f"module {__name__} has no attribute {name}")
101+
102+
103+
__all__ = [
104+
"Draft201909Validator",
105+
"Draft202012Validator",
106+
"Draft3Validator",
107+
"Draft4Validator",
108+
"Draft6Validator",
109+
"Draft7Validator",
110+
"FormatChecker",
111+
"SchemaError",
112+
"TypeChecker",
113+
"ValidationError",
114+
"Validator",
115+
"validate",
116+
]

jsonschema/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
The jsonschema CLI is now deprecated in favor of check-jsonschema.
3+
"""
14
from jsonschema.cli import main
25

36
main()

jsonschema/_format.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def __init__(self, formats: typing.Iterable[str] | None = None):
5151
self.checkers = {k: self.checkers[k] for k in formats}
5252

5353
def __repr__(self):
54-
return "<FormatChecker checkers={}>".format(sorted(self.checkers))
54+
return f"<FormatChecker checkers={sorted(self.checkers)}>"
5555

56-
def checks(
56+
def checks( # noqa: D417,D214,D405 (charliermarsh/ruff#3547)
5757
self, format: str, raises: _RaisesType = (),
5858
) -> typing.Callable[[_F], _F]:
5959
"""
@@ -73,7 +73,7 @@ def checks(
7373
The exception object will be accessible as the
7474
`jsonschema.exceptions.ValidationError.cause` attribute of the
7575
resulting validation error.
76-
"""
76+
""" # noqa: D417,D214,D405 (charliermarsh/ruff#3547)
7777

7878
def _checks(func: _F) -> _F:
7979
self.checkers[format] = (func, raises)
@@ -126,7 +126,6 @@ def check(self, instance: object, format: str) -> None:
126126
127127
if the instance does not conform to ``format``
128128
"""
129-
130129
if format not in self.checkers:
131130
return
132131

@@ -157,7 +156,6 @@ def conforms(self, instance: object, format: str) -> bool:
157156
158157
bool: whether it conformed
159158
"""
160-
161159
try:
162160
self.check(instance, format)
163161
except FormatError:

jsonschema/_legacy_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def recursiveRef(validator, recursiveRef, instance, schema):
222222

223223
def find_evaluated_item_indexes_by_schema(validator, instance, schema):
224224
"""
225-
Get all indexes of items that get evaluated under the current schema
225+
Get all indexes of items that get evaluated under the current schema.
226226
227227
Covers all keywords related to unevaluatedItems: items, prefixItems, if,
228228
then, else, contains, unevaluatedItems, allOf, oneOf, anyOf

jsonschema/_types.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# the concrete type of a type checker mapping
1515
# this "do nothing" wrapper presents the correct information to mypy
1616
def _typed_map_converter(
17-
init_val: Mapping[str, Callable[["TypeChecker", Any], bool]],
18-
) -> HashTrieMap[str, Callable[["TypeChecker", Any], bool]]:
17+
init_val: Mapping[str, Callable[[TypeChecker, Any], bool]],
18+
) -> HashTrieMap[str, Callable[[TypeChecker, Any], bool]]:
1919
return HashTrieMap.convert(init_val)
2020

2121

@@ -79,7 +79,7 @@ class TypeChecker:
7979
"""
8080

8181
_type_checkers: HashTrieMap[
82-
str, Callable[["TypeChecker", Any], bool],
82+
str, Callable[[TypeChecker, Any], bool],
8383
] = attr.ib(
8484
default=HashTrieMap(),
8585
converter=_typed_map_converter,
@@ -116,7 +116,7 @@ def is_type(self, instance, type: str) -> bool:
116116

117117
return fn(self, instance)
118118

119-
def redefine(self, type: str, fn) -> "TypeChecker":
119+
def redefine(self, type: str, fn) -> TypeChecker:
120120
"""
121121
Produce a new checker with the given type redefined.
122122
@@ -135,7 +135,7 @@ def redefine(self, type: str, fn) -> "TypeChecker":
135135
"""
136136
return self.redefine_many({type: fn})
137137

138-
def redefine_many(self, definitions=()) -> "TypeChecker":
138+
def redefine_many(self, definitions=()) -> TypeChecker:
139139
"""
140140
Produce a new checker with the given types redefined.
141141
@@ -148,7 +148,7 @@ def redefine_many(self, definitions=()) -> "TypeChecker":
148148
type_checkers = self._type_checkers.update(definitions)
149149
return attr.evolve(self, type_checkers=type_checkers)
150150

151-
def remove(self, *types) -> "TypeChecker":
151+
def remove(self, *types) -> TypeChecker:
152152
"""
153153
Produce a new checker with the given types forgotten.
154154
@@ -164,7 +164,6 @@ def remove(self, *types) -> "TypeChecker":
164164
165165
if any given type is unknown to this object
166166
"""
167-
168167
type_checkers = self._type_checkers
169168
for each in types:
170169
try:

jsonschema/exceptions.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151
parent=None,
5252
type_checker=_unset,
5353
):
54-
super(_Error, self).__init__(
54+
super().__init__(
5555
message,
5656
validator,
5757
path,
@@ -252,7 +252,7 @@ class FormatError(Exception):
252252
"""
253253

254254
def __init__(self, message, cause=None):
255-
super(FormatError, self).__init__(message, cause)
255+
super().__init__(message, cause)
256256
self.message = message
257257
self.cause = self.__cause__ = cause
258258

@@ -283,7 +283,6 @@ def __contains__(self, index):
283283
"""
284284
Check whether ``instance[index]`` has any errors.
285285
"""
286-
287286
return index in self._contents
288287

289288
def __getitem__(self, index):
@@ -295,7 +294,6 @@ def __getitem__(self, index):
295294
by ``instance.__getitem__`` will be propagated (usually this is
296295
some subclass of `LookupError`.
297296
"""
298-
299297
if self._instance is not _unset and index not in self:
300298
self._instance[index]
301299
return self._contents[index]
@@ -310,7 +308,6 @@ def __iter__(self):
310308
"""
311309
Iterate (non-recursively) over the indices in the instance with errors.
312310
"""
313-
314311
return iter(self._contents)
315312

316313
def __len__(self):
@@ -329,7 +326,6 @@ def total_errors(self):
329326
"""
330327
The total number of errors in the entire tree, including children.
331328
"""
332-
333329
child_errors = sum(len(tree) for _, tree in self._contents.items())
334330
return len(self.errors) + child_errors
335331

jsonschema/protocols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def validate(self, instance: Any) -> None:
206206
ValidationError: [2, 3, 4] is too long
207207
"""
208208

209-
def evolve(self, **kwargs) -> "Validator":
209+
def evolve(self, **kwargs) -> Validator:
210210
"""
211211
Create a new validator like this one, but with given changes.
212212

jsonschema/tests/test_jsonschema_test_suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def missing_format(test): # pragma: no cover
3939
):
4040
return
4141

42-
return "Format checker {0!r} not found.".format(schema["format"])
42+
return f"Format checker {schema['format']!r} not found."
4343
return missing_format
4444

4545

jsonschema/tests/test_validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ def test_schema_with_invalid_regex_with_disabled_format_validation(self):
15221522
)
15231523

15241524

1525-
class ValidatorTestMixin(MetaSchemaTestsMixin, object):
1525+
class ValidatorTestMixin(MetaSchemaTestsMixin):
15261526
def test_it_implements_the_validator_protocol(self):
15271527
self.assertIsInstance(self.Validator({}), protocols.Validator)
15281528

@@ -1632,7 +1632,7 @@ def check(value):
16321632
elif value == "bad":
16331633
raise bad
16341634
else: # pragma: no cover
1635-
self.fail("What is {}? [Baby Don't Hurt Me]".format(value))
1635+
self.fail(f"What is {value}? [Baby Don't Hurt Me]")
16361636

16371637
validator = self.Validator(
16381638
{"format": "foo"}, format_checker=checker,
@@ -2201,7 +2201,7 @@ def test_it_retrieves_local_refs_via_urlopen(self):
22012201
self.addCleanup(os.remove, tempf.name)
22022202
json.dump({"foo": "bar"}, tempf)
22032203

2204-
ref = "file://{}#foo".format(pathname2url(tempf.name))
2204+
ref = f"file://{pathname2url(tempf.name)}#foo"
22052205
with self.resolver.resolving(ref) as resolved:
22062206
self.assertEqual(resolved, "bar")
22072207

0 commit comments

Comments
 (0)