Skip to content

Commit bb6d93c

Browse files
committed
Test arguments that use "optional" but have no default
1 parent b547449 commit bb6d93c

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tests/test_stubs.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,28 @@ def foo(a: int | None=..., b: int=...) -> None: ...
149149
result = transformer.python_to_stub(source)
150150
assert expected == result
151151

152+
def test_optional_without_default(self):
153+
source = dedent(
154+
'''
155+
def foo(a):
156+
"""
157+
Parameters
158+
----------
159+
a : int, optional
160+
"""
161+
'''
162+
)
163+
expected = dedent(
164+
"""
165+
def foo(a: int) -> None: ...
166+
"""
167+
)
168+
169+
transformer = Py2StubTransformer()
170+
# TODO should warn about a required arg being marked "optional"
171+
result = transformer.python_to_stub(source)
172+
assert expected == result
173+
152174
# fmt: off
153175
@pytest.mark.parametrize(
154176
("assign", "expected"),
@@ -376,7 +398,7 @@ class Foo:
376398
b: str = ""
377399
# docstub: on
378400
c: int = None
379-
b: str = ""
401+
d: str = ""
380402
"""
381403
)
382404
expected = dedent(
@@ -387,7 +409,7 @@ class Foo:
387409
b: str = ""
388410
389411
c: int
390-
b: str
412+
d: str
391413
"""
392414
)
393415
transformer = Py2StubTransformer()

0 commit comments

Comments
 (0)