Skip to content

Releases: ionite34/einspect

v0.5.16

03 Apr 06:48
c528fc3
Compare
Choose a tag to compare

Fixes

  • Fix TypeView.restore sentinel handling with no named args by @ionite34 in #85

Full Changelog: v0.5.15...v0.5.16

v0.5.15

20 Mar 19:40
55f3c63
Compare
Choose a tag to compare

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

17 Mar 18:45
8073dd4
Compare
Choose a tag to compare

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

20 Feb 02:20
bda745a
Compare
Choose a tag to compare

Adds

  • PyTypeObject.Ready pythonapi method

Enhancements

  • Improved stability for impl and TypeView setitem with new PyMethods struct allocation mode. This now recursively allocates for subtypes and supports allocating to the object 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

15 Feb 09:11
60cdf2e
Compare
Choose a tag to compare

Added:

  • View.address property that returns the memory address of an object, like PyObject.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()
  • 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 in PyObject and other structures.

Fixes:

  • Skip weakref check when detach=False

Full Changelog: v0.5.10...v0.5.11

v0.5.10

07 Feb 06:57
bf1cc3a
Compare
Choose a tag to compare

Added

  • @impl now has optional bool keyword argument detach. 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

05 Feb 18:53
093dbc4
Compare
Choose a tag to compare

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

v0.5.8

02 Feb 19:14
807b70c
Compare
Choose a tag to compare

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

02 Feb 18:33
31b50f6
Compare
Choose a tag to compare

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

02 Feb 03:15
932462e
Compare
Choose a tag to compare

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