Remove errors when type annotations used without experimental-inspect#5999
Remove errors when type annotations used without experimental-inspect#5999tbates-redarc wants to merge 1 commit intoPyO3:mainfrom
experimental-inspect#5999Conversation
Tpt
left a comment
There was a problem hiding this comment.
Thank you for this. It makes sense to me.
@davidhewitt no objection on this?
May you add a changelog in newsfragments/5999.changed.md file?
Merging this PR will not alter performance
Comparing Footnotes
|
davidhewitt
left a comment
There was a problem hiding this comment.
Agreed this seems like the right approach, presumably once we remove the experimental-inspect feature gate we'll be in this state anyway.
I have been thinking in the background about what we do regarding the stub fragments in the final binary. I wonder if there's a way we can get pyo3-introspection to have a way to strip them out, so two builds of the extension are not needed?
Definitely, we can do something like calling a well configured |
9fa312f to
60a9e42
Compare
I want to be able to build with the
experimental-inspectfeature enabled for generating type stubs, but without it for the release build of my extension. It reduces the extension DLL from 7MB to 6MB, and since I ship the generated type stubs anyway, there's no need to include this extra data in the binary.However, trying to include type information in the
#[pyo3(signature = ...)]annotations gives errors when building withoutexperimental-inspect. Trying to conditionally compile the type information seems to be impossible, because pyo3's macros don't appear to see annotations inside#[cfg_attr(feature = "experimental-inspect", pyo3(signature = ...))]("error: cannot find attributepyo3in this scope") and do appear to see them even when protected by#[cfg(feature = "experimental-inspect")].Rather than try to fix the macros, which would still require me to have two copies of the signature (with and without type annotations), I thought it might be reasonable to just remove the errors, since having the extra type information there does no harm, it is still parsed by the macros and then ignored if the feature is disabled.