Unsure if bug: static_property_type
needs dynamic heap?
#4981
makslevental
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Note, I'm on 2.10.4 on CPython 3.11.4.
Recently I tried to do this
Roughly, this is adding a static property to a pure python class, where the getter is implemented in C++. Ignoring why one might want to do this1, I was met with a curious error:
Digging into the implementation of
make_static_property_type
, I found a pretty relevant/useful comment:As a kind of "by hook or by crook" approach, I moved the
enable_dynamic_attributes
out of the#if
and theAttributeError
was resolved. Great! But the confusing thing is I'm not testing/using 3.122 and thus the comment suggests/implies that__doc__
doesn't need to be writeable? I tried searching around for when/where the requirement (for dynamic attributes of property-derived types in CPython) would be required but couldn't find much (but I'm not a CPython contributor so I don't really know where to look for that kind of info, other than release notes). I also couldn't quite figure out how toMy intuition is that I'm doing something wrong because conventional users of pybind and
def_property_readonly_static
aren't seeing this error (I assume...).Any advice would be appreciated.
P.S.
On writing this up and going back to double check some things I've found there's some history/context here:
doc
argument ofproperty.__init__
in subclasses python/cpython#23205 and correspondingly added that very comment/#if
inmake_static_property_type
property
assumes that its subclasses have __dict__ python/cpython#98963.Still digesting but posting anyway for posterity/reference.
cc @martin-luecke
Footnotes
It's our way of enabling downstream users to sign up for an object hierarchy in C++ and have that reflected in python... ↩
And if I were well then the
#if
would catch and__doc__
would be writeable. ↩Beta Was this translation helpful? Give feedback.
All reactions