I am dynamically loading a Python module using importlib.import_module
as follows
def load_module(mod_name: str) -> ???: return importlib.import_module(mod_name)
Can somebody tell me what is the correct type annotation for a module type. The typing
module does not contain one and I could not find an answer elsewhere.
The typing module provides us with Type Aliases, which is defined by assigning a type to the alias. In the above snippet, Vector is an alias, which stands for a list of floating point values. We can type hint at an alias, which is what the above program is doing.
This module supports type hints as specified by PEP 484 and PEP 526. The most fundamental support consists of the types Any , Union , Tuple , Callable , TypeVar , and Generic . For full specification please see PEP 484. For a simplified introduction to type hints see PEP 483.
Syntax of the Python type() function The type() function is used to get the type of an object. When a single argument is passed to the type() function, it returns the type of the object. Its value is the same as the object.
class types. SimpleNamespace. A simple object subclass that provides attribute access to its namespace, as well as a meaningful repr. Unlike object , with SimpleNamespace you can add and remove attributes.
You're looking for types.ModuleType
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With