Skip to content

pybind: Remove in-place mutation operators from hashable types#629

Merged
jmr merged 2 commits into
google:masterfrom
deustis:deustis/remove_inplace_operators
May 22, 2026
Merged

pybind: Remove in-place mutation operators from hashable types#629
jmr merged 2 commits into
google:masterfrom
deustis:deustis/remove_inplace_operators

Conversation

@deustis
Copy link
Copy Markdown
Contributor

@deustis deustis commented May 22, 2026

In-place arithmetic operators (__iadd__, __isub__, __imul__, __itruediv__) mutate the object in place. If the object is used as a dictionary key or set member, mutation corrupts the hash table entry.

Removes these operators from S1Angle, R2Point, and S2Point. Augmented assignment (+=, -=, *=, /=) still works: Python falls back to the binary operator and rebinds the variable, so a += b is equivalent to a = a + b.

Tests renamed to test_add_assign / test_sub_assign / test_mul_assign / test_div_assign to reflect the fallback semantics.

deustis added 2 commits May 22, 2026 15:46
In-place operators (__iadd__, __isub__, __imul__, __itruediv__) mutate
the object, which corrupts dict/set entries if the object is used as a
key. Without them, +=, -=, *=, /= fall back to the non-mutating
binary operators + rebinding, so the syntax still works.

Affects S1Angle, R2Point, and S2Point. Rename the corresponding tests
to test_add_assign / test_sub_assign / test_mul_assign / test_div_assign
to reflect the fallback semantics.
@jmr jmr merged commit 364a288 into google:master May 22, 2026
24 checks passed
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.

2 participants