Skip to content

funcs

Classes:

  • StrList

    Custom class for representing a recursively "stringable" list.

Attributes:

Sentinel module-attribute

Sentinel = SentinelDispatcher()

SentinelT module-attribute

SentinelDispatcher

Methods:

__call__

__call__() -> SentinelDispatcher
Source code in jetpytools/types/funcs.py
90
91
def __call__(self) -> SentinelDispatcher:
    return SentinelDispatcher()

check

check(ret_value: T, cond: bool) -> T | SentinelDispatcher
Source code in jetpytools/types/funcs.py
53
54
def check[T](self, ret_value: T, cond: bool) -> T | SentinelDispatcher:
    return ret_value if cond else self

check_cb

check_cb(
    callback: Callable[P, tuple[T, bool]],
) -> Callable[P, T | SentinelDispatcher]
Source code in jetpytools/types/funcs.py
56
57
58
59
60
61
62
63
def check_cb[T, **P](self, callback: Callable[P, tuple[T, bool]]) -> Callable[P, T | SentinelDispatcher]:
    from functools import wraps

    @wraps(callback)
    def _wrap(*args: P.args, **kwargs: P.kwargs) -> T | SentinelDispatcher:
        return self.check(*callback(*args, **kwargs))

    return _wrap

filter

filter(items: Iterable[T | SentinelDispatcher]) -> Iterator[T]
Source code in jetpytools/types/funcs.py
65
66
67
68
69
def filter[T](self, items: Iterable[T | SentinelDispatcher]) -> Iterator[T]:
    for item in items:
        if isinstance(item, SentinelDispatcher):
            continue
        yield item

filter_multi classmethod

filter_multi(
    items: Iterable[T | SentinelDispatcher], *sentinels: SentinelDispatcher
) -> Iterator[T]
Source code in jetpytools/types/funcs.py
71
72
73
74
75
76
77
78
79
80
@classmethod
def filter_multi[T](cls, items: Iterable[T | SentinelDispatcher], *sentinels: SentinelDispatcher) -> Iterator[T]:
    def _in_sentinels(it: Any) -> TypeIs[SentinelDispatcher]:
        return it in sentinels

    for item in items:
        if _in_sentinels(item):
            continue

        yield item

StrList

StrList(iterable: Iterable[SupportsString | None] | None = ...)

Bases: list[SupportsString]

Custom class for representing a recursively "stringable" list.

Methods:

Attributes:

Source code in jetpytools/types/funcs.py
20
def __init__(self, iterable: Iterable[SupportsString | None] | None = ..., /) -> None: ...

mlength property

mlength: int

string property

string: str

append

append(*__object: SupportsString) -> None
Source code in jetpytools/types/funcs.py
47
48
49
def append(self, *__object: SupportsString) -> None:
    for __obj in __object:
        super().append(__obj)

to_str

to_str() -> str
Source code in jetpytools/types/funcs.py
26
27
def to_str(self) -> str:
    return str(self)