I wonder how can I define a static class variable from C++ for Python? The equivalent Python code would be like:
class foo:
bar = int
I tried to use tp_getset field when defining the type, but it turns out it doesn't work and returns a getset_descriptor
in Python, and it doesn't work when called on instances (AttributeError). Furthermore, Python doc says directly manipulating tp_dict
with C API is unsafe. But it doesn't tell what to use instead. (see here)
I deliberately chose int
in the example since I'm referencing some other class in it, if that matters.