Skip to content

Commit

Permalink
#81: added utils.function. utils cleanup. removed unused files
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-biasion committed Sep 13, 2024
1 parent 6447dbb commit 337b6f3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 300 deletions.
253 changes: 0 additions & 253 deletions sxpat/distance_function.py

This file was deleted.

9 changes: 7 additions & 2 deletions sxpat/utils/collections.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations
from collections import UserDict
from typing import Iterable, Iterator, Mapping, Sequence, Tuple, Type, TypeVar, Union
from typing import Iterable, Iterator, Mapping, Tuple, Type, TypeVar

import itertools

__all__ = ['mapping_inv', 'flat', 'pairwise', 'MultiDict', 'InheritanceMapping']


NOTHING = object()
Expand Down Expand Up @@ -39,6 +40,10 @@ def pairwise(iterable: Iterable[T]) -> Iterator[Tuple[T, T]]:
a = b


def unzip(iterable: Iterable) -> Iterable:
return zip(*iterable)


class MultiDict(UserDict, Mapping[K, V]):
def __init__(self, mapping: Mapping[Iterable[K], V] = None) -> None:
super().__init__()
Expand Down
27 changes: 27 additions & 0 deletions sxpat/utils/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import Callable, TypeVar


__all__ = ['get_producer', 'identity', 'str_to_bool']


T = TypeVar('T')


def get_producer(value: T) -> Callable[[], T]:
return lambda: value


def identity(value: T) -> T:
return value


STR_TO_BOOL = {
'true': True,
't': True,
'false': False,
'f': False,
}


def str_to_bool(string: str) -> bool:
return STR_TO_BOOL[string.lower()]
5 changes: 4 additions & 1 deletion sxpat/utils/inheritance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from typing import List, Set, Type
from typing import Set, Type


__all__ = ['get_all_subclasses', 'get_all_leaves_subclasses']


def get_all_subclasses(cls: Type) -> Set[Type]:
Expand Down
44 changes: 0 additions & 44 deletions sxpat/utils/utils.py

This file was deleted.

0 comments on commit 337b6f3

Please sign in to comment.