kwcoco.util.util_monkey module¶
- class kwcoco.util.util_monkey.SupressPrint(*mods, **kw)[source]¶
Bases:
object
Temporarily replace the print function in a module with a noop
- Parameters
*mods – the modules to disable print in
**kw – only accepts “enabled” enabled (bool, default=True): enables or disables this context
- class kwcoco.util.util_monkey.Reloadable[source]¶
Bases:
type
This is a metaclass that overrides the behavior of isinstance and issubclass when invoked on classes derived from this such that they only check that the module and class names agree, which are preserved through module reloads, whereas class instances are not.
This is useful for interactive develoment, but should be removed in production.
Example
>>> from kwcoco.util.util_monkey import * # NOQA >>> # Illustrate what happens with a reload when using this utility >>> # versus without it. >>> class Base1: >>> ... >>> class Derived1(Base1): >>> ... >>> @Reloadable.add_metaclass >>> class Base2: >>> ... >>> class Derived2(Base2): >>> ... >>> inst1 = Derived1() >>> inst2 = Derived2() >>> assert isinstance(inst1, Derived1) >>> assert isinstance(inst2, Derived2) >>> # Simulate reload >>> class Base1: >>> ... >>> class Derived1(Base1): >>> ... >>> @Reloadable.add_metaclass >>> class Base2: >>> ... >>> class Derived2(Base2): >>> ... >>> assert not isinstance(inst1, Derived1) >>> assert isinstance(inst2, Derived2)