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
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
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_attributesout of the#ifand theAttributeErrorwas 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_staticaren'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:
docargument ofproperty.__init__in subclasses python/cpython#23205 and correspondingly added that very comment/#ifinmake_static_property_typepropertyassumes 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
#ifwould catch and__doc__would be writeable. ↩Beta Was this translation helpful? Give feedback.
All reactions