What is the benefit of using import X as X?

61 Views Asked by At

I know what as keyword does in import statement, we use it to give an object a different name in the module's namespace. It can be its simplified name(like np for numpy) or completely different name that avoids clashes with other names present in the module.

But, I've seen many libraries that give the exact same name to the object like:

from package.module import FOO as FOO

Why? Is it different from: from package.module import FOO ?

couple of examples:

FastAPI:

from .applications import FastAPI as FastAPI

SQLAlchemy:

from .engine import AdaptedConnection as AdaptedConnection

and so many others.

0

There are 0 best solutions below