mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-09 06:46:18 +08:00
allow arbitrary types in set difference (#15160)
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
from typing_extensions import Literal, assert_type
|
||||
|
||||
|
||||
# Note: type checkers / linters are free to point out that the set difference
|
||||
# below is redundant. But typeshed should allow it, as its job is to describe
|
||||
# what is legal in Python, not what is sensible.
|
||||
# For instance, set[Literal] - set[str] should be legal.
|
||||
def test_set_difference(x: set[Literal["foo", "bar"]], y: set[str], z: set[int]) -> None:
|
||||
assert_type(x - y, set[Literal["foo", "bar"]])
|
||||
assert_type(y - x, set[str])
|
||||
assert_type(x - z, set[Literal["foo", "bar"]])
|
||||
assert_type(z - x, set[int])
|
||||
assert_type(y - z, set[str])
|
||||
assert_type(z - y, set[int])
|
||||
+2
-2
@@ -1282,7 +1282,7 @@ class set(MutableSet[_T]):
|
||||
def __iand__(self, value: AbstractSet[object], /) -> Self: ...
|
||||
def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
|
||||
def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
|
||||
def __sub__(self, value: AbstractSet[_T | None], /) -> set[_T]: ...
|
||||
def __sub__(self, value: AbstractSet[object], /) -> set[_T]: ...
|
||||
def __isub__(self, value: AbstractSet[object], /) -> Self: ...
|
||||
def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
|
||||
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
|
||||
@@ -1313,7 +1313,7 @@ class frozenset(AbstractSet[_T_co]):
|
||||
def __iter__(self) -> Iterator[_T_co]: ...
|
||||
def __and__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ...
|
||||
def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
|
||||
def __sub__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ...
|
||||
def __sub__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
|
||||
def __xor__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
|
||||
def __le__(self, value: AbstractSet[object], /) -> bool: ...
|
||||
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
|
||||
|
||||
Reference in New Issue
Block a user