Issue #81 resolved

Exported variables are not listed in `dir(lib)`

Amaury Forgeot d'Arc
created an issue

After lib = ffi.verify(...), dir(lib) shows the functions, but not variables. They are stored as properties on the library class.

This is because FFILibrary subclasses ModuleType, which has a special __dir__. FFILibrary should have its own dir to also list properties.

Comments (3)

  1. Amaury Forgeot d'Arc reporter

    A possible fix:

    diff -r c28026358db5 cffi/vengine_gen.py
    --- a/cffi/vengine_gen.py   Thu Mar 07 17:51:24 2013 +0100
    +++ b/cffi/vengine_gen.py   Sun May 05 17:48:26 2013 +0200
    @@ -64,6 +64,10 @@
             class FFILibrary(types.ModuleType):
                 _cffi_generic_module = module
                 _cffi_ffi = self.ffi
    +            def __dir__(self):
    +                # An approximation of the default dir() implementation.
    +                return sorted(list(self.__dict__) +
    +                              list(type(self).__dict__))
             library = FFILibrary("")
             #
             # finally, call the loaded_gen_xxx() functions.  This will set
    
  2. Log in to comment