Skip to content

Commit

Permalink
skip type annotations for 3.7, which fails for unknown reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Nov 17, 2021
1 parent 2f23f7d commit 59c3f83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions sphinx_autodoc_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ def _is_dataclass(name: str, what: str, qualname: str) -> bool:


def _future_annotations_imported(obj):
if sys.version_info < (3, 7):
# Only Python ≥ 3.7 supports PEP563.
if sys.version_info < (3, 8):
# Only Python ≥ 3.7 supports PEP563, however
# Python 3.7 doesn't give the expected results.
# TODO: make it work for Python 3.7.
return False

_annotations = getattr(inspect.getmodule(obj), "annotations", None)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_sphinx_autodoc_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ def test_sphinx_output(app, status, warning, always_document_param_types):

app.config.always_document_param_types = always_document_param_types
app.config.autodoc_mock_imports = ['mailbox']
if sys.version_info < (3, 7):
if sys.version_info < (3, 8):
# TODO: fix for Python 3.7
app.config.autodoc_mock_imports.append('dummy_module_future_annotations')
app.build()

Expand Down Expand Up @@ -558,7 +559,8 @@ class dummy_module.DataClass(x)
assert text_contents == maybe_fix_py310(expected_contents)


@pytest.mark.skipif(sys.version_info < (3, 7),
# TODO: fix for Python 3.7, which *should* work but fails for unknown reasons
@pytest.mark.skipif(sys.version_info < (3, 8),
reason="Future annotations are not implemented in Python < 3.7")
@pytest.mark.sphinx('text', testroot='dummy')
@patch('sphinx.writers.text.MAXWIDTH', 2000)
Expand Down

0 comments on commit 59c3f83

Please sign in to comment.