Skip to content

Commit 89e6130

Browse files
committed
Remove unsafe overlap in overload example.
1 parent fbb847e commit 89e6130

3 files changed

Lines changed: 5 additions & 6 deletions

File tree

conformance/results/pyright/overloads_evaluation.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ overloads_evaluation.py:116:17 - error: Argument of type "int | str" cannot be a
2323
  Type "int | str" is not assignable to type "int"
2424
    "str" is not assignable to "int" (reportArgumentType)
2525
overloads_evaluation.py:284:17 - error: "assert_type" mismatch: expected "Any" but received "list[int]" (reportAssertTypeFailure)
26-
overloads_evaluation.py:354:5 - error: Overload 1 for "example8" overlaps overload 2 and returns an incompatible type (reportOverlappingOverload)
2726
overloads_evaluation.py:398:17 - error: "assert_type" mismatch: expected "A[Any]" but received "A[None]" (reportAssertTypeFailure)
2827
"""

conformance/tests/overloads_evaluation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,15 @@ def check_example7(v1: list[Any], v2: Any) -> None:
351351

352352

353353
@overload
354-
def example8(x: str, y: Literal['o1']) -> str: ... # E? some type checkers report unsafe overlap between example8's overloads
354+
def example8(x: str, y: Literal['o1']) -> bool: ...
355355

356356

357357
@overload
358358
def example8(x: str, y: str) -> int: ...
359359

360360

361-
def example8(x: str, y: str) -> str | int:
362-
return x if y == 'o1' else 0
361+
def example8(x: str, y: str) -> bool | int:
362+
return True
363363

364364

365365
def check_example8(x: Any):
@@ -368,7 +368,7 @@ def check_example8(x: Any):
368368
# `Literal['o1']` match the first overload, so the second overload can be
369369
# eliminated.
370370
ret = example8(x, 'o1')
371-
assert_type(ret, str)
371+
assert_type(ret, bool)
372372

373373

374374
class A[T]:

docs/spec/overload.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Consider the following examples::
295295
and::
296296

297297
@overload
298-
def example2(x: str, y: Literal['o1']) -> str: ...
298+
def example2(x: str, y: Literal['o1']) -> bool: ...
299299
@overload
300300
def example2(x: str, y: str) -> int: ...
301301

0 commit comments

Comments
 (0)