syn.base_utils package¶
Submodules¶
syn.base_utils.alg module¶
Some general purpose algorithms.
-
syn.base_utils.alg.
defer_reduce
(func, items, test, accum=None)¶ Recursively reduce items by func, but only the items that do not cause test(items, accum) to return False. Returns the reduced list (accum) and the list of remaining deferred items.
syn.base_utils.context module¶
-
syn.base_utils.context.
null_context
(*args, **kwds)¶ A context manager that does nothing.
-
syn.base_utils.context.
assign
(*args, **kwds)¶ Assigns B to A.attr, yields, and then assigns A.attr back to its original value.
-
syn.base_utils.context.
setitem
(*args, **kwds)¶
-
syn.base_utils.context.
chdir
(*args, **kwds)¶
-
syn.base_utils.context.
delete
(*args, **kwds)¶ For using then deleting objects.
-
syn.base_utils.context.
nested_context
(*args, **kwds)¶
-
syn.base_utils.context.
capture
(*args, **kwds)¶
-
syn.base_utils.context.
on_error
(*args, **kwds)¶
syn.base_utils.debug module¶
-
class
syn.base_utils.debug.
Trace
¶ Bases:
object
-
c_call
(frame, arg)¶
-
c_exception
(frame, arg)¶
-
c_return
(frame, arg)¶
-
call
(frame, arg)¶
-
exception
(frame, arg)¶
-
line
(frame, arg)¶
-
return_
(frame, arg)¶
-
-
class
syn.base_utils.debug.
CallTrace
(indent=0, tab=' ')¶ Bases:
syn.base_utils.debug.Trace
-
call
(frame, arg)¶
-
return_
(frame, arg)¶
-
-
syn.base_utils.debug.
call_trace
(**kwargs)¶
-
syn.base_utils.debug.
reset_trace
(*args, **kwds)¶
syn.base_utils.dict module¶
Various dict extensions.
-
class
syn.base_utils.dict.
AttrDict
¶ Bases:
dict
A dict whose items can be accessed as attributes.
-
class
syn.base_utils.dict.
UpdateDict
(*args, **kwargs)¶ Bases:
dict
A dict with an extensible update() hook.
-
update
(*args, **kwargs)¶
-
-
class
syn.base_utils.dict.
GroupDict
¶ Bases:
syn.base_utils.dict.AttrDict
An AttrDict whose items are treated as sets.
-
complement
(*args)¶ Returns the difference of the union of all values and the union of the values in *args.
-
intersection
(*args)¶ Returns the intersection of the values whose keys are in *args. If *args is blank, returns the intersection of all values.
-
union
(*args)¶ Returns the union of the values whose keys are in *args. If *args is blank, returns the union of all values.
-
update
(*args, **kwargs)¶
-
-
class
syn.base_utils.dict.
ReflexiveDict
(*args, **kwargs)¶ Bases:
syn.base_utils.dict.AttrDict
An AttrDict for which each key == the associated value.
-
class
syn.base_utils.dict.
SeqDict
¶ Bases:
syn.base_utils.dict.AttrDict
An AttrDict whose items are treated as sequences.
-
update
(*args, **kwargs)¶
-
syn.base_utils.filters module¶
Various filters for processing arguments. Inteded for use in the call keyword argument to the base.Base constructor.
-
syn.base_utils.filters.
split
(obj, sep=None)¶
-
syn.base_utils.filters.
join
(obj, sep=' ')¶
-
syn.base_utils.filters.
dictify_strings
(obj, empty=None, sep=None, typ=<type 'dict'>)¶
syn.base_utils.float module¶
-
syn.base_utils.float.
feq
(a, b, tol=1.4901161193847696e-08, relative=False)¶
-
syn.base_utils.float.
cfeq
(a, b, tol=1.4901161193847696e-08, relative=False)¶
-
syn.base_utils.float.
prod
(args, log=False)¶
-
syn.base_utils.float.
sgn
(x)¶
syn.base_utils.iter module¶
-
syn.base_utils.iter.
iterlen
(iter)¶ Returns the number of iterations remaining over iter.
-
syn.base_utils.iter.
is_empty
(iter)¶ Returns True if iter is empty, otherwise False.
-
syn.base_utils.iter.
consume
(it, *args, **kwargs)¶ Consumes N items from iter. If N is None (or not given), consumes all.
-
syn.base_utils.iter.
first
(it, *args, **kwargs)¶
-
syn.base_utils.iter.
last
(it, *args, **kwargs)¶
-
syn.base_utils.iter.
iteration_length
(N, start=0, step=1)¶ Return the number of iteration steps over a list of length N, starting at index start, proceeding step elements at a time.
syn.base_utils.list module¶
-
class
syn.base_utils.list.
ListView
(lst, start, end)¶ Bases:
_abcoll.MutableSequence
A list view.
-
insert
(idx, obj)¶
-
-
class
syn.base_utils.list.
IterableList
(values, position=0, position_mark=None)¶ Bases:
list
-
consume
(n)¶
-
copy
()¶
-
displacement
()¶
-
empty
()¶
-
mark
()¶
-
next
()¶
-
peek
(n=None, safe=True)¶
-
previous
()¶
-
reset
()¶
-
seek
(n, mode=0)¶
-
take
(n)¶
-
-
class
syn.base_utils.list.
DefaultList
(default, *args, **kwargs)¶ Bases:
list
-
syn.base_utils.list.
is_proper_sequence
(seq)¶
-
syn.base_utils.list.
is_flat
(seq)¶
-
syn.base_utils.list.
is_unique
(seq)¶ Returns True if every item in the seq is unique, False otherwise.
-
syn.base_utils.list.
indices_removed
(lst, idxs)¶ Returns a copy of lst with each index in idxs removed.
-
syn.base_utils.list.
flattened
(seq)¶
syn.base_utils.logic module¶
-
syn.base_utils.logic.
implies
(a, b)¶
-
syn.base_utils.logic.
equiv
(a, b)¶
-
syn.base_utils.logic.
xor
(a, b)¶
-
syn.base_utils.logic.
and_
(*args)¶
-
syn.base_utils.logic.
or_
(*args)¶
-
syn.base_utils.logic.
nand
(*args)¶
-
syn.base_utils.logic.
nor
(*args)¶
-
syn.base_utils.logic.
fuzzy_and
(*args)¶
-
syn.base_utils.logic.
fuzzy_not
(arg)¶
-
syn.base_utils.logic.
fuzzy_nand
(*args)¶
-
syn.base_utils.logic.
fuzzy_or
(*args)¶
-
syn.base_utils.logic.
fuzzy_nor
(*args)¶
-
syn.base_utils.logic.
fuzzy_implies
(a, b)¶
-
syn.base_utils.logic.
fuzzy_equiv
(a, b)¶
-
syn.base_utils.logic.
fuzzy_xor
(a, b)¶
-
syn.base_utils.logic.
collection_equivalent
(A, B)¶
-
syn.base_utils.logic.
collection_comp
(A, B, item_func=<built-in function eq>, coll_func=<built-in function all>)¶
syn.base_utils.order module¶
-
class
syn.base_utils.order.
Precedes
(A, B)¶ Bases:
object
-
syn.base_utils.order.
Succeeds
(A, B)¶
-
syn.base_utils.order.
topological_sorting
(nodes, relations)¶ An implementation of Kahn’s algorithm.
syn.base_utils.py module¶
-
syn.base_utils.py.
mro
(cls)¶
-
syn.base_utils.py.
hasmethod
(x, name)¶
-
syn.base_utils.py.
import_module
(modname)¶
-
syn.base_utils.py.
message
(e)¶
-
syn.base_utils.py.
run_all_tests
(env, verbose=False, print_errors=False, exclude=None, include=None)¶
-
syn.base_utils.py.
index
(seq, elem)¶
-
syn.base_utils.py.
nearest_base
(cls, bases)¶ Returns the closest ancestor to cls in bases.
-
syn.base_utils.py.
get_typename
(x)¶ Returns the name of the type of x, if x is an object. Otherwise, returns the name of x.
-
syn.base_utils.py.
get_mod
(cls)¶ Returns the string identifying the module that cls is defined in.
-
syn.base_utils.py.
compose
(*funcs)¶
-
syn.base_utils.py.
assert_equivalent
(o1, o2)¶ Asserts that o1 and o2 are distinct, yet equivalent objects
-
syn.base_utils.py.
assert_inequivalent
(o1, o2)¶ Asserts that o1 and o2 are distinct and inequivalent objects
-
syn.base_utils.py.
assert_type_equivalent
(o1, o2)¶ Asserts that o1 and o2 are distinct, yet equivalent objects of the same type
-
syn.base_utils.py.
assert_pickle_idempotent
(obj)¶ Assert that obj does not change (w.r.t. ==) under repeated picklings
-
syn.base_utils.py.
assert_deepcopy_idempotent
(obj)¶ Assert that obj does not change (w.r.t. ==) under repeated deepcopies
-
syn.base_utils.py.
rgetattr
(obj, attr, *args)¶
-
syn.base_utils.py.
callables
(obj, exclude_sys=True)¶
-
syn.base_utils.py.
is_subclass
(x, typ)¶
-
syn.base_utils.py.
getitem
(mapping, item, default=None, allow_none_default=False, delete=False)¶
-
syn.base_utils.py.
same_lineage
(o1, o2)¶ Returns True iff o1 and o2 are of the same class lineage (that is, a direct line of descent, without branches).
-
syn.base_utils.py.
type_partition
(lst, *types)¶
-
syn.base_utils.py.
subclasses
(cls, lst=None)¶ Recursively gather subclasses of cls.
-
syn.base_utils.py.
unzip
(seq)¶
-
syn.base_utils.py.
this_module
(npop=1)¶ Returns the module object of the module this function is called from
-
syn.base_utils.py.
eprint
(out, flush=True)¶
-
syn.base_utils.py.
harvest_metadata
(fpath, abspath=False, template='__{}__')¶
-
syn.base_utils.py.
tuple_append
(tup, x)¶
-
syn.base_utils.py.
get_fullname
(x)¶
-
syn.base_utils.py.
tuple_prepend
(x, tup)¶
-
syn.base_utils.py.
elog
(exc, func, args=None, kwargs=None, str=<type 'str'>, pretty=True, name='')¶ For logging exception-raising function invocations during randomized unit tests.
-
syn.base_utils.py.
ngzwarn
(value, name)¶
-
syn.base_utils.py.
full_funcname
(func)¶
-
syn.base_utils.py.
hangwatch
(timeout, func, *args, **kwargs)¶
-
syn.base_utils.py.
safe_vars
(*args, **kwargs)¶
-
syn.base_utils.py.
getfunc
(obj, name='')¶ Get the function corresponding to name from obj, not the method.
-
class
syn.base_utils.py.
Partial
(f, args=None, indexes=None, kwargs=None)¶ Bases:
object
Partial function object that allows specification of which indices are “baked in”.
-
syn.base_utils.py.
pyversion
()¶
-
syn.base_utils.py.
getkey
(mapping, value, default=None, use_id=False)¶ Returns the first key mapping to value, as encountered via iteritems(), otherwise default. Obviously, works best for injective maps.
syn.base_utils.rand module¶
Random value-generating utilities. Intended mainly for generating random values for testing purposes (i.e. finding edge cases).
-
syn.base_utils.rand.
rand_bool
(thresh=0.5, **kwargs)¶
-
syn.base_utils.rand.
rand_int
(min_val=-9223372036854775808, max_val=9223372036854775807, **kwargs)¶
-
syn.base_utils.rand.
rand_float
(lb=None, ub=None, **kwargs)¶
-
syn.base_utils.rand.
rand_complex
(imag_only=False, **kwargs)¶
-
syn.base_utils.rand.
rand_long
(min_len=None, max_len=None, **kwargs)¶
-
syn.base_utils.rand.
rand_str
(min_char=0, max_char=255, min_len=0, max_len=10, func=<built-in function chr>, **kwargs)¶ For values in the (extended) ASCII range, regardless of Python version.
-
syn.base_utils.rand.
rand_unicode
(min_char=0, max_char=1114111, min_len=0, max_len=10, **kwargs)¶ For values in the unicode range, regardless of Python version.
-
syn.base_utils.rand.
rand_bytes
(**kwargs)¶
-
syn.base_utils.rand.
rand_list
(**kwargs)¶
-
syn.base_utils.rand.
rand_tuple
(**kwargs)¶
-
syn.base_utils.rand.
rand_dict
(**kwargs)¶
-
syn.base_utils.rand.
rand_set
(**kwargs)¶
-
syn.base_utils.rand.
rand_frozenset
(**kwargs)¶
-
syn.base_utils.rand.
rand_none
(**kwargs)¶
-
syn.base_utils.rand.
rand_dispatch
(typ, **kwargs)¶
-
syn.base_utils.rand.
rand_primitive
(**kwargs)¶
-
syn.base_utils.rand.
rand_hashable
(**kwargs)¶
syn.base_utils.repl module¶
-
class
syn.base_utils.repl.
REPL
(prompt='')¶ Bases:
object
-
command_help
= {'q': 'quit', 'h': 'display available commands', 'e': 'eval the argument', '?': 'display available commands'}¶
-
commands
= {'q': <function quit>, 'h': <function print_commands>, 'e': <function eval>, '?': <function print_commands>}¶
-
eval
(expr)¶
-
print_commands
(**kwargs)¶
-
quit
(*args, **kwargs)¶
-
-
class
syn.base_utils.repl.
repl_command
(name, help='')¶ Bases:
object
syn.base_utils.str module¶
-
syn.base_utils.str.
quote_string
(obj)¶
-
syn.base_utils.str.
outer_quotes
(string)¶
-
syn.base_utils.str.
break_quoted_string
(string, pattern, repl=None)¶
-
syn.base_utils.str.
break_around_line_breaks
(string)¶
-
syn.base_utils.str.
escape_line_breaks
(string)¶
-
syn.base_utils.str.
escape_null
(string)¶
-
syn.base_utils.str.
escape_for_eval
(string)¶
-
syn.base_utils.str.
chrs
(lst)¶
-
syn.base_utils.str.
safe_chr
(x)¶
-
syn.base_utils.str.
safe_str
(x, encoding='utf-8')¶
-
syn.base_utils.str.
safe_unicode
(x)¶
-
syn.base_utils.str.
safe_print
(x, encoding='utf-8')¶
-
syn.base_utils.str.
istr
(obj, pretty=False, indent=0)¶
syn.base_utils.tree module¶
-
syn.base_utils.tree.
seq_list_nested
(b, d, x=0, top_level=True)¶ Create a nested list of iteratively increasing values.
b: branching factor d: max depth x: starting value (default = 0)