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

Bad error message when using incorrect signature for some dunder methods #4507

Open
Walter-Reactor opened this issue Aug 31, 2024 · 0 comments
Labels

Comments

@Walter-Reactor
Copy link

Walter-Reactor commented Aug 31, 2024

Bug Description

When implementing __iadd__, I assumed that I'd need to return a reference to self since that's generally the behavior expected in python. Following that logic, I wrote it with the signature:

fn __iadd__<'a>(self_: PyRefMut<'a, Self>, other: &Self) -> PyRefMut<'a, Self>.

This lead to a compiler error message about PyRefMut not implementing the correct conversion trait, which lead me down a bit of a rabbit hole until I found the correct section in the readme.

Ideally a dunder method with an incorrect signature could be detected, and the error message note the expected signature or just point users to the relevant section of the readme.

Steps to Reproduce

Define a pyclass with
fn __iadd__<'a>(self_: PyRefMut<'a, Self>, other: &Self) -> PyRefMut<'a, Self>{...} in the impl block, observe the error message

Backtrace

No response

Your operating system and version

Windows 11

Your Python version (python --version)

Python 3.12.4

Your Rust version (rustc --version)

rustc 1.80.1 (3f5fd8dd4 2024-08-06)

Your PyO3 version

0.22.1

How did you install python? Did you use a virtualenv?

Basic installer for python, UV 0.3 used for virtualenv

Additional Info

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant