Skip to content

v0.5.9

Compare
Choose a tag to compare
@ionite34 ionite34 released this 05 Feb 18:53
· 125 commits to main since this release
093dbc4

Added

  • impl now has an optional keyword argument alloc, with options of "all", "sequence", "mapping". The default of None will automatically allocate PyMethods when a slot name being set is not allocated on the type.

    • The setting "all" will unconditionally allocate all PyMethods (PyAsyncMethods, PyNumberMethods, PySequenceMethods, PyMappingMethods) before the impl.
    • "sequence" and "mapping" options will allocate the respective PyMethods when the slot name is ambiguious (such as __len__ and __getitem__, which are in both PySequenceMethods and PyMappingMethods.
  • orig now works within __new__ impls. orig(cls) will return a custom slot wrapper to tp_new that will resolve further subclasses without a custom __new__ as object.__new__ instead. This also handles the special case where object.__new__ has a different signature than CustomType.__new__

from einspect import impl, orig


@impl(object)
def __new__(cls, *args, **kwargs):
    print("in new:", cls, args, kwargs)
    return orig(cls).__new__(cls, *args, **kwargs)

class Foo:
    ...

print(object())
# in new: <class 'object'> () {}
# <object object at 0x000001EA9D2A4FE0>

print(Foo())
# in new: <class '__main__.Foo'> () {}
# <__main__.Foo object at 0x000001EA9D797DD0>

Full Changelog: v0.5.8...v0.5.9