Skip to content

Commit 909efc0

Browse files
committed
address mypy and ruff concerns
1 parent 906f2cb commit 909efc0

File tree

6 files changed

+23
-15
lines changed

6 files changed

+23
-15
lines changed

sphinx_immaterial/__init__.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import re
5-
from typing import Dict, List, Mapping, Optional, Type, cast
5+
from typing import Dict, Mapping, Optional, Type, cast
66
from urllib.parse import urlparse
77

88
import docutils.nodes
@@ -18,6 +18,14 @@
1818
from sphinx.application import Sphinx
1919
from sphinxcontrib.serializinghtml import JSONHTMLBuilder
2020

21+
if version_info < (7, 2):
22+
from sphinx.builders.html import JavaScript # type: ignore[attr-defined]
23+
from sphinx.builders.html import ( # type: ignore[attr-defined]
24+
Stylesheet as StyleSheet,
25+
)
26+
else:
27+
from sphinx.builders.html._assets import _CascadingStyleSheet as StyleSheet
28+
from sphinx.builders.html._assets import _JavaScript as JavaScript
2129
from . import (
2230
html_translator_mixin,
2331
json_builder_serializing_implementation,
@@ -62,9 +70,9 @@ def _get_html_builder(base_builder: Type[sphinx.builders.html.StandaloneHTMLBuil
6270

6371
class CustomHTMLBuilder(base_builder): # type: ignore
6472
if version_info < (7, 2):
65-
css_files: List[sphinx.builders.html.Stylesheet]
73+
css_files: list[StyleSheet]
6674
else:
67-
_css_files: List[sphinx.builders.html._assets._CascadingStyleSheet] # type: ignore[name-defined]
75+
_css_files: list[StyleSheet] # type: ignore[name-defined]
6876
theme: sphinx.theming.Theme
6977
templates: sphinx.jinja2glue.BuiltinTemplateLoader
7078

@@ -98,11 +106,11 @@ def init_js_files(self):
98106
excluded_scripts.add("_static/jquery.js")
99107
excluded_scripts.add("_static/_sphinx_javascript_frameworks_compat.js")
100108
if version_info < (7, 2):
101-
self.script_files: List[sphinx.builders.html.JavaScript] = [
109+
self.script_files: list[JavaScript] = [
102110
x for x in self.script_files if x.filename not in excluded_scripts
103111
]
104112
else:
105-
self._js_files: List[sphinx.builders.html._assets._JavaScript] = [ # type: ignore[name-defined]
113+
self._js_files: list[JavaScript] = [ # type: ignore[name-defined]
106114
x for x in self._js_files if x.filename not in excluded_scripts
107115
]
108116

@@ -121,14 +129,14 @@ def init_css_files(self):
121129
if version_info < (7, 2):
122130
self.css_files = [
123131
x
124-
for x in cast(List[sphinx.builders.html.Stylesheet], self.css_files)
132+
for x in cast(list[StyleSheet], self.css_files)
125133
if x.filename not in excluded
126134
]
127135
else:
128136
self._css_files = [
129137
x
130138
for x in cast(
131-
List[sphinx.builders.html._assets._CascadingStyleSheet], # type: ignore[name-defined]
139+
list[StyleSheet], # type: ignore[name-defined]
132140
self._css_files,
133141
)
134142
if x.filename not in excluded

sphinx_immaterial/apidoc/json/domain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def _add_sub_schema(
693693
return sphinx_utils.parse_rst(
694694
self.state,
695695
sphinx_utils.format_directive("json:schema", entry.id, options=kwargs),
696-
*self.get_source_info(),
696+
*cast(tuple[str, int], self.get_source_info()),
697697
)
698698

699699
def _make_field(
@@ -1107,7 +1107,7 @@ class JsonSchemaDomain(sphinx.domains.Domain):
11071107
"schema": JsonSchemaRole(warn_dangling=True),
11081108
}
11091109

1110-
object_types: Dict[str, sphinx.domains.ObjType] = {
1110+
object_types: Dict[str, sphinx.domains.ObjType] = { # type: ignore[misc]
11111111
"schema": sphinx.domains.ObjType("type", "schema"),
11121112
"subschema": sphinx.domains.ObjType("member", "schema"),
11131113
}
@@ -1116,7 +1116,7 @@ class JsonSchemaDomain(sphinx.domains.Domain):
11161116
"schema": JsonSchemaDirective,
11171117
}
11181118

1119-
initial_data: Dict[str, DomainSchemaEntry] = {
1119+
initial_data: Dict[str, DomainSchemaEntry] = { # type: ignore[misc]
11201120
"schemas": cast(DomainSchemaEntry, {}),
11211121
}
11221122

sphinx_immaterial/apidoc/python/type_param_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def get_base_class_type_param_substitutions(
155155
}
156156

157157
if sys.version_info >= (3, 10):
158-
_ENCODE_TYPE_PARAM[typing.ParamSpec] = (
159-
lambda annotation: TYPE_VAR_ANNOTATION_PREFIX + "P_" + annotation.__name__
158+
_ENCODE_TYPE_PARAM[typing.ParamSpec] = lambda annotation: (
159+
TYPE_VAR_ANNOTATION_PREFIX + "P_" + annotation.__name__
160160
)
161161
_DECODE_TYPE_PARAM["P"] = typing.ParamSpec
162162
if sys.version_info >= (3, 11):

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sphinx
66

77
if sphinx.version_info < (7, 2):
8-
from sphinx.testing.path import path as SphinxPath
8+
from sphinx.testing.path import path as SphinxPath # type: ignore[import-not-found]
99
else:
1010
from pathlib import Path as SphinxPath # type: ignore[assignment]
1111

tests/python_apigen_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515

1616
if sphinx.version_info < (7, 2):
17-
from sphinx.testing.path import path as SphinxPath
17+
from sphinx.testing.path import path as SphinxPath # type: ignore[import-not-found]
1818
else:
1919
from pathlib import Path as SphinxPath # type: ignore[assignment]
2020

tests/python_transform_type_annotations_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sphinx.domains.python
88

99
if sphinx.version_info < (7, 2):
10-
from sphinx.testing.path import path as SphinxPath
10+
from sphinx.testing.path import path as SphinxPath # type: ignore[import-not-found]
1111
else:
1212
from pathlib import Path as SphinxPath # type: ignore[assignment]
1313

0 commit comments

Comments
 (0)