Skip to content

Commit fdad0d7

Browse files
authored
Fix mypy errors due to unneeded type ignores (#469)
It seems we brought in better sphinx types due to an upstream change?
1 parent df66980 commit fdad0d7

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ def process_docstring( # noqa: PLR0913, PLR0917
653653

654654
localns = TypeAliasNamespace(app.config["autodoc_type_aliases"])
655655
type_hints = get_all_type_hints(app.config.autodoc_mock_imports, obj, name, localns)
656-
app.config._annotation_globals = getattr(obj, "__globals__", {}) # type: ignore[attr-defined] # noqa: SLF001
656+
app.config._annotation_globals = getattr(obj, "__globals__", {}) # noqa: SLF001
657657
try:
658658
_inject_types_to_docstring(type_hints, signature, original_obj, app, what, name, lines)
659659
finally:

tests/test_sphinx_autodoc_typehints.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ def test_always_document_param_types(
565565
) -> None:
566566
set_python_path()
567567

568-
app.config.always_document_param_types = always_document_param_types # type: ignore[attr-defined] # create flag
569-
app.config.autodoc_mock_imports = ["mailbox"] # type: ignore[attr-defined] # create flag
568+
app.config.always_document_param_types = always_document_param_types # create flag
569+
app.config.autodoc_mock_imports = ["mailbox"] # create flag
570570

571571
# Prevent "document isn't included in any toctree" warnings
572572
for f in Path(app.srcdir).glob("*.rst"):
@@ -633,7 +633,7 @@ def maybe_fix_py310(expected_contents: str) -> str:
633633
def test_sphinx_output_future_annotations(app: SphinxTestApp, status: StringIO) -> None:
634634
set_python_path()
635635

636-
app.config.master_doc = "future_annotations" # type: ignore[attr-defined] # create flag
636+
app.config.master_doc = "future_annotations" # create flag
637637
app.build()
638638

639639
assert "build succeeded" in status.getvalue() # Build succeeded
@@ -667,8 +667,8 @@ def test_sphinx_output_future_annotations(app: SphinxTestApp, status: StringIO)
667667
def test_sphinx_output_default_role(app: SphinxTestApp, status: StringIO) -> None:
668668
set_python_path()
669669

670-
app.config.master_doc = "simple_default_role" # type: ignore[attr-defined] # create flag
671-
app.config.default_role = "literal" # type: ignore[attr-defined]
670+
app.config.master_doc = "simple_default_role" # create flag
671+
app.config.default_role = "literal"
672672
app.build()
673673

674674
assert "build succeeded" in status.getvalue() # Build succeeded
@@ -716,8 +716,8 @@ def test_sphinx_output_defaults(
716716
) -> None:
717717
set_python_path()
718718

719-
app.config.master_doc = "simple" # type: ignore[attr-defined] # create flag
720-
app.config.typehints_defaults = defaults_config_val # type: ignore[attr-defined] # create flag
719+
app.config.master_doc = "simple" # create flag
720+
app.config.typehints_defaults = defaults_config_val # create flag
721721
if isinstance(expected, Exception):
722722
with pytest.raises(Exception, match=re.escape(str(expected))):
723723
app.build()
@@ -763,8 +763,8 @@ def test_sphinx_output_formatter(
763763
) -> None:
764764
set_python_path()
765765

766-
app.config.master_doc = "simple" # type: ignore[attr-defined] # create flag
767-
app.config.typehints_formatter = formatter_config_val # type: ignore[attr-defined] # create flag
766+
app.config.master_doc = "simple" # create flag
767+
app.config.typehints_formatter = formatter_config_val # create flag
768768
if isinstance(expected, Exception):
769769
with pytest.raises(Exception, match=re.escape(str(expected))):
770770
app.build()
@@ -888,7 +888,7 @@ def func(x): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202
888888
@pytest.mark.sphinx("text", testroot="resolve-typing-guard")
889889
def test_resolve_typing_guard_imports(app: SphinxTestApp, status: StringIO, warning: StringIO) -> None:
890890
set_python_path()
891-
app.config.autodoc_mock_imports = ["viktor"] # type: ignore[attr-defined] # create flag
891+
app.config.autodoc_mock_imports = ["viktor"] # create flag
892892
app.build()
893893
out = status.getvalue()
894894
assert "build succeeded" in out
@@ -917,8 +917,8 @@ def test_no_source_code_type_guard() -> None:
917917
@patch("sphinx.writers.text.MAXWIDTH", 2000)
918918
def test_sphinx_output_formatter_no_use_rtype(app: SphinxTestApp, status: StringIO) -> None:
919919
set_python_path()
920-
app.config.master_doc = "simple_no_use_rtype" # type: ignore[attr-defined] # create flag
921-
app.config.typehints_use_rtype = False # type: ignore[attr-defined]
920+
app.config.master_doc = "simple_no_use_rtype" # create flag
921+
app.config.typehints_use_rtype = False
922922
app.build()
923923
assert "build succeeded" in status.getvalue()
924924
text_path = Path(app.srcdir) / "_build" / "text" / "simple_no_use_rtype.txt"
@@ -982,8 +982,8 @@ def test_sphinx_output_formatter_no_use_rtype(app: SphinxTestApp, status: String
982982
@patch("sphinx.writers.text.MAXWIDTH", 2000)
983983
def test_sphinx_output_with_use_signature(app: SphinxTestApp, status: StringIO) -> None:
984984
set_python_path()
985-
app.config.master_doc = "simple" # type: ignore[attr-defined] # create flag
986-
app.config.typehints_use_signature = True # type: ignore[attr-defined]
985+
app.config.master_doc = "simple" # create flag
986+
app.config.typehints_use_signature = True
987987
app.build()
988988
assert "build succeeded" in status.getvalue()
989989
text_path = Path(app.srcdir) / "_build" / "text" / "simple.txt"
@@ -1011,8 +1011,8 @@ def test_sphinx_output_with_use_signature(app: SphinxTestApp, status: StringIO)
10111011
@patch("sphinx.writers.text.MAXWIDTH", 2000)
10121012
def test_sphinx_output_with_use_signature_return(app: SphinxTestApp, status: StringIO) -> None:
10131013
set_python_path()
1014-
app.config.master_doc = "simple" # type: ignore[attr-defined] # create flag
1015-
app.config.typehints_use_signature_return = True # type: ignore[attr-defined]
1014+
app.config.master_doc = "simple" # create flag
1015+
app.config.typehints_use_signature_return = True
10161016
app.build()
10171017
assert "build succeeded" in status.getvalue()
10181018
text_path = Path(app.srcdir) / "_build" / "text" / "simple.txt"
@@ -1040,9 +1040,9 @@ def test_sphinx_output_with_use_signature_return(app: SphinxTestApp, status: Str
10401040
@patch("sphinx.writers.text.MAXWIDTH", 2000)
10411041
def test_sphinx_output_with_use_signature_and_return(app: SphinxTestApp, status: StringIO) -> None:
10421042
set_python_path()
1043-
app.config.master_doc = "simple" # type: ignore[attr-defined] # create flag
1044-
app.config.typehints_use_signature = True # type: ignore[attr-defined]
1045-
app.config.typehints_use_signature_return = True # type: ignore[attr-defined]
1043+
app.config.master_doc = "simple" # create flag
1044+
app.config.typehints_use_signature = True
1045+
app.config.typehints_use_signature_return = True
10461046
app.build()
10471047
assert "build succeeded" in status.getvalue()
10481048
text_path = Path(app.srcdir) / "_build" / "text" / "simple.txt"
@@ -1070,8 +1070,8 @@ def test_sphinx_output_with_use_signature_and_return(app: SphinxTestApp, status:
10701070
@patch("sphinx.writers.text.MAXWIDTH", 2000)
10711071
def test_default_annotation_without_typehints(app: SphinxTestApp, status: StringIO) -> None:
10721072
set_python_path()
1073-
app.config.master_doc = "without_complete_typehints" # type: ignore[attr-defined]# create flag
1074-
app.config.typehints_defaults = "comma" # type: ignore[attr-defined]
1073+
app.config.master_doc = "without_complete_typehints" # create flag
1074+
app.config.typehints_defaults = "comma"
10751075
app.build()
10761076
assert "build succeeded" in status.getvalue()
10771077
text_path = Path(app.srcdir) / "_build" / "text" / "without_complete_typehints.txt"

0 commit comments

Comments
 (0)