pane.util
pane.util
P = ParamSpec('P')
module-attribute
KeyCache
Source code in pane/util.py
maxsize = maxsize
instance-attribute
key_f = key_f
instance-attribute
inner_f = f
instance-attribute
cache = {}
instance-attribute
full = self.maxsize == 0
instance-attribute
partition(f, iter)
Partition iter
into values that satisfy f
and those which don't.
Source code in pane/util.py
pluralize(word, plural, suffix='s', article=None)
Pluralize word
based on the value of plural
.
Source code in pane/util.py
list_phrase(words, conj='or')
Form an english list phrase from words
, using the conjunction conj
.
remove_article(s)
collect_typevars(args)
Collect a list of type variables in args
Preserves order but removes duplicates (i.e. type variables are returned in the order they are encountered, but no type variable is returned twice).
Loosely based on typing._collect_parameters
.
Source code in pane/util.py
type_union(types)
flatten_union_args(types)
Flatten nested unions, returning a single sequence of possible union types.
Source code in pane/util.py
replace_typevars(ty, replacements)
Apply a list of type-variable replacements to ty
, and return the modified type.
Source code in pane/util.py
get_type_hints(cls)
Extract a dict of type hints from cls
. Evaluate forward refs if possible.
This is a slightly modified version of typing.get_type_hints.
Source code in pane/util.py
broadcast_shapes(*args)
Attempt to broadcast the given shapes together using numpy semantics.
Defers to numpy.broadcast_shapes
if numpy is available.
Source code in pane/util.py
is_broadcastable(*args)
Return whether args
are broadcastable together using numpy semantics.