diff --git a/pyproject.toml b/pyproject.toml index 80b82af1f..5d20d5d66 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ files = [ ] exclude = "setup.py" plugins = ["pydantic.mypy"] +check_untyped_defs = true [tool.black] include = '\.py$' diff --git a/sphinx_immaterial/__init__.py b/sphinx_immaterial/__init__.py index 2c4008558..25a7918b3 100644 --- a/sphinx_immaterial/__init__.py +++ b/sphinx_immaterial/__init__.py @@ -68,7 +68,7 @@ def init_js_files(self): if nav_adapt.READTHEDOCS is None: excluded_scripts.add("_static/jquery.js") excluded_scripts.add("_static/_sphinx_javascript_frameworks_compat.js") - self.script_files = [ + self.script_files: List[sphinx.builders.html.JavaScript] = [ x for x in self.script_files if x.filename not in excluded_scripts ] @@ -93,7 +93,7 @@ def init_css_files(self): def gen_additional_pages(self): # Prevent the search.html page from being written since this theme provides # its own search results display that does not use it. - search = self.search + search = self.search # type: ignore[has-type] self.search = False super().gen_additional_pages() self.search = search diff --git a/sphinx_immaterial/apidoc/cpp/api_parser.py b/sphinx_immaterial/apidoc/cpp/api_parser.py index 291708d24..f1906992f 100644 --- a/sphinx_immaterial/apidoc/cpp/api_parser.py +++ b/sphinx_immaterial/apidoc/cpp/api_parser.py @@ -289,36 +289,36 @@ class Config: include_directory_map_pattern: ClassVar[Pattern] def __post_init__(self): - self.allow_path_pattern = _combine_regexp_list(self.allow_paths) - self.disallow_path_pattern = _combine_regexp_list(self.disallow_paths) - self.allow_path_pattern = _combine_regexp_list(self.allow_paths) + self.allow_path_pattern = _combine_regexp_list(self.allow_paths) # type: ignore[misc] + self.disallow_path_pattern = _combine_regexp_list(self.disallow_paths) # type: ignore[misc] + self.allow_path_pattern = _combine_regexp_list(self.allow_paths) # type: ignore[misc] self.disallow_namespaces_pattern = _combine_regexp_list( self.disallow_namespaces ) - self.allow_symbols_pattern = _combine_regexp_list(self.allow_symbols) - self.disallow_symbols_pattern = _combine_regexp_list(self.disallow_symbols) - self.allow_macros_pattern = _combine_regexp_list(self.allow_macros) - self.disallow_macros_pattern = _combine_regexp_list(self.disallow_macros) - self.ignore_diagnostics_pattern = _combine_regexp_list(self.ignore_diagnostics) - self.hide_types_pattern = _combine_regexp_list(self.hide_types) - self.type_replacements_pattern = _make_replacement_pattern( - self.type_replacements, prefix=r"\b", suffix=r"\b" + self.allow_symbols_pattern = _combine_regexp_list(self.allow_symbols) # type: ignore[misc] + self.disallow_symbols_pattern = _combine_regexp_list(self.disallow_symbols) # type: ignore[misc] + self.allow_macros_pattern = _combine_regexp_list(self.allow_macros) # type: ignore[misc] + self.disallow_macros_pattern = _combine_regexp_list(self.disallow_macros) # type: ignore[misc] + self.ignore_diagnostics_pattern = _combine_regexp_list(self.ignore_diagnostics) # type: ignore[misc] + self.hide_types_pattern = _combine_regexp_list(self.hide_types) # type: ignore[misc] + self.type_replacements_pattern = _make_replacement_pattern( # type: ignore[misc] + list(self.type_replacements.keys()), prefix=r"\b", suffix=r"\b" ) - self.ignore_template_parameters_pattern = _combine_regexp_list( + self.ignore_template_parameters_pattern = _combine_regexp_list( # type: ignore[misc] self.ignore_template_parameters ) - self.hide_initializers_pattern = _combine_regexp_list(self.hide_initializers) + self.hide_initializers_pattern = _combine_regexp_list(self.hide_initializers) # type: ignore[misc] if os.name == "nt": - self._include_directory_map = { + self._include_directory_map = { # type: ignore[misc] key.replace("\\", "/"): value for key, value in self.include_directory_map.items() } else: - self._include_directory_map = self.include_directory_map - self.include_directory_map_pattern = _make_replacement_pattern( + self._include_directory_map = self.include_directory_map # type: ignore[misc] + self.include_directory_map_pattern = _make_replacement_pattern( # type: ignore[misc] list(self._include_directory_map.keys()), prefix="^", suffix="" ) - self._cached_mapped_include_directories = {} + self._cached_mapped_include_directories = {} # type: ignore[misc] _include_directory_map: ClassVar[Dict[str, str]] _cached_mapped_include_directories: ClassVar[Dict[str, str]] @@ -613,8 +613,8 @@ def get_spellings(): # angle brackets. if prev_token is not None: spelling = prev_token.spelling - token_end = prev_token.extent.end - offset_diff = token_end.offset - extent.end.offset + token_end = cast(SourceLocation, prev_token.extent.end) + offset_diff = token_end.offset - cast(SourceLocation, extent.end).offset if offset_diff != 0: yield spelling[:-offset_diff] else: @@ -1439,7 +1439,7 @@ def _transform_cursor_to_json(self, decl: Cursor, parent: Optional[Cursor]): json_repr["parent"] = get_entity_id(parent) entity_id = get_entity_id(decl) if document_with: - prev_json = self._prev_decl[1] + prev_json = cast(Any, self._prev_decl)[1] if ( prev_json is None or not _kinds_are_compatible(prev_json["kind"], json_repr["kind"]) diff --git a/sphinx_immaterial/apidoc/cpp/ast_fixes.py b/sphinx_immaterial/apidoc/cpp/ast_fixes.py index 2d02d40dd..f0b6d6181 100644 --- a/sphinx_immaterial/apidoc/cpp/ast_fixes.py +++ b/sphinx_immaterial/apidoc/cpp/ast_fixes.py @@ -1,6 +1,10 @@ """Fixes limitations of the Sphinx C++ parser.""" -from . import fix_cpp_domain_requires_clause # type: ignore[unused-import] +import sphinx + from . import fix_cpp_domain_symbol_resolution_through_type_aliases # type: ignore[unused-import] -from . import fix_cpp_is_pack # type: ignore[unused-import] -from . import fix_cpp_symbol_to_normalize_template_args # type: ignore[unused-import] + +if sphinx.version_info < (5, 2): + from . import fix_cpp_domain_requires_clause # type: ignore[unused-import] + from . import fix_cpp_is_pack # type: ignore[unused-import] + from . import fix_cpp_symbol_to_normalize_template_args # type: ignore[unused-import] diff --git a/sphinx_immaterial/apidoc/cpp/cpp_resolve_c_xrefs.py b/sphinx_immaterial/apidoc/cpp/cpp_resolve_c_xrefs.py index f29fc9770..ecb02985f 100644 --- a/sphinx_immaterial/apidoc/cpp/cpp_resolve_c_xrefs.py +++ b/sphinx_immaterial/apidoc/cpp/cpp_resolve_c_xrefs.py @@ -88,7 +88,7 @@ def _resolve_xref_inner( return None, None - sphinx.domains.cpp.CPPDomain._resolve_xref_inner = _resolve_xref_inner + sphinx.domains.cpp.CPPDomain._resolve_xref_inner = _resolve_xref_inner # type: ignore[assignment] def _monkey_patch_cpp_expr_role_to_include_c_parent_key(): @@ -112,7 +112,7 @@ def run( refnode["c:parent_key"] = c_parent_key return nodes, messages - CPPExprRole.run = run + CPPExprRole.run = run # type: ignore[assignment] _monkey_patch_cpp_resolve_c_xrefs() diff --git a/sphinx_immaterial/apidoc/cpp/fix_cpp_domain_requires_clause.py b/sphinx_immaterial/apidoc/cpp/fix_cpp_domain_requires_clause.py index 4f79749d1..1a433b054 100644 --- a/sphinx_immaterial/apidoc/cpp/fix_cpp_domain_requires_clause.py +++ b/sphinx_immaterial/apidoc/cpp/fix_cpp_domain_requires_clause.py @@ -6,10 +6,15 @@ import re from typing import Optional, Union +import sphinx import sphinx.domains.cpp from sphinx.domains.cpp import DefinitionParser, ASTDeclaration +# Not needed in Sphinx 5.2 +assert sphinx.version_info < (5, 2) + + def _monkey_patch_cpp_domain_support_requires_clause(): orig_parse_declaration = DefinitionParser.parse_declaration @@ -33,9 +38,9 @@ def assert_end_or_requires(allowSemicolon=False): return orig_parse_type(self, named, outer) finally: self.assert_end = orig_assert_end - return orig_parse_type(self, named, outer) + return orig_parse_type(self, named, outer) # type: ignore[arg-type] - DefinitionParser._parse_type = _parse_type + DefinitionParser._parse_type = _parse_type # type: ignore[assignment] def parse_declaration( self: DefinitionParser, objectType: str, directiveType: str @@ -59,7 +64,7 @@ def parse_declaration( requires_clause = None def parse_template_declaration_prefix(*args, **kwargs): - self._parse_template_declaration_prefix = ( + self._parse_template_declaration_prefix = ( # type: ignore[assignment] orig_parse_template_declaration_prefix ) result = orig_parse_template_declaration_prefix(*args, **kwargs) @@ -72,14 +77,14 @@ def parse_template_declaration_prefix(*args, **kwargs): self._parse_template_declaration_prefix = parse_template_declaration_prefix # type: ignore[assignment] result = orig_parse_declaration(self, objectType, directiveType) - result.requiresClause = requires_clause + result.requiresClause = requires_clause # type: ignore[attr-defined] return result finally: self._parse_template_declaration_prefix = ( # type: ignore[assignment] orig_parse_template_declaration_prefix ) - DefinitionParser.parse_declaration = parse_declaration + DefinitionParser.parse_declaration = parse_declaration # type: ignore[assignment] _monkey_patch_cpp_domain_support_requires_clause() diff --git a/sphinx_immaterial/apidoc/cpp/fix_cpp_domain_symbol_resolution_through_type_aliases.py b/sphinx_immaterial/apidoc/cpp/fix_cpp_domain_symbol_resolution_through_type_aliases.py index 5421ec9db..d980a40ef 100644 --- a/sphinx_immaterial/apidoc/cpp/fix_cpp_domain_symbol_resolution_through_type_aliases.py +++ b/sphinx_immaterial/apidoc/cpp/fix_cpp_domain_symbol_resolution_through_type_aliases.py @@ -116,7 +116,7 @@ def _find_named_symbols( self, identOrOp, None, - None, + None, # type: ignore[arg-type] templateShorthand, matchSelf, recurseInAnon, @@ -145,7 +145,7 @@ def _find_named_symbols( searchInSiblings=False, ) - Symbol._find_named_symbols = _find_named_symbols + Symbol._find_named_symbols = _find_named_symbols # type: ignore[assignment] in_symbol_lookup_with_shorthand = [] @@ -184,7 +184,7 @@ def _symbol_lookup( finally: in_symbol_lookup_with_shorthand.pop() - Symbol._symbol_lookup = _symbol_lookup + Symbol._symbol_lookup = _symbol_lookup # type: ignore[assignment] orig_find_identifier = Symbol.find_identifier @@ -220,7 +220,7 @@ def find_identifier( return s return None - Symbol.find_identifier = find_identifier + Symbol.find_identifier = find_identifier # type: ignore[assignment] _monkey_patch_cpp_domain_symbol_resolution_through_type_aliases() diff --git a/sphinx_immaterial/apidoc/cpp/fix_cpp_is_pack.py b/sphinx_immaterial/apidoc/cpp/fix_cpp_is_pack.py index bb7d43da7..fc5d5f3b0 100644 --- a/sphinx_immaterial/apidoc/cpp/fix_cpp_is_pack.py +++ b/sphinx_immaterial/apidoc/cpp/fix_cpp_is_pack.py @@ -3,17 +3,21 @@ https://github.com/sphinx-doc/sphinx/pull/10257 """ +import sphinx import sphinx.domains.cpp +# Not needed in Sphinx 5.2 +assert sphinx.version_info < (5, 2) + def _monkey_patch_cpp_is_pack(): - sphinx.domains.cpp.ASTDeclaratorPtr.isPack = property(lambda self: self.next.isPack) - sphinx.domains.cpp.ASTDeclaratorRef.isPack = property(lambda self: self.next.isPack) - sphinx.domains.cpp.ASTDeclaratorMemPtr.isPack = property( + sphinx.domains.cpp.ASTDeclaratorPtr.isPack = property(lambda self: self.next.isPack) # type: ignore[assignment] + sphinx.domains.cpp.ASTDeclaratorRef.isPack = property(lambda self: self.next.isPack) # type: ignore[assignment] + sphinx.domains.cpp.ASTDeclaratorMemPtr.isPack = property( # type: ignore[assignment] lambda self: self.next.isPack ) - sphinx.domains.cpp.ASTDeclaratorParamPack.isPack = property(lambda self: True) - sphinx.domains.cpp.ASTDeclaratorParen.isPack = property( + sphinx.domains.cpp.ASTDeclaratorParamPack.isPack = property(lambda self: True) # type: ignore[assignment] + sphinx.domains.cpp.ASTDeclaratorParen.isPack = property( # type: ignore[assignment] lambda self: self.inner.isPack or self.next.isPack ) diff --git a/sphinx_immaterial/apidoc/cpp/fix_cpp_symbol_to_normalize_template_args.py b/sphinx_immaterial/apidoc/cpp/fix_cpp_symbol_to_normalize_template_args.py index d18518d9c..ebefc0531 100644 --- a/sphinx_immaterial/apidoc/cpp/fix_cpp_symbol_to_normalize_template_args.py +++ b/sphinx_immaterial/apidoc/cpp/fix_cpp_symbol_to_normalize_template_args.py @@ -28,9 +28,13 @@ from typing import Union, Any +import sphinx import sphinx.domains.cpp from sphinx.domains.cpp import Symbol +# Not needed in Sphinx 5.2 +assert sphinx.version_info < (5, 2) + def _is_cpp_ast_specialization( templateParams: Union[ @@ -92,7 +96,7 @@ def __init__( line, ) - Symbol.__init__ = __init__ + Symbol.__init__ = __init__ # type: ignore[assignment] _monkey_patch_cpp_symbol_to_normalize_template_args() diff --git a/sphinx_immaterial/apidoc/cpp/macro_parameters.py b/sphinx_immaterial/apidoc/cpp/macro_parameters.py index b07ae9eb2..010eb2437 100644 --- a/sphinx_immaterial/apidoc/cpp/macro_parameters.py +++ b/sphinx_immaterial/apidoc/cpp/macro_parameters.py @@ -33,7 +33,7 @@ def _add_function_params(self: CSymbol) -> None: assert len(nn.names) == 1 self._add_symbols(nn, decl, self.docname, self.line) - CSymbol._add_function_params = _add_function_params + CSymbol._add_function_params = _add_function_params # type: ignore[assignment] def get_id( self: ASTMacroParameter, version: int, objectType: str, symbol: CSymbol @@ -41,7 +41,7 @@ def get_id( # the anchor will be our parent return symbol.parent.declaration.get_id(version, prefixed=False) - ASTMacroParameter.get_id = get_id + ASTMacroParameter.get_id = get_id # type: ignore[attr-defined] sphinx.domains.c.CDomain.object_types["macroParam"] = sphinx.domains.ObjType( "macro parameter", "identifier", "var", "member", "data" diff --git a/sphinx_immaterial/apidoc/cpp/parameter_objects.py b/sphinx_immaterial/apidoc/cpp/parameter_objects.py index 94aa6b102..e98c6f199 100644 --- a/sphinx_immaterial/apidoc/cpp/parameter_objects.py +++ b/sphinx_immaterial/apidoc/cpp/parameter_objects.py @@ -169,7 +169,7 @@ def get_objects( priority = OBJECT_PRIORITY_DEFAULT yield (name, dispname, objectType, docname, anchor, priority) - sphinx.domains.cpp.CPPDomain.get_objects = get_objects + sphinx.domains.cpp.CPPDomain.get_objects = get_objects # type: ignore[assignment] def _add_parameter_links_to_signature( diff --git a/sphinx_immaterial/apidoc/cpp/signodes.py b/sphinx_immaterial/apidoc/cpp/signodes.py index f58c69ef0..63575125f 100644 --- a/sphinx_immaterial/apidoc/cpp/signodes.py +++ b/sphinx_immaterial/apidoc/cpp/signodes.py @@ -10,6 +10,7 @@ import sphinx.addnodes import sphinx.application import sphinx.domains.cpp +from sphinx.domains.cpp import ASTTemplateParams class desc_cpp_template_param(sphinx.addnodes.desc_sig_element): @@ -37,7 +38,6 @@ class desc_cpp_explicit(sphinx.addnodes.desc_sig_element): def _monkey_patch_cpp_ast_template_params(): - ASTTemplateParams = sphinx.domains.cpp.ASTTemplateParams orig_describe_signature_as_introducer = ( ASTTemplateParams.describe_signature_as_introducer ) @@ -60,7 +60,7 @@ def describe_signature_as_introducer( x["classes"].append("sig-name-nonprimary") parentNode.extend(fake_parent.children) - ASTTemplateParams.describe_signature_as_introducer = ( + ASTTemplateParams.describe_signature_as_introducer = ( # type: ignore[assignment] describe_signature_as_introducer ) diff --git a/sphinx_immaterial/apidoc/generic_synopses.py b/sphinx_immaterial/apidoc/generic_synopses.py index 0d4b8fc76..e35a700be 100644 --- a/sphinx_immaterial/apidoc/generic_synopses.py +++ b/sphinx_immaterial/apidoc/generic_synopses.py @@ -26,12 +26,12 @@ def _monkey_patch_generic_object_to_support_synopses(): def transform_content(self: GenericObject, contentnode) -> None: setattr(self, "contentnode", contentnode) - orig_transform_content(self, contentnode) + orig_transform_content(self, contentnode) # type: ignore[arg-type] - GenericObject.transform_content = transform_content + GenericObject.transform_content = transform_content # type: ignore[assignment] def after_content(self: GenericObject) -> None: - orig_after_content(self) + orig_after_content(self) # type: ignore[arg-type] noindex = "noindex" in self.options if noindex: return @@ -48,7 +48,7 @@ def after_content(self: GenericObject) -> None: for name in self.names: std.data["synopses"][self.objtype, name] = synopsis - GenericObject.after_content = after_content + GenericObject.after_content = after_content # type: ignore[assignment] orig_merge_domaindata = StandardDomain.merge_domaindata @@ -56,7 +56,7 @@ def merge_domaindata(self, docnames: List[str], otherdata: dict) -> None: orig_merge_domaindata(self, docnames, otherdata) self.data["synopses"].update(otherdata["synopses"]) - StandardDomain.merge_domaindata = merge_domaindata + StandardDomain.merge_domaindata = merge_domaindata # type: ignore[assignment] def make_refnode( std: StandardDomain, @@ -108,7 +108,7 @@ def _resolve_obj_xref( self, builder, fromdocname, docname, labelid, contnode, objtype, target ) - StandardDomain._resolve_obj_xref = _resolve_obj_xref + StandardDomain._resolve_obj_xref = _resolve_obj_xref # type: ignore[assignment] def resolve_any_xref( self: StandardDomain, @@ -157,7 +157,7 @@ def resolve_any_xref( ) return results - StandardDomain.resolve_any_xref = resolve_any_xref + StandardDomain.resolve_any_xref = resolve_any_xref # type: ignore[assignment] def get_object_synopses( self: StandardDomain, @@ -169,7 +169,7 @@ def get_object_synopses( continue yield ((docname, labelid), synopsis) - StandardDomain.get_object_synopses = get_object_synopses + StandardDomain.get_object_synopses = get_object_synopses # type: ignore[attr-defined] def setup(app: sphinx.application.Sphinx): diff --git a/sphinx_immaterial/apidoc/json/domain.py b/sphinx_immaterial/apidoc/json/domain.py index e02d68f3c..662ea2a28 100644 --- a/sphinx_immaterial/apidoc/json/domain.py +++ b/sphinx_immaterial/apidoc/json/domain.py @@ -15,6 +15,7 @@ Iterator, Set, Union, + Iterable, ) import docutils @@ -340,6 +341,7 @@ def _handle_prop(prop): obj = schema.get(prop) if obj is None: return + items: Iterable[Tuple[Union[int, str], JsonSchema]] if isinstance(obj, list): items = enumerate(obj) elif isinstance(obj, dict): diff --git a/sphinx_immaterial/apidoc/object_toc.py b/sphinx_immaterial/apidoc/object_toc.py index d1adce878..f24a0073a 100644 --- a/sphinx_immaterial/apidoc/object_toc.py +++ b/sphinx_immaterial/apidoc/object_toc.py @@ -212,15 +212,18 @@ def run(self: sphinx.directives.ObjectDescription) -> List[docutils.nodes.Node]: return nodes obj_desc = nodes[-1] + assert isinstance(obj_desc, sphinx.addnodes.desc_content) obj_id = None for sig in obj_desc[:-1]: + assert isinstance(sig, sphinx.addnodes.desc_signature) ids = sig["ids"] if ids and ids[0]: obj_id = ids[0] break obj_content = obj_desc[-1] + assert isinstance(obj_content, sphinx.addnodes.desc_content) for child in obj_content: if not isinstance(child, docutils.nodes.field_list): continue @@ -236,7 +239,7 @@ def run(self: sphinx.directives.ObjectDescription) -> List[docutils.nodes.Node]: return nodes - sphinx.directives.ObjectDescription.run = run + sphinx.directives.ObjectDescription.run = run # type: ignore[assignment] _monkey_patch_object_description_to_include_fields_in_toc() @@ -265,7 +268,9 @@ def run(self: sphinx.directives.ObjectDescription) -> List[docutils.nodes.Node]: return nodes obj_desc = nodes[-1] + assert isinstance(obj_desc, sphinx.addnodes.desc) obj_content = obj_desc[-1] + assert isinstance(obj_content, sphinx.addnodes.desc_content) for child in obj_content: if not isinstance(child, docutils.nodes.rubric): continue @@ -277,7 +282,7 @@ def run(self: sphinx.directives.ObjectDescription) -> List[docutils.nodes.Node]: return nodes - sphinx.directives.ObjectDescription.run = run + sphinx.directives.ObjectDescription.run = run # type: ignore[assignment] _monkey_patch_object_description_to_include_rubrics_in_toc() diff --git a/sphinx_immaterial/apidoc/python/annotation_style.py b/sphinx_immaterial/apidoc/python/annotation_style.py index 91484503b..e0053afa3 100644 --- a/sphinx_immaterial/apidoc/python/annotation_style.py +++ b/sphinx_immaterial/apidoc/python/annotation_style.py @@ -23,7 +23,7 @@ def _monkey_patch_python_parse_annotation(): def parse_annotation( annotation: str, env: Optional[sphinx.environment.BuildEnvironment] = None ) -> List[docutils.nodes.Node]: - return ensure_wrapped_in_desc_type(orig_parse_annotation(annotation, env)) + return ensure_wrapped_in_desc_type(orig_parse_annotation(annotation, env)) # type: ignore[arg-type] sphinx.domains.python._parse_annotation = parse_annotation diff --git a/sphinx_immaterial/apidoc/python/apigen.py b/sphinx_immaterial/apidoc/python/apigen.py index 727e1197a..e31075181 100644 --- a/sphinx_immaterial/apidoc/python/apigen.py +++ b/sphinx_immaterial/apidoc/python/apigen.py @@ -1751,7 +1751,7 @@ def load_custom_sections( self, section ) # pylint: disable=protected-access - sphinx.ext.napoleon.docstring.GoogleDocstring._load_custom_sections = ( + sphinx.ext.napoleon.docstring.GoogleDocstring._load_custom_sections = ( # type: ignore[assignment] load_custom_sections # pylint: disable=protected-access ) diff --git a/sphinx_immaterial/apidoc/python/autodoc_property_type.py b/sphinx_immaterial/apidoc/python/autodoc_property_type.py index 7a2ac4c7a..aa6155a93 100644 --- a/sphinx_immaterial/apidoc/python/autodoc_property_type.py +++ b/sphinx_immaterial/apidoc/python/autodoc_property_type.py @@ -76,7 +76,7 @@ def import_object(self: PropertyDocumenter, raiseerror: bool = False) -> bool: self.retann = new_retann return True - PropertyDocumenter.import_object = import_object + PropertyDocumenter.import_object = import_object # type: ignore[assignment] old_add_directive_header = PropertyDocumenter.add_directive_header @@ -98,7 +98,7 @@ def add_directive_header(self, sig: str) -> None: # Type annotation not already added. self.add_line(" :type: " + retann, self.get_sourcename()) - PropertyDocumenter.add_directive_header = add_directive_header + PropertyDocumenter.add_directive_header = add_directive_header # type: ignore[assignment] # Modify PyProperty to improve formatting of :type: option PyProperty = sphinx.domains.python.PyProperty @@ -115,7 +115,7 @@ def handle_signature( return fullname, prefix - PyProperty.handle_signature = handle_signature + PyProperty.handle_signature = handle_signature # type: ignore[assignment] apply_property_documenter_type_annotation_fix() diff --git a/sphinx_immaterial/apidoc/python/object_ids.py b/sphinx_immaterial/apidoc/python/object_ids.py index 6dcc62158..698650eb6 100644 --- a/sphinx_immaterial/apidoc/python/object_ids.py +++ b/sphinx_immaterial/apidoc/python/object_ids.py @@ -29,7 +29,7 @@ def add_directive_header(self: sphinx.ext.autodoc.Documenter, sig: str) -> None: value = self.options[option_name] self.add_line(f" :{option_name}: {value}", self.get_sourcename()) - sphinx.ext.autodoc.Documenter.add_directive_header = add_directive_header + sphinx.ext.autodoc.Documenter.add_directive_header = add_directive_header # type: ignore[assignment] orig_handle_signature = sphinx.domains.python.PyObject.handle_signature @@ -70,7 +70,7 @@ def handle_signature( ) return fullname, prefix - sphinx.domains.python.PyObject.handle_signature = handle_signature + sphinx.domains.python.PyObject.handle_signature = handle_signature # type: ignore[assignment] orig_after_content = PyObject.after_content @@ -121,7 +121,7 @@ def strip_object_entry_node_id(existing_node_id: str, object_id: str): "entries" ] = new_entries - PyObject.after_content = after_content + PyObject.after_content = after_content # type: ignore[assignment] _monkey_patch_python_domain_to_support_object_ids() diff --git a/sphinx_immaterial/apidoc/python/parameter_objects.py b/sphinx_immaterial/apidoc/python/parameter_objects.py index e25780bc5..9230dfeb7 100644 --- a/sphinx_immaterial/apidoc/python/parameter_objects.py +++ b/sphinx_immaterial/apidoc/python/parameter_objects.py @@ -74,7 +74,7 @@ def handle_item(fieldarg: str, content: Any) -> docutils.nodes.Node: fieldbody = docutils.nodes.field_body("", bodynode) return docutils.nodes.field("", fieldname, fieldbody) - PyTypedField.make_field = make_field + PyTypedField.make_field = make_field # type: ignore[assignment] class PyParamXRefRole(sphinx.domains.python.PyXRefRole): @@ -116,7 +116,7 @@ def before_content(self: PyObject) -> None: else: self.env.ref_context.pop("py:func", None) - PyObject.before_content = before_content + PyObject.before_content = before_content # type: ignore[assignment] orig_after_content = PyObject.after_content @@ -133,7 +133,7 @@ def after_content(self: PyObject) -> None: else: self.env.ref_context["py:func"] = prev_py_func - PyObject.after_content = after_content + PyObject.after_content = after_content # type: ignore[assignment] def _monkey_patch_python_domain_to_resolve_params(): @@ -168,7 +168,7 @@ def resolve_xref( raise sphinx.errors.NoUri return result - PythonDomain.resolve_xref = resolve_xref + PythonDomain.resolve_xref = resolve_xref # type: ignore[assignment] orig_resolve_any_xref = PythonDomain.resolve_any_xref @@ -188,7 +188,7 @@ def resolve_any_xref( # ambiguities. return [r for r in results if r[0] != "py:param"] - PythonDomain.resolve_any_xref = resolve_any_xref + PythonDomain.resolve_any_xref = resolve_any_xref # type: ignore[assignment] OBJECT_PRIORITY_DEFAULT = 1 @@ -217,7 +217,7 @@ def get_objects( OBJECT_PRIORITY_UNIMPORTANT, ) - PythonDomain.get_objects = get_objects + PythonDomain.get_objects = get_objects # type: ignore[assignment] def _add_parameter_links_to_signature( @@ -500,7 +500,7 @@ def after_content(self: PyObject) -> None: noindex=noindex, ) - PyObject.after_content = after_content + PyObject.after_content = after_content # type: ignore[assignment] _monkey_patch_python_domain_to_cross_link_parameters() diff --git a/sphinx_immaterial/apidoc/python/section_titles.py b/sphinx_immaterial/apidoc/python/section_titles.py index 0fa55aad7..59f0de640 100644 --- a/sphinx_immaterial/apidoc/python/section_titles.py +++ b/sphinx_immaterial/apidoc/python/section_titles.py @@ -27,10 +27,10 @@ def transform_content(self: PyObject, contentnode: docutils.nodes.Node) -> None: getattr(self, "_saved_content"), contentnode, ) - orig_transform_content(self, contentnode) + orig_transform_content(self, contentnode) # type: ignore[arg-type] - PyObject.before_content = before_content - PyObject.transform_content = transform_content + PyObject.before_content = before_content # type: ignore[assignment] + PyObject.transform_content = transform_content # type: ignore[assignment] _monkey_patch_python_domain_to_support_titles() diff --git a/sphinx_immaterial/apidoc/python/synopses.py b/sphinx_immaterial/apidoc/python/synopses.py index cab8bd166..4fe82121e 100644 --- a/sphinx_immaterial/apidoc/python/synopses.py +++ b/sphinx_immaterial/apidoc/python/synopses.py @@ -51,7 +51,7 @@ def resolve_xref( _add_synopsis(self, env, refnode) return refnode - PythonDomain.resolve_xref = resolve_xref + PythonDomain.resolve_xref = resolve_xref # type: ignore[assignment] orig_resolve_any_xref = PythonDomain.resolve_any_xref @@ -71,7 +71,7 @@ def resolve_any_xref( _add_synopsis(self, env, refnode) return results - PythonDomain.resolve_any_xref = resolve_any_xref + PythonDomain.resolve_any_xref = resolve_any_xref # type: ignore[assignment] def _monkey_patch_python_domain_to_support_synopses(): @@ -82,9 +82,9 @@ def _monkey_patch_python_domain_to_support_synopses(): def transform_content(self: PyObject, contentnode) -> None: setattr(self, "contentnode", contentnode) - orig_transform_content(self, contentnode) + orig_transform_content(self, contentnode) # type: ignore[arg-type] - PyObject.transform_content = transform_content + PyObject.transform_content = transform_content # type: ignore[assignment] def after_content(self: PyObject) -> None: orig_after_content(self) @@ -123,7 +123,7 @@ def after_content(self: PyObject) -> None: for symbol in symbols: py.data["synopses"][symbol] = synopsis - PyObject.after_content = after_content + PyObject.after_content = after_content # type: ignore[assignment] orig_merge_domaindata = PythonDomain.merge_domaindata @@ -131,7 +131,7 @@ def merge_domaindata(self, docnames: List[str], otherdata: dict) -> None: orig_merge_domaindata(self, docnames, otherdata) self.data["synopses"].update(otherdata["synopses"]) - PythonDomain.merge_domaindata = merge_domaindata + PythonDomain.merge_domaindata = merge_domaindata # type: ignore[assignment] def get_object_synopses( self: PythonDomain, @@ -143,7 +143,7 @@ def get_object_synopses( continue yield ((obj.docname, obj.node_id), synopsis) - PythonDomain.get_object_synopses = get_object_synopses + PythonDomain.get_object_synopses = get_object_synopses # type: ignore[attr-defined] _monkey_patch_python_domain_to_add_object_synopses_to_references() diff --git a/sphinx_immaterial/apidoc/python/type_annotation_transforms.py b/sphinx_immaterial/apidoc/python/type_annotation_transforms.py index 5f791fc35..ed5d862af 100644 --- a/sphinx_immaterial/apidoc/python/type_annotation_transforms.py +++ b/sphinx_immaterial/apidoc/python/type_annotation_transforms.py @@ -373,7 +373,7 @@ def type_to_xref( node.append(docutils.nodes.Text(new_target)) return node - sphinx.domains.python.type_to_xref = type_to_xref + sphinx.domains.python.type_to_xref = type_to_xref # type: ignore[assignment] def setup(app: sphinx.application.Sphinx): diff --git a/sphinx_immaterial/custom_admonitions.py b/sphinx_immaterial/custom_admonitions.py index de2bb79ca..eacbde6ac 100644 --- a/sphinx_immaterial/custom_admonitions.py +++ b/sphinx_immaterial/custom_admonitions.py @@ -5,7 +5,7 @@ import hashlib from pathlib import Path, PurePath import re -from typing import List, Dict, Any, Tuple, Optional, Type, Union +from typing import List, Dict, Any, Tuple, Optional, Type, Union, cast from docutils import nodes from docutils.parsers.rst import directives, Directive import jinja2 @@ -84,7 +84,7 @@ class CustomAdmonitionConfig(pydantic.BaseModel): def validate_name(cls, val): illegal = re.findall(r"([^a-zA-Z0-9\-_])", val) if illegal: - raise pydantic.ValidationError( + raise ValueError( f"The following characters are illegal for directive names: {illegal}" ) return val @@ -99,9 +99,7 @@ def validate_title(cls, val, values): def validate_color_component(cls, val): if 0 <= val <= 255: return val - raise pydantic.ValidationError( - f"color component {val} is not in range [0, 255]" - ) + raise ValueError(f"color component {val} is not in range [0, 255]") @pydantic.validator("classes", each_item=True) def conform_classes(cls, val): @@ -132,7 +130,7 @@ def visit_admonition(self: HTML5Translator, node: nodes.Element, name: str = "") else: orig_func(self, node, name) - HTML5Translator.visit_admonition = visit_admonition + HTML5Translator.visit_admonition = visit_admonition # type: ignore[assignment] def patch_depart_admonition(): @@ -144,7 +142,7 @@ def depart_admonition(self: HTML5Translator, node: Optional[nodes.Element] = Non else: self.body.append("\n") - HTML5Translator.depart_admonition = depart_admonition + HTML5Translator.depart_admonition = depart_admonition # type: ignore[assignment] class CustomAdmonitionDirective(Directive, ABC): @@ -155,7 +153,7 @@ class CustomAdmonitionDirective(Directive, ABC): argument parsing for other derivative classes. """ - node_class: Type[nodes.Admonition] = nodes.admonition + node_class: Type[nodes.admonition] = nodes.admonition optional_arguments: int final_argument_whitespace: bool = True has_content = True @@ -186,10 +184,10 @@ def run(self): if not title_text: title_text = self.default_title self.assert_has_content() - admonition_node = self.node_class("\n".join(self.content), **self.options) + admonition_node = self.node_class("\n".join(self.content), **self.options) # type: ignore[call-arg] ( - admonition_node.source, - admonition_node.line, + admonition_node.source, # type: ignore[attr-defined] + admonition_node.line, # type: ignore[attr-defined] ) = self.state_machine.get_source_and_line(self.lineno) if isinstance(admonition_node, sphinx.ext.todo.todo_node): # todo admonitions need extra info for the todolist directive @@ -239,7 +237,10 @@ class CustomizedAdmonition(CustomAdmonitionDirective): default_title = title classes = class_list optional_arguments = int(name not in admonitionlabels) - node_class = nodes.admonition if name != "todo" else sphinx.ext.todo.todo_node + node_class = cast( + Type[nodes.admonition], + nodes.admonition if name != "todo" else sphinx.ext.todo.todo_node, + ) return CustomizedAdmonition diff --git a/sphinx_immaterial/default_literal_role.py b/sphinx_immaterial/default_literal_role.py index 4c1930eaf..a13e116f4 100644 --- a/sphinx_immaterial/default_literal_role.py +++ b/sphinx_immaterial/default_literal_role.py @@ -95,7 +95,7 @@ def enable(self): orig_enable(self) setattr(self, "_literal_func", Inliner.dispatch[_LITERAL_KEY]) - CustomReSTDispatcher.enable = enable + CustomReSTDispatcher.enable = enable # type: ignore[assignment] orig_disable = CustomReSTDispatcher.disable @@ -103,7 +103,7 @@ def disable(self): Inliner.dispatch[_LITERAL_KEY] = getattr(self, "_literal_func") orig_disable(self) - CustomReSTDispatcher.disable = disable + CustomReSTDispatcher.disable = disable # type: ignore[assignment] _monkey_patch_custom_rest_dispatcher() diff --git a/sphinx_immaterial/highlight_push_pop.py b/sphinx_immaterial/highlight_push_pop.py index 0003b5ea9..54e1b9bb7 100644 --- a/sphinx_immaterial/highlight_push_pop.py +++ b/sphinx_immaterial/highlight_push_pop.py @@ -72,7 +72,7 @@ def visit_highlightlang(self, node: sphinx.addnodes.highlightlang) -> None: else: orig_visit_highlightlang(self, node) - HighlightLanguageVisitor.visit_highlightlang = visit_highlightlang + HighlightLanguageVisitor.visit_highlightlang = visit_highlightlang # type: ignore[assignment] _monkey_patch_highlight_language_visitor() diff --git a/sphinx_immaterial/search_adapt.py b/sphinx_immaterial/search_adapt.py index 13867acee..4ac0692d1 100644 --- a/sphinx_immaterial/search_adapt.py +++ b/sphinx_immaterial/search_adapt.py @@ -182,7 +182,7 @@ def load( def _monkey_patch_index_builder(): - sphinx.search.IndexBuilder = IndexBuilder + sphinx.search.IndexBuilder = IndexBuilder # type: ignore[misc] def setup(app: sphinx.application.Sphinx): diff --git a/sphinx_immaterial/theme_result.py b/sphinx_immaterial/theme_result.py index 410189ea6..6290ec3b8 100644 --- a/sphinx_immaterial/theme_result.py +++ b/sphinx_immaterial/theme_result.py @@ -24,7 +24,7 @@ def run(self): "", classes=self.options.get("class", []) + ["results"] ) code = "\n".join(self.content) - literal_node = nodes.literal_block(code, code) + literal_node: nodes.Element = nodes.literal_block(code, code) literal_node["language"] = "rst" if self.arguments: literal_node = container_wrapper(self, literal_node, self.arguments[0])