From 398a7f8579636aedd164988101ad7ad33fe946c5 Mon Sep 17 00:00:00 2001 From: Juan Carrano Date: Fri, 21 Aug 2020 13:53:36 +0200 Subject: [PATCH] autodoc: Test the signature of typing.Generic subclasses. This test is currently failing because typing.Generic.__new__ clobbers the real signature. --- tests/test_ext_autodoc.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py index 90a2ec95a37..d88e0bf7eac 100644 --- a/tests/test_ext_autodoc.py +++ b/tests/test_ext_autodoc.py @@ -290,6 +290,36 @@ def foo3(self, d='\n'): '(b, c=42, *d, **e)' +@pytest.mark.skipif(sys.version_info < (3, 5), reason='typing is available since python3.5.') +@pytest.mark.xfail +def test_autodoc_process_signature_typing_generic(app): + import typing + + # Test that typing.Generic's __new__ method does not mask our class' + # __init__ signature. + T = typing.TypeVar('T') + + class A(typing.Generic[T]): + def __init__(self, a, b=None): + pass + + directive = make_directive_bridge(app.env) + + inst = app.registry.documenters['class'](directive, 'A') + inst.fullname = 'A' + inst.doc_as_attr = False # for class objtype + inst.parent = object # dummy + inst.object = A + inst.objpath = ['A'] + inst.args = None + inst.retann = None + + sig = inst.format_signature() + print(sig) + + assert sig == '(a, b=None)' + + def test_autodoc_process_signature_typehints(app): captured = []