Skip to content

Commit 19e9f21

Browse files
authored
stubtest: allow ellipsis as default argument (#12838)
Resolves #12819
1 parent 9d63fa5 commit 19e9f21

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

mypy/stubtest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ def _verify_arg_default_value(
419419
and stub_type is not None
420420
# Avoid false positives for marker objects
421421
and type(runtime_arg.default) != object
422+
# And ellipsis
423+
and runtime_arg.default is not ...
422424
and not is_subtype_helper(runtime_type, stub_type)
423425
):
424426
yield (

mypy/test/teststubtest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __getitem__(self, typeargs: Any) -> object: ...
4343
4444
Callable: _SpecialForm = ...
4545
Generic: _SpecialForm = ...
46+
Protocol: _SpecialForm = ...
4647
4748
class TypeVar:
4849
def __init__(self, name, covariant: bool = ..., contravariant: bool = ...) -> None: ...
@@ -1020,6 +1021,27 @@ class _Options(TypedDict):
10201021
error="opt3",
10211022
)
10221023

1024+
@collect_cases
1025+
def test_protocol(self) -> Iterator[Case]:
1026+
if sys.version_info < (3, 7):
1027+
return
1028+
yield Case(
1029+
stub="""
1030+
from typing_extensions import Protocol
1031+
1032+
class X(Protocol):
1033+
def foo(self, x: int, y: bytes = ...) -> str: ...
1034+
""",
1035+
runtime="""
1036+
from typing_extensions import Protocol
1037+
1038+
class X(Protocol):
1039+
def foo(self, x: int, y: bytes = ...) -> str: ...
1040+
""",
1041+
# TODO: this should not be an error, #12820
1042+
error="X.__init__"
1043+
)
1044+
10231045

10241046
def remove_color_code(s: str) -> str:
10251047
return re.sub("\\x1b.*?m", "", s) # this works!

0 commit comments

Comments
 (0)