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

Add error messages when compiling for ABI3 with unsupported macro features #3945

Open
davidhewitt opened this issue Mar 10, 2024 · 5 comments

Comments

@davidhewitt
Copy link
Member

davidhewitt commented Mar 10, 2024

Building from #3835 (comment) and https://pyo3.rs/v0.20.3/building_and_distribution#missing-features

We have some #[pyclass] options which do not work on older ABI3 versions:

  • #[pyo3(text_signature = "...")] does not work on classes until Python 3.10 or greater.
  • #[pyclass(dict)] and #[pyclass(weakref)] options on classes are not supported until Python 3.9 or greater.

At the moment I think these conditions fail silently (they compile but the runtime behaviour is missing). The proc macros should instead detect these cases and emit a helpful warning.

@cojmeister
Copy link

Hi!
I can do this! But I'll need some guidance! Where should I start?

@davidhewitt
Copy link
Member Author

Thanks for volunteering! To focus on #[pyclass(weakref)] as an initial example, try looking in pyo3-macros-backend/src/pyclass.rs for the part of the proc-macro code which handles the weakref option. pyo3-macros-backend/src/utils.rs has a method for checking if it's an ABI3 build, so you can use that method (and other information from pyo3_build_config) to work out if weakref has been set for an unsupported build.

Once that's figured out, look for e.g. the bail_spanned! / ensure_spanned! macros which is how most of PyO3's macro code emits errors.

@davidhewitt
Copy link
Member Author

Once the error has been implemented, it would be worth adding a test for this as part of test_compile_error.

@cojmeister
Copy link

Hey @davidhewitt, I've opened PR #3993
Can you let me know if I'm going on the right direction?
Thanks!

@codeguru42
Copy link

I created a follow up PR #4194 that superceded #3993. This doesn't include any error message for text_signature which may no longer be necessary or can be a separate PR.

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

No branches or pull requests

3 participants