hwt.pyUtils package

This package contains python utils used in this library.

Submodules

hwt.pyUtils.arrayQuery module

exception hwt.pyUtils.arrayQuery.DuplicitValueExc[source]

Bases: Exception

Exception which means that there are multiple items which this query selected but it should return only one

exception hwt.pyUtils.arrayQuery.NoValueExc[source]

Bases: Exception

Exception which means that query did not selected any item

hwt.pyUtils.arrayQuery.areSetsIntersets(setA: set, setB: set)[source]

Check if intersection of sets is not empty

hwt.pyUtils.arrayQuery.arr_all(iterable, fn)[source]
Returns:

True if fn(item) for all items in interable or iterable is empty else False

hwt.pyUtils.arrayQuery.arr_any(iterable, fn)[source]
Returns:

True if fn(item) for any item else False

hwt.pyUtils.arrayQuery.balanced_reduce(arr: Sequence, opFn)[source]
hwt.pyUtils.arrayQuery.flatten(iterables, level=inf)[source]

Flatten nested lists, tuples, generators and maps

Parameters:

level – maximum depth of flattening

hwt.pyUtils.arrayQuery.groupedby(collection, fn)[source]

same like itertools.groupby

Note:

This function does not needs initial sorting like itertools.groupby

Attention:

Order of pairs is not deterministic.

hwt.pyUtils.arrayQuery.grouper(n: int, iterable: Sequence, padvalue=None)[source]

grouper(3, ‘abcdefg’, ‘x’) –> (‘a’,’b’,’c’), (‘d’,’e’,’f’), (‘g’,’x’,’x’)

hwt.pyUtils.arrayQuery.single(iterable, fn)[source]

Get value from iterable where fn(item) and check if there is not fn(other item)

Raises:
hwt.pyUtils.arrayQuery.take(iterrable, howMay)[source]
Returns:

generator of first n items from iterrable

hwt.pyUtils.arrayQuery.where(iterable, fn)[source]
Returns:

generator of items from iterable where fn(item)

hwt.pyUtils.fileHelpers module

hwt.pyUtils.fileHelpers.find_files(directory, pattern, recursive=True)[source]

Find files by pattern in directory

hwt.pyUtils.setDeque module

class hwt.pyUtils.setDeque.SetDeque(initSeq: Sequence[T] | None = None)[source]

Bases: Generic[T], deque

Deque of unique items

See:

https://docs.python.org/3/tutorial/datastructures.html

__init__(initSeq: Sequence[T] | None = None)[source]
_get_set() set[T][source]
append(item: T) bool[source]
Returns:

True if the item was newly added

clear()[source]

Remove all elements from the deque.

copy()[source]

Return a shallow copy of a deque.

discard(item: T) bool[source]
Returns:

True if the item was previously in this deque

extend(items: Sequence[T])[source]

Extend the right side of the deque with elements from the iterable

insert(i: int, x: T)[source]

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

intersection_set(other: set[T])[source]
pop(*args, **kwargs) T[source]

Remove and return the rightmost element.

popleft() T[source]

Remove and return the leftmost element.

remove(item: T)[source]

D.remove(value) – remove first occurrence of value.

hwt.pyUtils.setList module

class hwt.pyUtils.setList.SetList(initSeq: Sequence[T] | None = None)[source]

Bases: Generic[T], list

List of unique items

See:

https://docs.python.org/3/tutorial/datastructures.html

__init__(initSeq: Sequence[T] | None = None)[source]
_get_set() set[T][source]
append(item: T) bool[source]
Returns:

True if the item was newly added

clear()[source]

Remove all items from list.

copy()[source]

Return a shallow copy of the list.

discard(item: T) bool[source]
Returns:

True if the item was previously in this list

extend(items: Sequence[T])[source]

Extend list by appending elements from the iterable.

insert(i: int, x: T)[source]

Insert object before index.

intersection_set(other: set[T])[source]
pop(*args, **kwargs) T[source]

Remove and return item at index (default last).

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

remove(item: T)[source]

Remove first occurrence of value.

Raises ValueError if the value is not present.

hwt.pyUtils.testUtils module

class hwt.pyUtils.testUtils.TestMatrix(*args, **kwargs)[source]

Bases: object

Class which instance is a decorator which executes unittest.TestCase test method with every combination of argumets

__init__(*args, **kwargs)[source]
Note:

args, kwargs are lists of arguments which should be passed as a test arguments

split_args_kwargs(args)[source]

hwt.pyUtils.typingFuture module

hwt.pyUtils.typingFuture.override(method)[source]

Check that the method overrides the parent method. A temporal supplement for typing.override from python3.12

Inspired by https://stackoverflow.com/questions/1167617/in-python-how-do-i-indicate-im-overriding-a-method