Allow reflected fallback for in-place set operators (#9182)

Assisted-by: Codex:gpt-6
This commit is contained in:
1ndahous3 authored and GitHub committed 2026-10-18 23:00:18 +09:00
1 parent e411f91721
commit e7e3dfd6ce
2 files changed
+28 -4

No files matched your search

+16
View File
@@ -1,3 +1,5 @@
import operator
from testutils import assert_raises
assert set([1, 2]) == set([1, 2])
@@ -706,3 +708,17 @@ for use_operator in (False, True):
intersection_target.intersection_update({1})
assert not intersection_target
assert intersection_events == [True, True]
# Unsupported right operands must reach their reflected set operation.
keys = {2: None, 3: None}.keys()
for method, operation, expected in (
(set.__ior__, operator.ior, {1, 2, 3}),
(set.__iand__, operator.iand, {2}),
(set.__isub__, operator.isub, {1}),
(set.__ixor__, operator.ixor, {1, 3}),
):
source = {1, 2}
assert method(source, keys) is NotImplemented
assert operation(source, keys) == expected
assert source == {1, 2}