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

Fix set xor return types for abstract sets - #16127

Open
subotac wants to merge 4 commits into
python:mainfrom
subotac:fix-set-xor-abstract-set
Open

subotac wants to merge 4 commits into
python:mainfrom
subotac:fix-set-xor-abstract-set

Conversation

subotac commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #16115.

set.__xor__ and frozenset.__xor__ return NotImplemented for arbitrary collections.abc.Set implementations, allowing reflected dispatch to determine the result type. Preserve the concrete return type
for built-in set operands and return AbstractSet for the general case.

The new test covers both built-in left operands with an abstract set right operand.

This comment has been minimized.

Copy link
Copy Markdown

To be 100% correct the input type should be widened to Iterable. The default implementation of AbstractSet handles them

Comment thread stdlib/builtins.pyi Outdated
@overload
def __xor__(self, value: set[_S] | frozenset[_S], /) -> set[_T | _S]: ...
@overload
def __xor__(self, value: AbstractSet[_S], /) -> AbstractSet[_T | _S]: ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This seems incorrect, set.__xor__ doesn't return this. It only accepts set and frozenset. xor with AbstractSets instead works through an __rxor__ method on those other sets.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated the builtin signatures to accept only set/frozenset and added AbstractSet.rxor for reflected dispatch; the regression test checks both paths. Could you take another look?

This comment has been minimized.

subotac requested a review from JelleZijlstra October 6, 2026 21:11

subotac commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

The local conflict resolution preserves the newer reflected overloads and restores reflected XOR support for AbstractSet The focused typing checks pass. The update has not been pushed yet

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

This branch has not been deployed

No deployments
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

frozenset.__xor__ signature is wrong

3 participants


Back | FazBrowse Home | New Git URL