Skip to content

Commit 92e5400

Browse files
committed
Merge remote-tracking branch 'upstream/maint/1.10.1'
2 parents 272f9d6 + 56700b7 commit 92e5400

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

tools/schemacode/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ filename = "../../src/schema/SCHEMA_VERSION"
131131
line-length = 99
132132

133133
[tool.ruff.lint]
134+
# Recognize imports from _lazytypes as coming from typing
134135
typing-modules = ["bidsschematools._lazytypes"]
135136
select = [
136137
"E", # pycodestyle errors

tools/schemacode/src/bidsschematools/_lazytypes.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,26 @@ def func(arg: lt.Any) -> ReturnType:
5454

5555
TYPE_CHECKING = False
5656
if TYPE_CHECKING or "sphinx.ext.autodoc" in sys.modules: # pragma: no cover
57-
from collections.abc import Iterator, Mapping
57+
from collections.abc import Callable, Iterator, Mapping
5858
from contextlib import AbstractContextManager
59-
from typing import Any, Callable, Literal, NotRequired, Protocol, Self, TypedDict, TypeVar
59+
from typing import Any, Literal, Protocol, TypedDict, TypeVar
60+
61+
# Missing imports in 3.10. Avoid breaking third-party autodoc generation.
62+
try:
63+
from typing import NotRequired, Self
64+
except ImportError: # PY310
65+
NotRequired = tuple # type: ignore[misc,assignment]
66+
Self = object # type: ignore[misc,assignment]
6067

6168
from acres.typ import Traversable
62-
from jsonschema import FormatChecker
63-
from jsonschema.protocols import Validator as JsonschemaValidator
69+
70+
# Optional dependency, avoid breaking third-party autodoc generation.
71+
try:
72+
from jsonschema import FormatChecker
73+
from jsonschema.protocols import Validator as JsonschemaValidator
74+
except ImportError:
75+
FormatChecker = object # type: ignore[misc,assignment]
76+
JsonschemaValidator = object # type: ignore[misc,assignment]
6477

6578
# Helpful TypeVars for generic classes and functions.
6679
# These should never be accessed at runtime, only for type checking, so exclude from __all__.

0 commit comments

Comments
 (0)