pdkmaster._util

_util module with private helper functions

API Notes

  • This is an internal module and none of the functions or classes should be called or instantiated in user code. No backward compatibility is provided unless stated otherwise in specific autodoc.

pdkmaster._util.i2f_recursive(values: Any) Any[source]

Recursively convert int and bool elements of an iterable. Iterables will be converted to tuples

pdkmaster._util.is_iterable(it: Any) bool[source]

Check if a value is Iterable

pdkmaster._util.get_nth_of(it: Iterable[_elem_typevar_], *, n: int) _elem_typevar_[source]

Return nth element from an iterable.

Parameters:

n – element to return starting from 0. All values up to the element will have been consumed from the iterable.

Raises:

StopIteration – if iterable has less than n+1 elements

pdkmaster._util.get_first_of(it: Iterable[_elem_typevar_]) _elem_typevar_[source]

Get first element of an iterable

This function will consume the first element of the iterator

Raises:

StopIteration – if iterable is empty

pdkmaster._util.get_last_of(it: Iterable[_iter_typevar_]) _iter_typevar_[source]

Get last elemeent from an iterator.

The iterator will be exhausted after calling this function.

Raises:

StopIteration – if iterable is empty

pdkmaster._util.strip_literal(s: str) str[source]

Strip surrounding ‘”’ of a string.

Strip head and tail only if they are both ‘”’

class pdkmaster._util.IterableOverride(*args, **kwds)[source]

Bases: Iterable[_iter_typevar_], Generic[_iter_typevar_]

Mixin class to allow to override element with Iterable element with more specific element. This is for static typing support to have right element for an iterator whose elements are a subclass of parent’s element type.

Example

class Elem:
    pass

class ElemChild(Elem):
    pass

T = TypeVar("T")
class MyList(List[T], Generic[T]):
    pass

class ElemList(MyList[Elem]):
    pass

class ElemChildList(IterableOverride[ElemChild], ElemList):
    pass
_abc_impl = <_abc_data object>
class pdkmaster._util.IterTypeMixin(*args, **kwds)[source]

Bases: Iterable[_elem_typevar_], Generic[_elem_typevar_]

Internal collection support

TODO: Extended internal API documentation.

_abc_impl = <_abc_data object>
class pdkmaster._util.ExtendedList(iterable: Iterable[_elem_typevar_] = ())[source]

Bases: List[_elem_typevar_], IterTypeMixin[_elem_typevar_], Generic[_elem_typevar_]

An internal list class that allow only elements of certain type.

TODO: Extended internal API documentation.

append(_ExtendedList__object: _elem_typevar_) None[source]

Append object to the end of the list.

clear() None[source]

Remove all items from list.

extend(_ExtendedList__iterable: Iterable[_elem_typevar_]) None[source]

Extend list by appending elements from the iterable.

insert(_ExtendedList__index: int, _ExtendedList__object: _elem_typevar_) None[source]

Insert object before index.

pop(_ExtendedList__index: int = -1) _elem_typevar_[source]

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(_ExtendedList__value: _elem_typevar_) None[source]

Remove first occurrence of value.

Raises ValueError if the value is not present.

reverse() None[source]

Reverse IN PLACE.

sort(*, key=None, reverse: bool = False) None[source]

Sort the list in ascending order and return None.

The sort is in-place (i.e. the list 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 list item and sort them, ascending or descending, according to their function values.

The reverse flag can be set to sort in descending order.

_freeze_() None[source]
property _frozen_: bool
_reorder_(*, neworder: Iterable[int]) None[source]
_abc_impl = <_abc_data object>
class pdkmaster._util.ExtendedListMapping(iterable: _elem_typevar_ | Iterable[_elem_typevar_] = ())[source]

Bases: MutableSequence[_elem_typevar_], MutableMapping[_index_typevar_, _elem_typevar_], IterTypeMixin[_elem_typevar_], Generic[_elem_typevar_, _index_typevar_]

An internal collection class that combines a MutableSequence with MutableMapping

TODO: Extended internal API documentation.

API Notes

ExtendedListMapping assumes not isinstance(Iterable[_elem_typevar], _elem_typevar)

abstract property _index_attribute_: str
clear() None -- remove all items from S[source]
pop([index]) item -- remove and return item at index (default last).[source]

Raise IndexError if list is empty or index is out of range.

popitem() (k, v), remove and return some (key, value) pair[source]

as a 2-tuple; but raise KeyError if D is empty.

update([E, ]**F) None.  Update D from mapping/iterable E and F.[source]

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

index(elem: _elem_typevar_) int[source]

API Notes

  • Specifying start/end is currently not supported

insert(index: int, value: _elem_typevar_) None[source]

S.insert(index, value) – insert value before index

keys() a set-like object providing a view on D's keys[source]
items() a set-like object providing a view on D's items[source]
values() an object providing a view on D's values[source]
_freeze_() None[source]
property _frozen_: bool
_reorder_(neworder: Iterable[int]) None[source]
_abc_impl = <_abc_data object>
class pdkmaster._util._ListMappingOverride(*args, **kwds)[source]

Bases: MutableSequence[_elem_typevar_], MutableMapping[_index_typevar_, _elem_typevar_], Generic[_elem_typevar_, _index_typevar_]

A support class for helping subclassing of ListMapping. It allows to subclass a ListMapping class with an element that is a subclass of the parent ListMapping element.

TODO: Extended internal API documentation.

pop([index]) item -- remove and return item at index (default last).[source]

Raise IndexError if list is empty or index is out of range.

update([E, ]**F) None.  Update D from mapping/iterable E and F.[source]

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

_abc_impl = <_abc_data object>
index(value[, start[, stop]]) integer -- return first index of value.[source]

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

insert(index: int, value: _elem_typevar_) None[source]

S.insert(index, value) – insert value before index

class pdkmaster._util.ExtendedListStrMapping(iterable: _elem_typevar_ | Iterable[_elem_typevar_] = ())[source]

Bases: ExtendedListMapping[_elem_typevar_, str], Generic[_elem_typevar_]

TypeListMapping where the index type_ is str. By default this also take ‘name’ as default attribute name for the index. This can be overloaded in a subclass if needed.

TODO: Extended internal API documentation.

_abc_impl = <_abc_data object>
_map_: Dict[_index_typevar_, _elem_typevar_]
property _index_attribute_
class pdkmaster._util.ListStrMappingOverride(*args, **kwds)[source]

Bases: _ListMappingOverride[_elem_typevar_, str], Generic[_elem_typevar_]

A support class for helping subclassing of TypeListStrMapping analog to _ListMappingOverride.

TODO: Extended internal API documentation.

_abc_impl = <_abc_data object>