cpyext: Inconsistencies in PyPy's handling of __name__, __qualname__, and __module__
Dear PyPy team (& @mattip),
this is issue 3/3 of remaining inconsistencies I found in the nanobind test suite. Many thanks for fixing all of the previous reports so quickly.
The following reproducer creates a dummy type (
func) with a
Py_tp_getset that overrides
__module__. Querying those properties on an instance reveals differences between CPython 3.9+ and PyPy 3.9.
Python driver: https://github.com/wjakob/pypy_issues/blob/master/issue_6.py
The ability to do this is important when implementing a custom function object in a binding tool. For example, nanobind creates a custom function type
nanobind.nb_func that is used to wrap C/C++ functions and expose them in Python.
In that case, we don't want the
__module__ property to return
__name__ to return
'nb_func'. Instead, those properties should fetch information from the specific function instance ("what's the name of the bound function, and in which module do those specific bindings live?")