Skip to content
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

Expose binary operations (*, &, etc.) #3709

Closed
alex opened this issue Dec 29, 2023 · 1 comment · Fixed by #3712
Closed

Expose binary operations (*, &, etc.) #3709

alex opened this issue Dec 29, 2023 · 1 comment · Fixed by #3712

Comments

@alex
Copy link
Contributor

alex commented Dec 29, 2023

These are available in the CPython API via PyNumber_And, PyNumber_Multiply, etc.

I'm happy to send PRs for these. Though a) it probably makes sense to do this after #3684, b) is there a better way to do this than dozens of new methods on PyAny? (https://docs.python.org/3/c-api/number.html)

@davidhewitt
Copy link
Member

davidhewitt commented Dec 29, 2023

I would support having these, I've needed a couple of them in the past but just used the raw ffi instead of getting around to figuring out how to expose them properly 🙈

I think #3684 probably isn't blocking you. Maybe even just add the new methods only to the PyAnyMethods trait? It might be a nice carrot for users to upgrade 😃

I haven't thought of a better way than to add methods for each operator.

The usual problem with rust operators and traits is that we cannot express fallibility. I suppose for some of these we might be able to control the return value, does it make sense for + to return PyResult<Bound<PyAny>>? I think ((a + b)? + c)? is somewhat clunky to write, a.add(b)?.add(c)? might be clearer anyway?

alex added a commit to alex/pyo3 that referenced this issue Dec 29, 2023
alex added a commit to alex/pyo3 that referenced this issue Dec 29, 2023
alex added a commit to alex/pyo3 that referenced this issue Dec 29, 2023
alex added a commit to alex/pyo3 that referenced this issue Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants