Module that implements the New Import Hooks’ PEP0302.
-
class
bredala.modulehacker.
BredalaMetaImportHook
[source]¶ A class that import a module like normal and then passed to a hacker object that gets to do whatever it wants to the module. Then the return value from the hack call is put into sys.modules.
-
find_module
(name, path=None)[source]¶ This method is called by Python if this class is on sys.path. ‘name’ is the fully-qualified name of the module to look for, and ‘path’ is either __path__ (for submodules and subpackages) or None (for a top-level module/package).
Note that this method will be called every time an import statement is detected (or __import__ is called), before Python’s built-in package/module-finding code kicks in.
-
-
bredala.modulehacker.
itype
(module, name, input_types, decorator=<function inputs>)[source]¶ Function to register a decorator to type inputs.
Parameters: module: str (mandatory)
a module name whose functions will be decorated.
name: str ((mandatory)
a function or a method we want to decorate.
input_types: tuple of types (mandatory)
the decorate function input types.
decorator: callable (optional, default @inputs)
a decorator function.
-
bredala.modulehacker.
otype
(module, name, output_types, decorator=<function returns>)[source]¶ Function to register a decorator to type outputs.
Parameters: module: str (mandatory)
a module name whose functions will be decorated.
name: str ((mandatory)
a function or a method we want to decorate.
output_types: tuple of types (mandatory)
the decorate function returned types.
decorator: callable (optional, default @returns)
a decorator function.
-
bredala.modulehacker.
register
(module, decorator=<function bredala_signature>, names=None, decorator_type='signature', **kwargs)[source]¶ Function to register a decorator for a list of module names.
Parameters: module: str (mandatory)
a module name whose functions will be decorated.
decorator: callable (optional, default @bredala_signature)
a decorator function.
names: list of str (optional, default None)
a list of function or methods we want to decorate, if None all the module functions or methods will be decorated.
decorator_type: str
the decorator type. Supported values are ‘signature’, ‘inputs’ and ‘outputs’.
kwargs: dict (optional)
extra arguments used during the dynamic decorations: ‘istype’ and ‘types’.