-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
The following example is type-safe, but mypy reports 6 false positives:
- pyright playground: no errors
- pyrefly sandbox: no errors
- mypy playground: 6 false positives
- ty playground: 2 false positives (#2314)
def upcast(arg: int) -> int:
return arg
def test[X: int](items: list[X]) -> list[X]:
_a: list[int] = list(items) # ✅️
_b: list[int] = [*items] # ✅️
_c: list[int] = [x for x in items] # ✅️
_1: list[str] | list[int] = list(items) # ❌️
_2: list[int] | list[str] = list(items) # ❌️
_3: list[str] | list[int] = [*items] # ❌️
_4: list[int] | list[str] = [*items] # ❌️
_5: list[str] | list[int] = [x for x in items] # ❌️
_6: list[int] | list[str] = [x for x in items] # ❌️
_7: list[str] | list[int] = [upcast(x) for x in items] # ✅️
_8: list[int] | list[str] = [upcast(x) for x in items] # ✅️
return itemscontext: #20419 (comment)
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong