[Python-Dev] Python3 C extension how to support dir()

Barry Scott barry at barrys-emacs.org
Sun Apr 23 16:53:00 EDT 2017

I first ask this on python users. But I think the only people that can answer are the core developers.

I have a python3 C++ extension that works written using the PyCXX C++ interface.

But dir(obj) does not return the list of member variables.

With the python2 version supporting the __members__ variable was all that was needed.
But __members__ been removed from python3.

How should I support dir() from the C API?

I cannot use tp_members, not appropiate to the code I'm writing.
If I provide __dir__ I then hit the problem I need the C API version of:

	all_attr = super( mytype, obj ).__dir__();
	all_attr.extend( mytype_variable_names );
	return all_attr

I'm not getting inspiration from the python 3.6 sources for this problem.

I did find the object_dir function in typeobject.c, but that has not helped
get me move forward.

What is the the patten that I should implement?


More information about the Python-Dev mailing list