Releases: ionite34/einspect
v0.5.16
v0.5.15
Fixes
- Fix
PyTypeObject.setattr_safe
not 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
object
PyMethods allocations 0857b06 - Convert all remaining structures to use the
Struct
inheritance mode instead of the@struct
decorator, this allows them to have the dynamic casting rules applied a93c5ac
Tooling
- Added
tools
subpackage 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.Ready
pythonapi method
Enhancements
- Improved stability for
impl
andTypeView
setitem with new PyMethods struct allocation mode. This now recursively allocates for subtypes and supports allocating to theobject
type
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.address
property that returns the memory address of an object, likePyObject.address
TypeView.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)
# 38685626227668133590597632
Enhancements:
- Added
Struct
base metaclass form of@struct
decorator, simplify internal usages inPyObject
and other structures.
Fixes:
- Skip weakref check when detach=False
Full Changelog: v0.5.10...v0.5.11
v0.5.10
Added
@impl
now 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
-
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
v0.5.8
Enhancements
- Move
_pyobject
type hint eval to define time in__init_subclass__
- Improves internal reliability and performance by moving
get_type_hints
call 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())
# abcabc
Full Changelog: v0.5.6...v0.5.7