I would like to get the full listing of enums from the header file using cffi. But I see a strange behaviour: by observing the object, I'm forcing the change in the underlying __dict__
:
>>> from cffi import FFI
>>> ffi = FFI()
>>> ffi.cdef('typedef enum {RANDOM, IMMEDIATE, SEARCH} strategy;')
>>> c = ffi.dlopen('c')
# the dictionary is empty
>>> print c.__dict__
{}
>>> dir(c)
# the dictionary is populated
>>> print c.__dict__
{'SEARCH': 2, 'RANDOM': 0, 'IMMEDIATE': 1}
I'm guessing that __dict__
is not populated until first getattr()
on the class is called, but the real question is: what does dir()
do that populates __dict__
? Calling hasattr()
seems to do the same thing.