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.
v2t
(value: Union[T, Iterable[T]], *, n: Optional[int] = None) → Tuple[_elem_typevar_, ...][source]¶ Convert a single value or an iterable of value to a tuple.
- Parameters:
value – a single value or an iterable of value
n – length specification for return value
- Returns:
If n is not specified and value is single value, a tuple with the value will be returned.
If n specified and value is a single value, a tuple with n times the value will be returns.
If n is specified and value is an iterable, the length of iterable will be checked to correspond with given length
-
pdkmaster._util.
nth
(it: Iterable[_elem_typevar_], n) → _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.
first
(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.
last
(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
[source]¶ Bases:
collections.abc.Iterable
,typing.Generic
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
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
[source]¶ Bases:
collections.abc.Iterable
,typing.Generic
Internal collection support
TODO: Extended internal API documentation.
-
_abc_impl
= <_abc_data object>¶
-
-
class
pdkmaster._util.
TypedList
(iterable: Iterable[_elem_typevar_] = ())[source]¶ Bases:
list
,pdkmaster._util.IterTypeMixin
,typing.Generic
An internal list class that allow only elements of certain type.
TODO: Extended internal API documentation.
-
abstract property
_elem_type_
¶
-
extend
(_TypedList__iterable: Iterable[_elem_typevar_]) → None[source]¶ Extend list by appending elements from the iterable.
-
insert
(_TypedList__index: int, _TypedList__object: _elem_typevar_) → None[source]¶ Insert object before index.
-
pop
(_TypedList__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
(_TypedList__value: _elem_typevar_) → None[source]¶ Remove first occurrence of value.
Raises ValueError if the value is not present.
-
property
_frozen_
¶
-
_abc_impl
= <_abc_data object>¶
-
abstract property
-
class
pdkmaster._util.
TypedListMapping
(iterable: Union[T, Iterable[T]] = ())[source]¶ Bases:
collections.abc.MutableSequence
,collections.abc.MutableMapping
,pdkmaster._util.IterTypeMixin
,typing.Generic
An internal collection class that combines a MutableSequence with MutableMapping
TODO: Extended internal API documentation.
API Notes
TypedListMapping assumes not isinstance(Iterable[_elem_typevar], _elem_typevar) _elem_type_ has to be valid when _typedListMapping.__init__() is called.
-
T
= ~T¶
-
class
_List
(iterable: Iterable[TypedListMapping.T], parent: pdkmaster._util.TypedListMapping)[source]¶ Bases:
pdkmaster._util.TypedList
-
property
_elem_type_
¶
-
_abc_impl
= <_abc_data object>¶
-
property
-
abstract property
_elem_type_
¶
-
abstract property
_index_type_
¶
-
abstract property
_index_attribute_
¶
-
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
-
property
_frozen_
¶
-
_abc_impl
= <_abc_data object>¶
-
-
class
pdkmaster._util.
_ListMappingOverride
[source]¶ Bases:
collections.abc.MutableSequence
,collections.abc.MutableMapping
,typing.Generic
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.
-
_abc_impl
= <_abc_data object>¶
-
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
-
-
class
pdkmaster._util.
TypedListStrMapping
(iterable: Union[T, Iterable[T]] = ())[source]¶ Bases:
pdkmaster._util.TypedListMapping
,typing.Generic
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>¶
-
property
_index_type_
¶
-
property
_index_attribute_
¶
-
-
class
pdkmaster._util.
ListStrMappingOverride
[source]¶ Bases:
pdkmaster._util._ListMappingOverride
,typing.Generic
A support class for helping subclassing of TypeListStrMapping analog to _ListMappingOverride.
TODO: Extended internal API documentation.
-
_abc_impl
= <_abc_data object>¶
-