Skip to content

Commit

Permalink
autodoc: Test the signature of typing.Generic subclasses.
Browse files Browse the repository at this point in the history
This test is currently failing because typing.Generic.__new__ clobbers the
real signature.
  • Loading branch information
jcarrano committed Aug 21, 2020
1 parent 9d48cb9 commit 398a7f8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_ext_autodoc.py
Expand Up @@ -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 = []

Expand Down

0 comments on commit 398a7f8

Please sign in to comment.