summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Carrano <juan.carrano@ebee.berlin>2020-08-21 13:53:36 +0200
committerJuan Carrano <juan.carrano@ebee.berlin>2020-08-21 18:47:14 +0200
commit642686159fb18fb3eec00563aa4773b941dad5bb (patch)
tree6c697f114ea8ad53f24e75f291090017da43e1b3
parent9d48cb9798a1f2eea8a800689dde6648e260916f (diff)
downloadsphinx-git-642686159fb18fb3eec00563aa4773b941dad5bb.tar.gz
autodoc: Test the signature of typing.Generic subclasses.
This test is currently failing because typing.Generic.__new__ clobbers the real signature.
-rw-r--r--tests/roots/test-ext-autodoc/target/generic_class.py12
-rw-r--r--tests/test_ext_autodoc.py16
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/roots/test-ext-autodoc/target/generic_class.py b/tests/roots/test-ext-autodoc/target/generic_class.py
new file mode 100644
index 000000000..cf4c5ed37
--- /dev/null
+++ b/tests/roots/test-ext-autodoc/target/generic_class.py
@@ -0,0 +1,12 @@
+from typing import TypeVar, Generic
+
+
+T = TypeVar('T')
+
+
+# Test that typing.Generic's __new__ method does not mask our class'
+# __init__ signature.
+class A(Generic[T]):
+ """docstring for A"""
+ def __init__(self, a, b=None):
+ pass
diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py
index 90a2ec95a..e90125ba9 100644
--- a/tests/test_ext_autodoc.py
+++ b/tests/test_ext_autodoc.py
@@ -290,6 +290,22 @@ def test_format_signature(app):
'(b, c=42, *d, **e)'
+@pytest.mark.skipif(sys.version_info < (3, 5), reason='typing is available since python3.5.')
+@pytest.mark.xfail
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_autodoc_process_signature_typing_generic(app):
+ actual = do_autodoc(app, 'class', 'target.generic_class.A', {})
+
+ assert list(actual) == [
+ '',
+ '.. py:class:: A(a, b=None)',
+ ' :module: target.generic_class',
+ '',
+ ' docstring for A',
+ '',
+ ]
+
+
def test_autodoc_process_signature_typehints(app):
captured = []