Reflection Utils

removed

treetensor.utils.reflection.removed(obj)[source]
Overview:

Add __removed__ attribute to the given object. The given object will be marked as removed, will be removed when class_autoremove() or module_autoremove() is used.

Arguments:
  • obj: Given object to be marked.

Returns:
  • marked: Marked object.

class_autoremove

treetensor.utils.reflection.class_autoremove(cls: type) → type[source]
Overview:

Remove the items which are marked as removed in the given cls.

Arguments:
  • cls (type): Given class.

Returns:
  • marked (type): Marked class.

Examples:

>>> @class_autoremove
>>> class MyClass:
>>>     pass

module_autoremove

treetensor.utils.reflection.module_autoremove(module: module)[source]
Overview:

Remove the items which are marked as removed in the given module.

Arguments:
  • module (ModuleType): Given module.

Returns:
  • marked (ModuleType): Marked module.

Examples:

>>> # At the imports' part
>>> import sys
>>>
>>> # At the very bottom of the module
>>> sys.modules[__name__] = module_autoremove(sys.modules[__name__])
>>>