v0.5.9
Added
-
impl
now has an optional keyword argumentalloc
, with options of"all", "sequence", "mapping"
. The default ofNone
will automatically allocatePyMethods
when a slot name being set is not allocated on the type.- The setting
"all"
will unconditionally allocate allPyMethods
(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 bothPySequenceMethods
andPyMappingMethods
.
- The setting
-
orig
now works within__new__
impls.orig(cls)
will return a custom slot wrapper totp_new
that will resolve further subclasses without a custom__new__
asobject.__new__
instead. This also handles the special case whereobject.__new__
has a different signature thanCustomType.__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