pytableaux.tools
Functions
pytableaux.tools
- select_fget(obj)[source]
Return
getitem()
if the object has a callable __getitem__ method, else returngetattr()
.
- group(*items)[source]
Tuple builder.
- Parameters:
*items -- members.
- Returns:
The tuple of arguments.
- re_boolyes = re.compile('^(true|yes|1)$', re.IGNORECASE)
Regex for string boolean yes.
- minfloor(floor, it, default=None)[source]
Return the minimum value of
it
, stopping when a value less than or equal tofloor
is reached.- Parameters:
floor (_T) --
it (Iterable[_T]) --
- Return type:
_T
- maxceil(ceil, it, default=None)[source]
Return the maximum value of
it
, stopping when a value greater than or equal toceil
is reached.- Parameters:
ceil (_T) --
it (Iterable[_T]) --
- Return type:
_T
- limit_best(better, limit, it, default=None)[source]
Generic form for
minfloor()
andmaxceil()
.- Parameters:
better (Callable[[_T, _T], bool]) -- A pairwise comparison function, e.g.
operator.lt()
limit (_T) -- The limit, e.g. floor or ceil.
it (Iterable[_T]) -- The iterable.
default -- A default value for an empty iterable.
- Return type:
_T
- substitute(collection, old, new)[source]
Return a new instance of the collection type with
new
substituted forold
.- Parameters:
collection (_T) --
- Return type:
_T
- for_defaults(defaults, override, /)[source]
Return a dict with keys from
defaults
, with values fromoverride
, ordefaults
if missing.
- slicerange(seqlen, slice_, values, /, strict=True)[source]
Get a range of indexes from a slice and new values, and perform checks.
- class wraps(wrapped=None, /, *, only=frozenset({'__annotations__', '__doc__', '__module__', '__name__', '__qualname__'}), exclude=frozenset({}), **kw)[source]
Replacement for
functools.wraps()
.
- closure(func)[source]
Closure decorator calls the argument and returns its return value. If the return value is a function, updates its wrapper.
- Parameters:
func (Callable[[...], _T]) --
- Return type:
_T
- class dictattr(*args, **kw)[source]
Dict attr base class.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
- update([E, ]**F) None. Update D from mapping/iterable E and F.
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 TransMmap(*args, **kw)[source]
Mutable mapping with key/value translators
- static kget(obj)
Return the argument.
- Parameters:
obj (_T) --
- Return type:
_T
- static kset(obj)
Return the argument.
- Parameters:
obj (_T) --
- Return type:
_T
- static vget(obj)
Return the argument.
- Parameters:
obj (_T) --
- Return type:
_T
- static vset(obj)
Return the argument.
- Parameters:
obj (_T) --
- Return type:
_T
- class PathedDict(*args, **kw)[source]
A nested dict that supports key path expressions like 'a:b:c'.
- get(k[, d]) D[k] if k in D, else d. d defaults to None.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
- update([E, ]**F) None. Update D from mapping/iterable E and F.
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 ItemMapEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Fixed mapping enum based on item tuples.
If a member value is defined as a mapping, the member's
_value_
attribute is converted to a tuple of item tuples during__init__()
.Implementations should always call
super().__init__()
if it is overridden.- keys() a set-like object providing a view on D's keys
- items() a set-like object providing a view on D's items
- values() an object providing a view on D's values
- get(k[, d]) D[k] if k in D, else d. d defaults to None.
abcs module
pytableaux.tools.abcs
- class Eset(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Enum meta enumeration.
- class Astr(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Attribute names for abc functionality.
- merge_attr(obj, name, it=None, /, *, setter=<built-in function setattr>, **kw)[source]
Merge an object's attribute, either from objects, or an mro.
- Parameters:
obj -- The object to update.
name (str) -- The attribute name.
it (
Optional
) -- Iterable of objects to check. Default is mro of obj.
- Keyword Arguments:
setter (
Callable
) -- The function to set the attribute, default issetattr
.**kw -- Additional arguments passed to
merged_attr()
- merged_attr(name, it=None, /, *, oper=<built-in function or_>, initial=<object object>, default=<object object>, transform=<function thru>, **iteropts)[source]
Get merged attribute value, either from objects, or an mro.
- Parameters:
- Keyword Arguments:
oper (
Callable
) -- The reduce operator, default isoperator.or_
.initial (
Any
) -- The initial reduce value. Fromfunctools.reduce()
: If initial is present, it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty.default (
Any
) -- The default value for each object in the iterable. If not present, initial is used if present.transform (
Callable
) -- A type or callable to transform the final value.
- Returns:
The merged value.
- mroiter(cls, *, supcls=None, mcls=None, reverse=True)[source]
Returns an iterator for a class's mro with filters.
- Parameters:
- Keyword Arguments:
- Returns:
An iterator.
- Return type:
- class abcf(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Enum flag for AbcMeta functionality.
- clsafter(cls, ns=None, /, *, deleter=<slot wrapper '__delattr__' of 'type' objects>)[source]
After class init routine. Usable as standalone class decorator.