Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python typing for module type

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.

like image 870
andrekupka Avatar asked Jan 22 '18 19:01

andrekupka


People also ask

What is the typing module in Python?

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.

Does Python 3.6 support type hints?

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.

What does type () do in Python?

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.

What is types SimpleNamespace?

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.


1 Answers

You're looking for types.ModuleType.

like image 172
Aran-Fey Avatar answered Sep 26 '22 14:09

Aran-Fey