-
Notifications
You must be signed in to change notification settings - Fork 763
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
Make __r*__ methods work with operators #839
Conversation
tests/test_arithmetics.rs
Outdated
Ok(format!("{:?} | RA", other)) | ||
} | ||
|
||
fn __rpow__(&self, other: &PyAny, _module: &PyAny) -> PyResult<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn __rpow__(&self, other: &PyAny, _module: &PyAny) -> PyResult<String> { | |
fn __rpow__(&self, other: &PyAny, _mod: &PyAny) -> PyResult<String> { |
tests/test_arithmetics.rs
Outdated
let py = gil.python(); | ||
|
||
let c = PyCell::new(py, LhsAndRhsArithmetic {}).unwrap(); | ||
py_run!(py, c, "assert c.__radd__(1) == '1 + BA'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if I understand this test, it means that it's never possible to call fn __radd__
?
(fn __radd__
has RA
in output, this has BA
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this can be a bug.
I'll check it tommorow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by using METH_COEXIST
👍 nicely figured out! Looks like |
It looks like we can't use COEXIST for |
I'm not sure that's true... isn't the issue that e.g. the supported forms should be
According to the note here, |
👍 |
Sign, coexist + round cause segfault that I can't reproduce in my local machine... 🤢 |
😢 I'll try later on mine and let you know if I have any luck! |
@davidhewitt |
Ok. I guess also there is no need for |
Actions CI failure this time was the usual datetime fail, I'm rerunning jobs... |
@davidhewitt |
Resolves #838.
This PR uses
__radd__
methods as reversed fallback methods for__add__
or so.This is the same as what cpython does and I'm sure it's a correct strategy, but, apparently, this implementation is dirty and has lots of templates 🙄
Need to simplify in the future.