Skip to content

Commit 4f0ef52

Browse files
committed
Enable ruff's simplify rules too.
1 parent db1e185 commit 4f0ef52

File tree

5 files changed

+22
-34
lines changed

5 files changed

+22
-34
lines changed

jsonschema/_utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ def extras_msg(extras):
9090
Create an error message for extra items or properties.
9191
"""
9292

93-
if len(extras) == 1:
94-
verb = "was"
95-
else:
96-
verb = "were"
93+
verb = "was" if len(extras) == 1 else "were"
9794
return ", ".join(repr(extra) for extra in sorted(extras)), verb
9895

9996

jsonschema/_validators.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ def additionalProperties(validator, aP, instance, schema):
4545
yield from validator.descend(instance[extra], aP, path=extra)
4646
elif not aP and extras:
4747
if "patternProperties" in schema:
48-
if len(extras) == 1:
49-
verb = "does"
50-
else:
51-
verb = "do"
52-
48+
verb = "does" if len(extras) == 1 else "do"
5349
joined = ", ".join(repr(each) for each in sorted(extras))
5450
patterns = ", ".join(
5551
repr(each) for each in sorted(schema["patternProperties"])

jsonschema/tests/_suite.py

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

66
from collections.abc import Iterable, Mapping
7+
from contextlib import suppress
78
from functools import partial
89
from pathlib import Path
910
from typing import TYPE_CHECKING, Any
@@ -131,13 +132,11 @@ def to_unittest_testcase(self, *groups, **kwargs):
131132
}
132133
cls = type(name, (unittest.TestCase,), methods)
133134

134-
try:
135+
# We're doing crazy things, so if they go wrong, like a function
136+
# behaving differently on some other interpreter, just make them
137+
# not happen.
138+
with suppress(Exception):
135139
cls.__module__ = _someone_save_us_the_module_of_the_caller()
136-
except Exception: # pragma: no cover
137-
# We're doing crazy things, so if they go wrong, like a function
138-
# behaving differently on some other interpreter, just make them
139-
# not happen.
140-
pass
141140

142141
return cls
143142

@@ -255,10 +254,8 @@ def validate(self, Validator, **kwargs):
255254
validator.validate(instance=self.data)
256255

257256
def validate_ignoring_errors(self, Validator): # pragma: no cover
258-
try:
257+
with suppress(jsonschema.ValidationError):
259258
self.validate(Validator=Validator)
260-
except jsonschema.ValidationError:
261-
pass
262259

263260

264261
def _someone_save_us_the_module_of_the_caller():

jsonschema/validators.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,8 +1097,7 @@ def find(key):
10971097
part = part.replace("~1", "/").replace("~0", "~")
10981098

10991099
if isinstance(document, Sequence):
1100-
# Array indexes should be turned into integers
1101-
try:
1100+
try: # noqa: SIM105
11021101
part = int(part)
11031102
except ValueError:
11041103
pass
@@ -1323,15 +1322,14 @@ class is returned:
13231322

13241323
if schema is True or schema is False or "$schema" not in schema:
13251324
return DefaultValidator
1326-
if schema["$schema"] not in _META_SCHEMAS:
1327-
if default is _UNSET:
1328-
warn(
1329-
(
1330-
"The metaschema specified by $schema was not found. "
1331-
"Using the latest draft to validate, but this will raise "
1332-
"an error in the future."
1333-
),
1334-
DeprecationWarning,
1335-
stacklevel=2,
1336-
)
1325+
if schema["$schema"] not in _META_SCHEMAS and default is _UNSET:
1326+
warn(
1327+
(
1328+
"The metaschema specified by $schema was not found. "
1329+
"Using the latest draft to validate, but this will raise "
1330+
"an error in the future."
1331+
),
1332+
DeprecationWarning,
1333+
stacklevel=2,
1334+
)
13371335
return _META_SCHEMAS.get(schema["$schema"], DefaultValidator)

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ show_error_codes = true
114114
[tool.ruff]
115115
line-length = 79
116116
target-version = "py38"
117-
select = ["B", "D", "D204", "E", "F", "Q", "UP", "W"]
117+
select = ["B", "D", "D204", "E", "F", "Q", "SIM", "UP", "W"]
118118
ignore = [
119119
# It's totally OK to call functions for default arguments.
120120
"B008",
@@ -146,10 +146,10 @@ docstring-quotes = "double"
146146

147147
[tool.ruff.per-file-ignores]
148148
"docs/*" = ["D"]
149-
"jsonschema/cli.py" = ["D", "UP"]
149+
"jsonschema/cli.py" = ["D", "SIM", "UP"]
150150
"jsonschema/_utils.py" = ["D"]
151151
"jsonschema/benchmarks/*" = ["D"]
152-
"jsonschema/tests/*" = ["D"]
152+
"jsonschema/tests/*" = ["D", "SIM"]
153153

154154
[tool.ruff.pyupgrade]
155155
# We support 3.8 + 3.9

0 commit comments

Comments
 (0)