Skip to content

Commit b307f31

Browse files
committed
Enable SIM style rules which catch minor import micro-optimizations.
May as well. Also Sphinx is again randomly confused now by an import, which is fine, so now ValidationError is only on the exceptions page.
1 parent 5bce0af commit b307f31

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

docs/api/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Submodules
1717
.. automodule:: jsonschema
1818
:members:
1919
:imported-members:
20-
:exclude-members: FormatError, Validator
20+
:exclude-members: FormatError, Validator, ValidationError
2121

2222
.. autodata:: jsonschema._format._F
2323

jsonschema/exceptions.py

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

66
from collections import defaultdict, deque
7-
from collections.abc import Iterable, Mapping, MutableMapping
87
from pprint import pformat
98
from textwrap import dedent, indent
10-
from typing import ClassVar
9+
from typing import TYPE_CHECKING, ClassVar
1110
import heapq
1211
import itertools
1312
import warnings
@@ -17,6 +16,9 @@
1716

1817
from jsonschema import _utils
1918

19+
if TYPE_CHECKING:
20+
from collections.abc import Iterable, Mapping, MutableMapping
21+
2022
WEAK_MATCHES: frozenset[str] = frozenset(["anyOf", "oneOf"])
2123
STRONG_MATCHES: frozenset[str] = frozenset()
2224

jsonschema/protocols.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from __future__ import annotations
99

10-
from collections.abc import Mapping
1110
from typing import (
1211
TYPE_CHECKING,
1312
Any,
@@ -22,12 +21,14 @@
2221
# therefore, only import at type-checking time (to avoid circular references),
2322
# but use `jsonschema` for any types which will otherwise not be resolvable
2423
if TYPE_CHECKING:
24+
from collections.abc import Mapping
25+
26+
import referencing.jsonschema
27+
2528
from jsonschema import _typing
29+
from jsonschema.exceptions import ValidationError
2630
import jsonschema
2731
import jsonschema.validators
28-
import referencing.jsonschema
29-
30-
from jsonschema.exceptions import ValidationError
3132

3233
# For code authors working on the validator protocol, these are the three
3334
# use-cases which should be kept in mind:

jsonschema/tests/_suite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
from __future__ import annotations
55

6-
from collections.abc import Iterable, Mapping
76
from contextlib import suppress
87
from functools import partial
98
from pathlib import Path
@@ -20,6 +19,8 @@
2019
import referencing.jsonschema
2120

2221
if TYPE_CHECKING:
22+
from collections.abc import Iterable, Mapping
23+
2324
import pyperf
2425

2526
from jsonschema.validators import _VALIDATORS

jsonschema/validators.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from collections.abc import Iterable, Mapping, Sequence
88
from functools import lru_cache
99
from operator import methodcaller
10+
from typing import TYPE_CHECKING
1011
from urllib.parse import unquote, urldefrag, urljoin, urlsplit
1112
from urllib.request import urlopen
1213
from warnings import warn
@@ -30,7 +31,9 @@
3031
_utils,
3132
exceptions,
3233
)
33-
from jsonschema.protocols import Validator
34+
35+
if TYPE_CHECKING:
36+
from jsonschema.protocols import Validator
3437

3538
_UNSET = _utils.Unset()
3639

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ exclude = ["jsonschema/benchmarks/*"]
141141

142142
[tool.ruff]
143143
line-length = 79
144-
select = ["B", "D", "D204", "E", "F", "Q", "RUF", "SIM", "UP", "W"]
144+
select = ["B", "D", "D204", "E", "F", "Q", "RUF", "SIM", "TCH", "UP", "W"]
145145
ignore = [
146146
# Wat, type annotations for self and cls, why is this a thing?
147147
"ANN101",
@@ -152,6 +152,8 @@ ignore = [
152152
"B008",
153153
# raise SomeException(...) is fine.
154154
"B904",
155+
# There's no need for explicit strict, this is simply zip's default behavior.
156+
"B905",
155157
# It's fine to not have docstrings for magic methods.
156158
"D105",
157159
# __init__ especially doesn't need a docstring
@@ -170,6 +172,8 @@ ignore = [
170172
"D407",
171173
# Plz spaces after section headers
172174
"D412",
175+
# Not sure what heuristic this uses, but it seems easy for it to be wrong.
176+
"SIM300",
173177
# We support 3.8 + 3.9
174178
"UP007",
175179
]

0 commit comments

Comments
 (0)