@@ -130,11 +130,15 @@ def test_subscription_error(self, doctype):
130130 "Literal[SomeEnum.FIRST, 3]" ,
131131 # Nesting
132132 "dict[Literal['a', 'b'], int]" ,
133+ # Custom qualname for literal
134+ "MyLiteral[0]" ,
135+ "MyLiteral[SomeEnum.FIRST]" ,
133136 ],
134137 )
135138 def test_literals (self , doctype ):
136139 expr = parse_doctype (doctype )
137140 assert expr .as_code () == doctype
141+ assert "literal" in [e .rule for e in expr .sub_expressions ]
138142
139143 @pytest .mark .parametrize (
140144 ("doctype" , "expected" ),
@@ -165,6 +169,7 @@ def test_literals(self, doctype):
165169 def test_natlang_literals (self , doctype , expected ):
166170 expr = parse_doctype (doctype )
167171 assert expr .as_code () == expected
172+ assert "natlang_literal" in [e .rule for e in expr .sub_expressions ]
168173
169174 def test_single_natlang_literal_warning (self , caplog ):
170175 expr = parse_doctype ("{True}" )
@@ -220,6 +225,7 @@ def test_optional_info(self, doctype, expected, optional_info):
220225 def test_callable (self , doctype ):
221226 expr = parse_doctype (doctype )
222227 assert expr .as_code () == doctype
228+ assert "callable" in [e .rule for e in expr .sub_expressions ]
223229
224230 @pytest .mark .parametrize (
225231 "doctype" ,
@@ -240,7 +246,7 @@ def test_callable_error(self, doctype):
240246 (":class:`Generator`" , "Generator" ),
241247 (":py:class:`Generator`" , "Generator" ),
242248 (":py:class:`Generator`[int]" , "Generator[int]" ),
243- (":py:ref:`~.Foo`[int]" , "_Foo [int]" ),
249+ (":py:ref:`~.Foo`[int]" , "~.Foo [int]" ),
244250 ("list[:py:class:`Generator`]" , "list[Generator]" ),
245251 ],
246252 )
@@ -284,31 +290,3 @@ def test_natlang_array_invalid_shape(self, shape):
284290 doctype = f"array of shape { shape } "
285291 with pytest .raises (lark .exceptions .UnexpectedInput ):
286292 _ = parse_doctype (doctype )
287-
288- def test_unknown_name (self ):
289- # Simple unknown name is aliased to typing.Any
290- annotation , unknown_names = parse_doctype ("a" )
291- assert annotation .value == "a"
292- assert annotation .imports == {
293- PyImport (import_ = "Incomplete" , from_ = "_typeshed" , as_ = "a" )
294- }
295- assert unknown_names == [("a" , 0 , 1 )]
296-
297- def test_unknown_qualname (self ):
298- # Unknown qualified name is escaped and aliased to typing.Any as well
299- annotation , unknown_names = parse_doctype ("a.b" )
300- assert annotation .value == "a_b"
301- assert annotation .imports == {
302- PyImport (import_ = "Incomplete" , from_ = "_typeshed" , as_ = "a_b" )
303- }
304- assert unknown_names == [("a.b" , 0 , 3 )]
305-
306- def test_multiple_unknown_names (self ):
307- # Multiple names are aliased to typing.Any
308- annotation , unknown_names = parse_doctype ("a.b of c" )
309- assert annotation .value == "a_b[c]"
310- assert annotation .imports == {
311- PyImport (import_ = "Incomplete" , from_ = "_typeshed" , as_ = "a_b" ),
312- PyImport (import_ = "Incomplete" , from_ = "_typeshed" , as_ = "c" ),
313- }
314- assert unknown_names == [("a.b" , 0 , 3 ), ("c" , 7 , 8 )]
0 commit comments