utool.experimental package¶
Submodules¶
utool.experimental.bytecode_optimizations module¶
References
http://code.activestate.com/recipes/576904/ http://code.activestate.com/recipes/277940-decorator-for-bindingconstants-at-compile-time/
-
utool.experimental.bytecode_optimizations.
bind_all
(mc, builtin_only=False, stoplist=[], verbose=False)[source]¶ Recursively apply constant binding to functions in a module or class.
Use as the last line of the module (after everything is defined, but before test code). In modules that need modifiable globals, set builtin_only to True.
-
utool.experimental.bytecode_optimizations.
get_disassembly_string
(x, lasti=-1)[source]¶ Reimplementation of disassemble that returns a string. Disassemble a code object.
- SeeAlso:
- std library dis.py module
-
utool.experimental.bytecode_optimizations.
make_constants
(builtin_only=False, stoplist=[], verbose=False)[source]¶ Return a decorator for optimizing global references.
Replaces global references with their currently defined values. If not defined, the dynamic (runtime) global lookup is left undisturbed. If builtin_only is True, then only builtins are optimized. Variable names in the stoplist are also left undisturbed. Also, folds constant attr lookups and tuples of constants. If verbose is True, prints each substitution as is occurs
-
utool.experimental.bytecode_optimizations.
sample
(population, k)[source]¶ Choose k unique random elements from a population sequence.
-
utool.experimental.bytecode_optimizations.
sample_normal
(population, k)[source]¶ Choose k unique random elements from a population sequence.
-
utool.experimental.bytecode_optimizations.
test_example
()[source]¶ Example
>>> # DISABLE_DOCTEST >>> from utool.experimental.bytecode_optimizations import * >>> from utool.experimental import bytecode_optimizations as bo >>> dis1 = bo.get_disassembly_string(bo.sample) >>> dis2 = bo.get_disassembly_string(bo.sample_normal) >>> diff = ut.get_textdiff(dis1, dis2) >>> print(diff) >>> if len(diff) == 0: ... print('no difference')