FunctionView#

class einspect.views.view_function.FunctionView(obj, ref=False)#
drop()#

Drop all references to the base object.

Return type:

None

Notes

This is useful for when you want to drop the reference to the base object, but still want to access the view.

gc_is_tracked()#

Returns True if the object is tracked by the GC.

Return type:

bool

gc_may_be_tracked()#

Return True if the object may be tracked by the GC in the future, or already is.

Return type:

bool

info(types=True, arr_max=64)#

Return a formatted info string of the view struct.

Parameters:
  • types (bool) – If True, include types as annotations.

  • arr_max (Optional[int]) – Maximum length of Array elements to display.

Return type:

str

Returns:

A formatted info string of the view struct.

is_gc()#

Returns True if the object implements the Garbage Collector protocol.

If True, a PyGC_HEAD struct will precede the object struct in memory.

Return type:

bool

move_from(other)#

Moves data at other Viewable to this View.

move_to(dst, start=8)#

Copy the object to another view’s location.

Parameters:
  • dst (View) – The destination view.

  • start (int) – The start offset in bytes to copy from. The default is pointer size to skip ob_refcnt

Return type:

None

swap(other)#

Swaps data at other Viewable with this View.

unsafe()#

Context manager to enter an unsafe context.

Return type:

ContextManager[Self]

Examples

>>> from einspect import view
>>> v = view(100)
>>> with v.unsafe():
>>>     v.size += 1
>>> with view(100).unsafe() as v:
>>>     v.size -= 1
property address: int#

Memory address of the object.

property base: _T#

Returns the base object of the view.

Requires either the View to be created with (ref=True) or the object to support weakrefs.

Notes

If neither ref nor weakref are available, and called within an unsafe context, returns an object via memory address cast. The result of the cast is undefined behavior, and could cause a segmentation fault.

Returns:

The base object of the view.

Raises:
  • AttributeError – If ref=False and base does not support weakrefs.

  • MovedError – If weak-ref of base is garbage collected.

property instance_dict: dict[str, Any] | None#

Instance Dictionary of the object.

property mem_allocated: int#

Memory allocated for the object in bytes.

property mem_size: int#

Memory size of the object in bytes.

property ref_count: int#

Reference count of the object.

property type: Type[_T]#

Type of the object.