pyo3
pyo3 copied to clipboard
Add error messages when compiling for ABI3 with unsupported macro features
Building from https://github.com/PyO3/pyo3/pull/3835#issuecomment-1986917915 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.
Hi! I can do this! But I'll need some guidance! Where should I start?
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.
Once the error has been implemented, it would be worth adding a test for this as part of test_compile_error
.
Hey @davidhewitt, I've opened PR #3993 Can you let me know if I'm going on the right direction? Thanks!
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.
@davidhewitt I think this is closed now, right?
Yes, many thanks again!