FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix set xor return types for abstract sets by subotac · Pull Request #16127 · python/typeshed · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (1) .pyi  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
12 changes: 12 additions & 0 deletions stdlib/@tests/test_cases/builtins/check_set.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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])
8 changes: 4 additions & 4 deletions stdlib/builtins.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1483,10 +1483,10 @@ class set(MutableSet[_T]):
@overload
def __rsub__(self, value: frozenset[_S], /) -> frozenset[_S]: ...

def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
def __xor__(self, value: set[_S] | frozenset[_S], /) -> set[_T | _S]: ... # type: ignore[override]
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]

@overload
@overload # type: ignore[override]
def __rxor__(self, value: set[_S], /) -> set[_T | _S]: ...
@overload
def __rxor__(self, value: frozenset[_S], /) -> frozenset[_T | _S]: ...
Expand Down Expand Up @@ -1538,9 +1538,9 @@ class frozenset(AbstractSet[_T_co]):
@overload
def __rsub__(self, value: frozenset[_S], /) -> frozenset[_S]: ...

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]

@overload
@overload # type: ignore[override]
def __rxor__(self, value: set[_S], /) -> set[_T_co | _S]: ...
@overload
def __rxor__(self, value: frozenset[_S], /) -> frozenset[_T_co | _S]: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/typing.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,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
Loading

Back | FazBrowse Home | New Git URL