Releases: ionite34/einspect
v0.5.16
v0.5.15
Fixes
- Fix
PyTypeObject.setattr_safenot setting non-override slot attributes
Tools
- Add struct source comparisons to tools sub-package
Full Changelog: v0.5.13...v0.5.15
v0.5.13
Fixes
- Improved stability of
objectPyMethods allocations 0857b06 - Convert all remaining structures to use the
Structinheritance mode instead of the@structdecorator, this allows them to have the dynamic casting rules applied a93c5ac
Tooling
- Added
toolssubpackage for verifying compatibility with CPython source. This is not included in pypi user distributions.
Full Changelog: v0.5.12...v0.5.13
v0.5.12
Adds
PyTypeObject.Readypythonapi method
Enhancements
- Improved stability for
implandTypeViewsetitem with new PyMethods struct allocation mode. This now recursively allocates for subtypes and supports allocating to theobjecttype
Fixes
- Fix Struct
__setattr__cast for ctypes.PYFUNCTION types that would always cast to NULL
Full Changelog: v0.5.11...v0.5.12
v0.5.11
Added:
View.addressproperty that returns the memory address of an object, likePyObject.addressTypeView.restore()restores the previously set or deleted attribute on a type- Can be called with one or more attribute names
view(int).restore("__add__", "__mul__")to restore those attributes - Or can be called with no arguments to restore all implemented attributes
view(int).restore()
- Can be called with one or more attribute names
TypeView.__delitem__type view subscripting now supports deletion
from einspect import view
del view(int)["__pow__"]
print(2 ** 85)
# TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'int'
view(int).restore("__pow__")
print(2 ** 85)
# 38685626227668133590597632Enhancements:
- Added
Structbase metaclass form of@structdecorator, simplify internal usages inPyObjectand other structures.
Fixes:
- Skip weakref check when detach=False
Full Changelog: v0.5.10...v0.5.11
v0.5.10
Added
@implnow has optional bool keyword argumentdetach. If True, this will create a weak-reference finalizer for the method being implemented, and detach the method from the type when the method is garbage collected. If an original attribute exists, it will be restored during finalization, otherwise the attribute is deleted.- This can be useful in cases where methods are not safe to be kept through interpreter shutdown, like
int.__hash__
from einspect import impl, orig
@impl(int, detach=True)
def __hash__(self):
print("in hash", self)
return orig(int).__hash__(self)Full Changelog: v0.5.9...v0.5.10
v0.5.9
Added
-
implnow has an optional keyword argumentalloc, with options of"all", "sequence", "mapping". The default ofNonewill automatically allocatePyMethodswhen 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 bothPySequenceMethodsandPyMappingMethods.
- The setting
-
orignow works within__new__impls.orig(cls)will return a custom slot wrapper totp_newthat 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
v0.5.8
Enhancements
- Move
_pyobjecttype hint eval to define time in__init_subclass__
- Improves internal reliability and performance by moving
get_type_hintscall to define time, avoids issues in runtime after internal types are modified.
Full Changelog: v0.5.7...v0.5.8
v0.5.7.post1
Docs
- Add orig and extending types documentation
This update only affects sphinx docs and
README.md
Full Changelog: v0.5.7...v0.5.7.post1
v0.5.7
Added
- Supports supplying multiple string attributes in
TypeView.__setattr__to set all given names to the same value
from einspect import view
view(str)["foo", "bar"] = lambda x: x * 2
print("abc".foo())
# abcabc
print("abc".bar())
# abcabcFull Changelog: v0.5.6...v0.5.7