@@ -108,12 +108,26 @@ def test_subscription_error(self, doctype):
108108 ("doctype" , "expected" ),
109109 [
110110 ("{0}" , "Literal[0]" ),
111- ("{'a', 1, None, False}" , "Literal['a', 1, None, False]" ),
112- ("dict[{'a', 'b'}, int]" , "dict[Literal['a', 'b'], int]" ),
111+ ("{-1, 1}" , "Literal[-1, 1]" ),
112+ ("{None}" , "Literal[None]" ),
113+ ("{True, False}" , "Literal[True, False]" ),
114+ ("""{'a', "bar"}""" , """Literal['a', "bar"]""" ),
115+ # Enum
113116 ("{SomeEnum.FIRST}" , "Literal[SomeEnum_FIRST]" ),
114117 ("{`SomeEnum.FIRST`, 1}" , "Literal[SomeEnum_FIRST, 1]" ),
115118 ("{:ref:`SomeEnum.FIRST`, 2}" , "Literal[SomeEnum_FIRST, 2]" ),
116119 ("{:py:ref:`SomeEnum.FIRST`, 3}" , "Literal[SomeEnum_FIRST, 3]" ),
120+ # Nesting
121+ ("dict[{'a', 'b'}, int]" , "dict[Literal['a', 'b'], int]" ),
122+ # These aren't officially valid as an argument to `Literal` (yet)
123+ # https://typing.python.org/en/latest/spec/literal.html
124+ # TODO figure out how docstub should deal with these
125+ ("{-2., 1.}" , "Literal[-2., 1.]" ),
126+ pytest .param (
127+ "{-inf, inf, nan}" ,
128+ "Literal[, 1.]" ,
129+ marks = pytest .mark .xfail (reason = "unsure how to support" ),
130+ ),
117131 ],
118132 )
119133 def test_literals (self , doctype , expected ):
@@ -188,6 +202,13 @@ def escape(name: str) -> str:
188202 assert annotation .value == expected
189203 # fmt: on
190204
205+ @pytest .mark .parametrize ("shape" , ["(-1, 3)" , "(1.0, 2)" , "-3D" , "-2-D" ])
206+ def test_natlang_array_invalid_shape (self , shape ):
207+ doctype = f"array of shape { shape } "
208+ transformer = DoctypeTransformer ()
209+ with pytest .raises (lark .exceptions .UnexpectedInput ):
210+ transformer .doctype_to_annotation (doctype )
211+
191212 def test_unknown_name (self ):
192213 # Simple unknown name is aliased to typing.Any
193214 transformer = DoctypeTransformer ()
0 commit comments