Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions stdlib/@tests/test_cases/builtins/check_set.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Set as AbstractSet
from typing_extensions import Literal, assert_type


Expand Down Expand Up @@ -55,3 +56,14 @@ def test_frozenset_interface(s: frozenset[Literal["foo", "bar"]], y: frozenset[s
assert_type(s & y, frozenset[Literal["foo", "bar"]])
assert_type(s | y, frozenset[str])
assert_type(s ^ y, frozenset[str])


def test_xor_with_abstract_set(
s: set[Literal["foo", "bar"]], frozen: frozenset[Literal["foo", "bar"]], other: AbstractSet[str]
) -> None:
s.__xor__(other) # type: ignore
frozen.__xor__(other) # type: ignore
assert_type(other.__rxor__(s), AbstractSet[str])
assert_type(other.__rxor__(frozen), AbstractSet[str])
assert_type(s ^ other, AbstractSet[str])
assert_type(frozen ^ other, AbstractSet[str])
6 changes: 4 additions & 2 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,8 @@ class set(MutableSet[_T]):
def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
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 __xor__(self, value: set[_S] | frozenset[_S], /) -> set[_T | _S]: ... # type: ignore[override]
def __rxor__(self, value: set[_S] | frozenset[_S], /) -> set[_T | _S]: ... # type: ignore[override,misc]
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
def __le__(self, value: AbstractSet[object], /) -> bool: ...
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
Expand Down Expand Up @@ -1491,7 +1492,8 @@ class frozenset(AbstractSet[_T_co]):
def __and__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
def __sub__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
def __xor__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
def __xor__(self, value: set[_S] | frozenset[_S], /) -> frozenset[_T_co | _S]: ... # type: ignore[override]
def __rxor__(self, value: set[_S] | frozenset[_S], /) -> frozenset[_T_co | _S]: ... # type: ignore[override,misc]
def __le__(self, value: AbstractSet[object], /) -> bool: ...
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
def __ge__(self, value: AbstractSet[object], /) -> bool: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ class AbstractSet(Collection[_T_co]):
def __or__(self, other: AbstractSet[_T], /) -> AbstractSet[_T_co | _T]: ...
def __sub__(self, other: AbstractSet[Any], /) -> AbstractSet[_T_co]: ...
def __xor__(self, other: AbstractSet[_T], /) -> AbstractSet[_T_co | _T]: ...
def __rxor__(self, other: AbstractSet[_T], /) -> AbstractSet[_T_co | _T]: ...
def __eq__(self, other: object, /) -> bool: ...
def isdisjoint(self, other: Iterable[Any], /) -> bool: ...

Expand Down