Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e908b80

Browse files
committed
Fix missing trailing commas.
Add flake8-commas to ensure this stays the case.
1 parent 39697cd commit e908b80

15 files changed

Lines changed: 92 additions & 110 deletions

docs/conf.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from textwrap import dedent
21
import os
32
import re
43
import sys
@@ -78,11 +77,9 @@
7877
# A list of ignored prefixes for module index sorting.
7978
# modindex_common_prefix = []
8079

81-
doctest_global_setup = dedent(
82-
"""
83-
from jsonschema import *
80+
doctest_global_setup = """
81+
from jsonschema import *
8482
"""
85-
)
8683

8784
intersphinx_mapping = {
8885
"python": ("https://docs.python.org/3", None),

jsonschema/_format.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ def wrap(func):
168168
if draft7:
169169
func = _draft_checkers["draft7"].checks(draft7, raises)(func)
170170
if draft202012:
171-
func = _draft_checkers["draft202012"].checks(
172-
draft202012, raises
173-
)(func)
171+
func = _draft_checkers["draft202012"].checks(draft202012, raises)(
172+
func,
173+
)
174174

175175
# Oy. This is bad global state, but relied upon for now, until
176176
# deprecation. See https://github.com/Julian/jsonschema/issues/519
177177
# and test_format_checkers_come_with_defaults
178178
FormatChecker.cls_checks(
179-
draft202012 or draft7 or draft6 or draft4 or draft3, raises
179+
draft202012 or draft7 or draft6 or draft4 or draft3, raises,
180180
)(func)
181181
return func
182182
return wrap

jsonschema/_legacy_validators.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ def dependencies_draft3(validator, dependencies, instance, schema):
3232
yield error
3333
elif validator.is_type(dependency, "string"):
3434
if dependency not in instance:
35-
yield ValidationError(
36-
"%r is a dependency of %r" % (dependency, property)
37-
)
35+
message = "%r is a dependency of %r"
36+
yield ValidationError(message % (dependency, property))
3837
else:
3938
for each in dependency:
4039
if each not in instance:
@@ -77,7 +76,7 @@ def disallow_draft3(validator, disallow, instance, schema):
7776
for disallowed in _utils.ensure_list(disallow):
7877
if validator.is_valid(instance, {"type": [disallowed]}):
7978
yield ValidationError(
80-
"%r is disallowed for %r" % (disallowed, instance)
79+
"%r is disallowed for %r" % (disallowed, instance),
8180
)
8281

8382

@@ -136,7 +135,7 @@ def minimum_draft3_draft4(validator, minimum, instance, schema):
136135

137136
if failed:
138137
yield ValidationError(
139-
"%r is %s the minimum of %r" % (instance, cmp, minimum)
138+
"%r is %s the minimum of %r" % (instance, cmp, minimum),
140139
)
141140

142141

@@ -153,7 +152,7 @@ def maximum_draft3_draft4(validator, maximum, instance, schema):
153152

154153
if failed:
155154
yield ValidationError(
156-
"%r is %s the maximum of %r" % (instance, cmp, maximum)
155+
"%r is %s the maximum of %r" % (instance, cmp, maximum),
157156
)
158157

159158

@@ -208,5 +207,5 @@ def contains_draft6_draft7(validator, contains, instance, schema):
208207

209208
if not any(validator.is_valid(element, contains) for element in instance):
210209
yield ValidationError(
211-
"None of %r are valid under the given schema" % (instance,)
210+
"None of %r are valid under the given schema" % (instance,),
212211
)

jsonschema/_utils.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,16 @@ def find_evaluated_item_indexes_by_schema(validator, instance, schema):
280280
if "if" in schema:
281281
if validator.is_valid(instance, schema["if"]):
282282
evaluated_indexes += find_evaluated_item_indexes_by_schema(
283-
validator, instance, schema["if"]
283+
validator, instance, schema["if"],
284284
)
285285
if "then" in schema:
286286
evaluated_indexes += find_evaluated_item_indexes_by_schema(
287-
validator, instance, schema["then"]
287+
validator, instance, schema["then"],
288288
)
289289
else:
290290
if "else" in schema:
291291
evaluated_indexes += find_evaluated_item_indexes_by_schema(
292-
validator, instance, schema["else"]
292+
validator, instance, schema["else"],
293293
)
294294

295295
for keyword in ["contains", "unevaluatedItems"]:
@@ -304,7 +304,7 @@ def find_evaluated_item_indexes_by_schema(validator, instance, schema):
304304
errs = list(validator.descend(instance, subschema))
305305
if not errs:
306306
evaluated_indexes += find_evaluated_item_indexes_by_schema(
307-
validator, instance, subschema
307+
validator, instance, subschema,
308308
)
309309

310310
return evaluated_indexes
@@ -328,13 +328,13 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
328328

329329
try:
330330
evaluated_keys += find_evaluated_property_keys_by_schema(
331-
validator, instance, resolved
331+
validator, instance, resolved,
332332
)
333333
finally:
334334
validator.resolver.pop_scope()
335335

336336
for keyword in [
337-
"properties", "additionalProperties", "unevaluatedProperties"
337+
"properties", "additionalProperties", "unevaluatedProperties",
338338
]:
339339
if keyword in schema:
340340
if validator.is_type(schema[keyword], "boolean"):
@@ -345,15 +345,15 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
345345
if validator.is_type(schema[keyword], "object"):
346346
for property, subschema in schema[keyword].items():
347347
if property in instance and validator.is_valid(
348-
instance[property], subschema
348+
instance[property], subschema,
349349
):
350350
evaluated_keys.append(property)
351351

352352
if "patternProperties" in schema:
353353
for property, value in instance.items():
354354
for pattern, subschema in schema["patternProperties"].items():
355355
if re.search(pattern, property) and validator.is_valid(
356-
{property: value}, schema["patternProperties"]
356+
{property: value}, schema["patternProperties"],
357357
):
358358
evaluated_keys.append(property)
359359

@@ -362,7 +362,7 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
362362
if property not in instance:
363363
continue
364364
evaluated_keys += find_evaluated_property_keys_by_schema(
365-
validator, instance, subschema
365+
validator, instance, subschema,
366366
)
367367

368368
for keyword in ["allOf", "oneOf", "anyOf"]:
@@ -371,22 +371,22 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
371371
errs = list(validator.descend(instance, subschema))
372372
if not errs:
373373
evaluated_keys += find_evaluated_property_keys_by_schema(
374-
validator, instance, subschema
374+
validator, instance, subschema,
375375
)
376376

377377
if "if" in schema:
378378
if validator.is_valid(instance, schema["if"]):
379379
evaluated_keys += find_evaluated_property_keys_by_schema(
380-
validator, instance, schema["if"]
380+
validator, instance, schema["if"],
381381
)
382382
if "then" in schema:
383383
evaluated_keys += find_evaluated_property_keys_by_schema(
384-
validator, instance, schema["then"]
384+
validator, instance, schema["then"],
385385
)
386386
else:
387387
if "else" in schema:
388388
evaluated_keys += find_evaluated_property_keys_by_schema(
389-
validator, instance, schema["else"]
389+
validator, instance, schema["else"],
390390
)
391391

392392
return evaluated_keys

jsonschema/_validators.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def items(validator, items, instance, schema):
7777
if not items:
7878
if len(instance) > len(schema['prefixItems']):
7979
yield ValidationError(
80-
"%r has more items than defined in prefixItems" % instance
80+
"%r has more items than defined in prefixItems" % instance,
8181
)
8282
else:
8383
non_prefixed_items = instance[len(schema['prefixItems']):] \
@@ -104,7 +104,7 @@ def additionalItems(validator, aI, instance, schema):
104104
error = "Additional items are not allowed (%s %s unexpected)"
105105
yield ValidationError(
106106
error %
107-
extras_msg(instance[len(schema.get("items", [])):])
107+
extras_msg(instance[len(schema.get("items", [])):]),
108108
)
109109

110110

@@ -134,7 +134,7 @@ def contains(validator, contains, instance, schema):
134134
# default contains behavior
135135
if not matches:
136136
yield ValidationError(
137-
"None of %r are valid under the given schema" % (instance,)
137+
"None of %r are valid under the given schema" % (instance,),
138138
)
139139
return
140140

@@ -143,8 +143,8 @@ def contains(validator, contains, instance, schema):
143143
yield ValidationError(
144144
"Too few matches under the given schema. "
145145
"Expected %d but there were only %d." % (
146-
min_contains, matches
147-
)
146+
min_contains, matches,
147+
),
148148
)
149149
return
150150

@@ -153,8 +153,8 @@ def contains(validator, contains, instance, schema):
153153
yield ValidationError(
154154
"Too many matches under the given schema. "
155155
"Expected %d but there were only %d." % (
156-
max_contains, matches
157-
)
156+
max_contains, matches,
157+
),
158158
)
159159
return
160160

@@ -163,8 +163,8 @@ def contains(validator, contains, instance, schema):
163163
yield ValidationError(
164164
"Invalid number or matches under the given schema, "
165165
"expected between %d and %d, got %d" % (
166-
min_contains, max_contains, matches
167-
)
166+
min_contains, max_contains, matches,
167+
),
168168
)
169169
return
170170

@@ -199,7 +199,7 @@ def minimum(validator, minimum, instance, schema):
199199

200200
if instance < minimum:
201201
yield ValidationError(
202-
"%r is less than the minimum of %r" % (instance, minimum)
202+
"%r is less than the minimum of %r" % (instance, minimum),
203203
)
204204

205205

@@ -209,7 +209,7 @@ def maximum(validator, maximum, instance, schema):
209209

210210
if instance > maximum:
211211
yield ValidationError(
212-
"%r is greater than the maximum of %r" % (instance, maximum)
212+
"%r is greater than the maximum of %r" % (instance, maximum),
213213
)
214214

215215

@@ -404,7 +404,7 @@ def required(validator, required, instance, schema):
404404
def minProperties(validator, mP, instance, schema):
405405
if validator.is_type(instance, "object") and len(instance) < mP:
406406
yield ValidationError(
407-
"%r does not have enough properties" % (instance,)
407+
"%r does not have enough properties" % (instance,),
408408
)
409409

410410

@@ -455,14 +455,14 @@ def oneOf(validator, oneOf, instance, schema):
455455
more_valid.append(first_valid)
456456
reprs = ", ".join(repr(schema) for schema in more_valid)
457457
yield ValidationError(
458-
"%r is valid under each of %s" % (instance, reprs)
458+
"%r is valid under each of %s" % (instance, reprs),
459459
)
460460

461461

462462
def not_(validator, not_schema, instance, schema):
463463
if validator.is_valid(instance, not_schema):
464464
yield ValidationError(
465-
"%r is not allowed for %r" % (not_schema, instance)
465+
"%r is not allowed for %r" % (not_schema, instance),
466466
)
467467

468468

@@ -480,13 +480,13 @@ def if_(validator, if_schema, instance, schema):
480480

481481
def unevaluatedItems(validator, unevaluatedItems, instance, schema):
482482
evaluated_item_indexes = find_evaluated_item_indexes_by_schema(
483-
validator, instance, schema
483+
validator, instance, schema,
484484
)
485485
unevaluated_items = []
486486
for k, v in enumerate(instance):
487487
if k not in evaluated_item_indexes:
488488
for error in validator.descend(
489-
v, unevaluatedItems, schema_path="unevaluatedItems"
489+
v, unevaluatedItems, schema_path="unevaluatedItems",
490490
):
491491
unevaluated_items.append(v)
492492

@@ -497,7 +497,7 @@ def unevaluatedItems(validator, unevaluatedItems, instance, schema):
497497

498498
def unevaluatedProperties(validator, unevaluatedProperties, instance, schema):
499499
evaluated_property_keys = find_evaluated_property_keys_by_schema(
500-
validator, instance, schema
500+
validator, instance, schema,
501501
)
502502
unevaluated_property_keys = []
503503
for property, subschema in instance.items():
@@ -521,6 +521,6 @@ def prefixItems(validator, prefixItems, instance, schema):
521521

522522
for k, v in enumerate(instance[:min(len(prefixItems), len(instance))]):
523523
for error in validator.descend(
524-
v, prefixItems[k], schema_path="prefixItems"
524+
v, prefixItems[k], schema_path="prefixItems",
525525
):
526526
yield error

jsonschema/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def parse_args(args):
201201
arguments = vars(parser.parse_args(args=args or ["--help"]))
202202
if arguments["output"] != "plain" and arguments["error_format"]:
203203
raise parser.error(
204-
"--error-format can only be used with --output plain"
204+
"--error-format can only be used with --output plain",
205205
)
206206
if arguments["output"] == "plain" and arguments["error_format"] is None:
207207
arguments["error_format"] = "{error.instance}: {error.message}\n"

jsonschema/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __str__(self):
7575
7676
On %s%s:
7777
%s
78-
""".rstrip()
78+
""".rstrip(),
7979
) % (
8080
self.validator,
8181
self._word_for_schema_in_error_message,
@@ -194,7 +194,7 @@ def __str__(self):
194194
195195
While checking instance:
196196
%s
197-
""".rstrip()
197+
""".rstrip(),
198198
) % (
199199
self.type,
200200
textwrap.indent(pschema, " "),

jsonschema/tests/_suite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _tests_in(self, subject, path):
143143
case_description=each["description"],
144144
schema=each["schema"],
145145
remotes=self._remotes,
146-
**test
146+
**test,
147147
) for test in each["tests"]
148148
)
149149

@@ -177,7 +177,7 @@ def fully_qualified_name(self): # pragma: no cover
177177
self.subject,
178178
self.case_description,
179179
self.description,
180-
]
180+
],
181181
)
182182

183183
@property
@@ -213,7 +213,7 @@ def validate(self, Validator, **kwargs):
213213
schema=self.schema,
214214
cls=Validator,
215215
resolver=resolver,
216-
**kwargs
216+
**kwargs,
217217
)
218218

219219
def validate_ignoring_errors(self, Validator): # pragma: no cover

0 commit comments

Comments
 (0)