-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Inplace dunders can return NotImplemented, and that's not documented #104219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
docs
Documentation in the Doc dir
Comments
For ye of little faith : class A:
def __init__(self, val):
self.val = val
def __str__(self):
return f"A<{self.val}>"
def __add__(self, other):
print("add", self, other)
return NotImplemented
def __iadd__(self, other):
print("iadd", self, other)
return NotImplemented
class B:
def __init__(self, val):
self.val = val
def __str__(self):
return f"B<{self.val}>"
def __radd__(self, other):
print("radd", self, other)
return NotImplemented
|
erlend-aasland
pushed a commit
that referenced
this issue
Mar 1, 2024
Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Mar 1, 2024
…thonGH-104220) (cherry picked from commit 2713c2a) Co-authored-by: Gouvernathor <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Mar 1, 2024
…thonGH-104220) (cherry picked from commit 2713c2a) Co-authored-by: Gouvernathor <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
This was referenced Mar 1, 2024
erlend-aasland
pushed a commit
that referenced
this issue
Mar 1, 2024
…H-104220) (#116210) (cherry picked from commit 2713c2a) Co-authored-by: Gouvernathor <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
erlend-aasland
pushed a commit
that referenced
this issue
Mar 1, 2024
…H-104220) (#116211) (cherry picked from commit 2713c2a) Co-authored-by: Gouvernathor <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
woodruffw
pushed a commit
to woodruffw-forks/cpython
that referenced
this issue
Mar 4, 2024
…thon#104220) Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
adorilson
pushed a commit
to adorilson/cpython
that referenced
this issue
Mar 25, 2024
…thon#104220) Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
…thon#104220) Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See this discussion.
Normal NotImplemented situation :
A() + B()
is resolved inA.__add__(A(), B())
which if returning NotImplemented, falls back toB.__radd__(B(), A())
.Now this behavior means there can be a double fallback : in
a += b
, ifA.__iadd__
exists but returns NotImplemented, it will first fall back toA.__add__
and then toB.__radd__
.This is a great feature, but it's not currently documented.
Linked PRs
The text was updated successfully, but these errors were encountered: