Re-exporting pyo3 breaks macros #1978
-
I've been using a wrapper crate to sync versions of pyo3, pyo3-log and pyo3-asyncio between different lib and binary crates I'm developing. However, some of the code in macros appears to rely on pyo3 being available in the global scope (example: 21196e6). This is not the case for me, as pyo3 comes as a dependency for the wrapper crate. Could you elaborate on why that choice was made? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
That (series of) commit(s) made it so that pyo3 doesn't rely on the things in the user's scope. Can you clarify what you mean? Or are you talking about macros in pyo3-log/pyo3-asyncio? If so you should file an issue there, because IMO a macro being unhygienic is a bug. |
Beta Was this translation helpful? Give feedback.
-
I guess the problem is that if However, previously |
Beta Was this translation helpful? Give feedback.
-
I think this is one of those things where it hurts both ways around. As the other answers say, we felt it was better to anchor the macros to the global scope rather than relying on OTOH, I can certainly appreciate your use case wanting to write |
Beta Was this translation helpful? Give feedback.
-
Maybe serde's approach is where we should aim at: https://serde.rs/container-attrs.html#crate Basically, allowing |
Beta Was this translation helpful? Give feedback.
I think this is one of those things where it hurts both ways around.
As the other answers say, we felt it was better to anchor the macros to the global scope rather than relying on
pyo3
being defined correctly at in the current scope. This leads to fewer suprises where PyO3 (or std) can be overridden in the local scope with unexpected effects.OTOH, I can certainly appreciate your use case wanting to write
use my_crate::pyo3
to override what the macros look at. I think a number of proc macro crates are in similar positions where it's not clear what's better on this front. I'm happy with what we currently do because it's more robust, however am not against reconsidering.