pytableaux.tools

Functions

pytableaux.tools

dund(name)[source]

Convert name to dunder format.

Parameters:

name (str) --

Return type:

str

isdund(name)[source]

Whether the string is a dunder name string.

Parameters:

name (str) --

Return type:

bool

undund(name)[source]

Remove dunder from the name.

Parameters:

name (str) --

Return type:

str

getitem(obj, key, default=<object object>, /)[source]

Get by subscript similar to getattr().

select_fget(obj)[source]

Return getitem() if the object has a callable __getitem__ method, else return getattr().

thru(obj)[source]

Return the argument.

Parameters:

obj (_T) --

Return type:

_T

group(*items)[source]

Tuple builder.

Parameters:

*items -- members.

Returns:

The tuple of arguments.

isint(obj)[source]

Whether the argument is an int instance

Return type:

bool

isattrstr(obj)[source]

Whether the argument is a non-keyword identifier string

Return type:

bool

re_boolyes = re.compile('^(true|yes|1)$', re.IGNORECASE)

Regex for string boolean yes.

sbool(arg, /)[source]

Cast string to boolean, leans toward False.

Parameters:

arg (str) --

Return type:

bool

minfloor(floor, it, default=None)[source]

Return the minimum value of it, stopping when a value less than or equal to floor is reached.

Parameters:
Return type:

_T

maxceil(ceil, it, default=None)[source]

Return the maximum value of it, stopping when a value greater than or equal to ceil is reached.

Parameters:
Return type:

_T

limit_best(better, limit, it, default=None)[source]

Generic form for minfloor() and maxceil().

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 for old.

Parameters:

collection (_T) --

Return type:

_T

for_defaults(defaults, override, /)[source]

Return a dict with keys from defaults, with values from override, or defaults if missing.

Parameters:
Return type:

dict[_KT, _VT]

absindex(seqlen, index, /, strict=True)[source]

Normalize to positive/absolute index.

Parameters:
  • seqlen (int) --

  • index (int) --

Return type:

int

slicerange(seqlen, slice_, values, /, strict=True)[source]

Get a range of indexes from a slice and new values, and perform checks.

Parameters:
Return type:

range

class wraps(wrapped=None, /, *, only=frozenset({'__annotations__', '__doc__', '__module__', '__name__', '__qualname__'}), exclude=frozenset({}), **kw)[source]

Replacement for functools.wraps().

write(wrapper)[source]

Write wrapped attributes to a wrapper.

update(obj=None, /, **kw)[source]

Read from an object/mapping and update relevant values. Any attributes already present are ignored. Returns self.

read(obj)[source]

Read relevant attributes from object/mapping.

setdefault(key, value)[source]

Override value if key is relevant and value is not empty.

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

dmerged()[source]

Basic dict merge copy, recursive for dict value.

Return type:

dict

class NoSetAttr(*, enabled=True, **opts)[source]

Lame thing that does a lame thing.

Parameters:
enabled: bool

Whether raising is enabled.

class MapCover(mapping, /)[source]

Mapping reference.

Parameters:

mapping (Mapping) --

class SeqCover(seq, /)[source]

Sequence cover.

Parameters:

seq (Sequence) --

class KeySetAttr[source]

Mixin class for read-write attribute-key gate.

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 dictns(*args, **kw)[source]

Dict attr namespace with __dict__ slot and liberal key approval.

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'.

default

alias of dict

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.
class SetView(set_, /)[source]

Set cover.

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.

isabstract(obj)[source]

Whether a class or method is abstract.

Return type:

bool

check_mrodict(mro, *names)[source]

Check whether methods are implemented for dynamic subclassing.

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 is setattr.

  • **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:
  • name (str) -- The attribute/key name.

  • it (Iterable | None) -- The iterable of objects. If None, mroiter is called with **iteropts.

Keyword Arguments:
  • oper (Callable) -- The reduce operator, default is operator.or_.

  • initial (Any) -- The initial reduce value. From functools.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:
  • cls (type[_T]) -- The base class.

  • supcls (type[_T1]) --

  • mcls (type[_T2]) --

Keyword Arguments:
  • supcls (type) -- The class(es) of which members must be a subclass.

  • mcls (type) -- The metaclass(es) of which members must be an instance.

  • reverse (bool) -- Start from the top with object. Default True.

Returns:

An iterator.

Return type:

Iterator[type[_T] | type[_T1] | _T2]

class abcf(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Enum flag for AbcMeta functionality.

classmethod read(obj, default=0, /, *, attr=Astr.flag)[source]

Get the flag (or blank) for any obj.

Return type:

abcf

classmethod save(obj, value, /, *, attr=Astr.flag)[source]

Write the value, returns obj for decorator use.

nsinit(ns, bases, /)[source]

Class namespace prepare routine.

Parameters:

ns (dict) --

clsafter(cls, ns=None, /, *, deleter=<slot wrapper '__delattr__' of 'type' objects>)[source]

After class init routine. Usable as standalone class decorator.

Parameters:
Return type:

type[_T]

class EnumLookup(Owner, /)[source]

Enum member lookup index.

build: Callable

Build and update the whole index.

pseudo: Callable

Add a single pseudo member to the index.

class EbcMeta(clsname, bases, ns, /, **kw)[source]

General-purpose base Metaclass for all Enum classes.

get(key, default=<object object>, /)[source]

Get a member by an indexed reference key.

Parameters:
  • key -- member lookup key, value, instance, etc..

  • default -- value to return if not found.

  • cls (type[_EnumT]) --

Returns:

The enum member, or default if specified and not found.

Raises:

KeyError -- if not found and no default specified.

Return type:

_EnumT

class AbcMeta(clsname, bases, ns, /, **kw)[source]

Abc Meta class with before/after hooks.

class Abc[source]

Convenience for using AbcMeta as metaclass.