TupleView#
- class einspect.views.view_tuple.TupleView(obj, ref=True)#
- append(value)#
S.append(value) – append value to the end of the sequence
- clear() None -- remove all items from S #
- count(value) integer -- return number of occurrences of value #
- drop()#
Drop all references to the base object.
- Return type:
Notes
This is useful for when you want to drop the reference to the base object, but still want to access the view.
- extend(values)#
S.extend(iterable) – extend sequence by appending elements from the iterable
- gc_may_be_tracked()#
Return True if the object may be tracked by the GC in the future, or already is.
- Return type:
- index(value[, start[, stop]]) integer -- return first index of value. #
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- info(types=True, arr_max=64)#
Return 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:
- move_from(other)#
Moves data at other Viewable to this View.
- move_to(dst, start=8)#
Copy the object to another view’s location.
- pop(index=None)#
Remove and return item at index (default last).
Raises IndexError if tuple is empty or index is out of range.
- Return type:
TypeVar
(_T
)
- remove(value)#
S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- reverse()#
S.reverse() – reverse IN PLACE
- sort(*, key=None, reverse=False)#
Sort the tuple in ascending order and return None.
The sort is in-place (i.e. the tuple itself is modified) and stable (i.e. the order of two equal elements is maintained).
If a key function is given, apply it once to each tuple item and sort them, ascending or descending, according to their function values.
The reverse flag can be set to sort in descending order.
- Return type:
- 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 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.