@@ -50,23 +50,28 @@ def parse(sig):
5050
5151
5252def test_function_signatures ():
53- rv = parse ('func(a=1) -> int object' )
54- assert rv == '(a=1)'
55-
56- rv = parse ('func(a=1, [b=None])' )
57- assert rv == '(a=1, [b=None])'
58-
59- rv = parse ('func(a=1[, b=None])' )
60- assert rv == '(a=1, [b=None])'
61-
6253 rv = parse ("compile(source : string, filename, symbol='file')" )
6354 assert rv == "(source : string, filename, symbol='file')"
6455
65- rv = parse ('func(a=[], [b=None])' )
66- assert rv == '(a=[], [b=None])'
67-
68- rv = parse ('func(a=[][, b=None])' )
69- assert rv == '(a=[], [b=None])'
56+ for params , expect in [
57+ ('(a=1)' , '(a=1)' ),
58+ ('(a: int = 1)' , '(a: int = 1)' ),
59+ ('(a=1, [b=None])' , '(a=1, [b=None])' ),
60+ ('(a=1[, b=None])' , '(a=1, [b=None])' ),
61+ ('(a=[], [b=None])' , '(a=[], [b=None])' ),
62+ ('(a=[][, b=None])' , '(a=[], [b=None])' ),
63+ ('(a: Foo[Bar]=[][, b=None])' , '(a: Foo[Bar]=[], [b=None])' ),
64+ ]:
65+ rv = parse (f'func{ params } ' )
66+ assert rv == expect
67+
68+ # Note: 'def f[Foo[Bar]]()' is not valid Python but people might write
69+ # it in a reST document to convene the intent of a higher-kinded type
70+ # variable.
71+ for tparams in ['' , '[Foo]' , '[Foo[Bar]]' ]:
72+ for retann in ['' , '-> Foo' , '-> Foo[Bar]' , '-> anything else' ]:
73+ rv = parse (f'func{ tparams } { params } { retann } ' .rstrip ())
74+ assert rv == expect
7075
7176
7277@pytest .mark .sphinx ('dummy' , testroot = 'domain-py' )
@@ -1710,6 +1715,10 @@ def test_pep_695_and_pep_696_whitespaces_in_bound(app, tp_list, tptext):
17101715 doctree = restructuredtext .parse (app , text )
17111716 assert doctree .astext () == f'\n \n f{ tptext } ()\n \n '
17121717
1718+ text = f'.. py:function:: f{ tp_list } () -> Annotated[T, Qux[int]()]'
1719+ doctree = restructuredtext .parse (app , text )
1720+ assert doctree .astext () == f'\n \n f{ tptext } () -> Annotated[T, Qux[int]()]\n \n '
1721+
17131722
17141723@pytest .mark .parametrize (
17151724 ('tp_list' , 'tptext' ),
@@ -1724,6 +1733,10 @@ def test_pep_695_and_pep_696_whitespaces_in_constraints(app, tp_list, tptext):
17241733 doctree = restructuredtext .parse (app , text )
17251734 assert doctree .astext () == f'\n \n f{ tptext } ()\n \n '
17261735
1736+ text = f'.. py:function:: f{ tp_list } () -> Annotated[T, Qux[int]()]'
1737+ doctree = restructuredtext .parse (app , text )
1738+ assert doctree .astext () == f'\n \n f{ tptext } () -> Annotated[T, Qux[int]()]\n \n '
1739+
17271740
17281741@pytest .mark .parametrize (
17291742 ('tp_list' , 'tptext' ),
@@ -1747,3 +1760,7 @@ def test_pep_695_and_pep_696_whitespaces_in_default(app, tp_list, tptext):
17471760 text = f'.. py:function:: f{ tp_list } ()'
17481761 doctree = restructuredtext .parse (app , text )
17491762 assert doctree .astext () == f'\n \n f{ tptext } ()\n \n '
1763+
1764+ text = f'.. py:function:: f{ tp_list } () -> Annotated[T, Qux[int]()]'
1765+ doctree = restructuredtext .parse (app , text )
1766+ assert doctree .astext () == f'\n \n f{ tptext } () -> Annotated[T, Qux[int]()]\n \n '
0 commit comments