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_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 41
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of IterableOverride

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

Bases: Iterable[_elem_typevar_], Generic[_elem_typevar_]

Internal collection support

TODO: Extended internal API documentation.

_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 41
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of IterTypeMixin

class pdkmaster._util.ExtendedList(*args, **kwds)[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(object) None -- append object to end[source]
clear() None -- remove all items from L[source]
extend(iterable) None -- extend list by appending elements from the iterable[source]
insert(_ExtendedList__index: int, _ExtendedList__object: _elem_typevar_) None[source]

L.insert(index, object) – insert object before index

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

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

remove(value) None -- remove first occurrence of value.[source]

Raises ValueError if the value is not present.

reverse() None[source]

L.reverse() – reverse IN PLACE

sort(key=None, reverse=False) None -- stable sort *IN PLACE*[source]
_freeze_() None[source]
property _frozen_: bool
_reorder_(*, neworder: Iterable[int]) None[source]
_abc_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 41
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of ExtendedList

class pdkmaster._util.ExtendedListMapping(iterable: Union[T, Iterable[T]] = ())[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_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 41
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of ExtendedListMapping

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_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 41
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of _ListMappingOverride

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: Union[T, Iterable[T]] = ())[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_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 41
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of ExtendedListStrMapping

_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_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache = <_weakrefset.WeakSet object>
_abc_generic_negative_cache_version = 41
_abc_registry = <_weakrefset.WeakSet object>
_gorg

alias of ListStrMappingOverride