@@ -108,12 +108,26 @@ def test_subscription_error(self, doctype):
108
108
("doctype" , "expected" ),
109
109
[
110
110
("{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
113
116
("{SomeEnum.FIRST}" , "Literal[SomeEnum_FIRST]" ),
114
117
("{`SomeEnum.FIRST`, 1}" , "Literal[SomeEnum_FIRST, 1]" ),
115
118
("{:ref:`SomeEnum.FIRST`, 2}" , "Literal[SomeEnum_FIRST, 2]" ),
116
119
("{: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
+ ),
117
131
],
118
132
)
119
133
def test_literals (self , doctype , expected ):
@@ -188,6 +202,13 @@ def escape(name: str) -> str:
188
202
assert annotation .value == expected
189
203
# fmt: on
190
204
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
+
191
212
def test_unknown_name (self ):
192
213
# Simple unknown name is aliased to typing.Any
193
214
transformer = DoctypeTransformer ()
0 commit comments