Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: What is the point of `import X as X` where X the same? [duplicate]

In aiohttp I found many statements with import X as X. Why it was done like that?

Link for the file

like image 720
Max Smirnov Avatar asked Dec 07 '25 19:12

Max Smirnov


1 Answers

I did not know the answer, but the history of the linked source file revealed it.

The construct from SOMEWHERE import X as X (with the same X) is required to silence a warning from mypy --strict about not re-exported module. AFAIK, adding the as X to import X has no effect to the program itself.

mypy is an optional static type analyzer and apparently the developers decided to use it and to use it in the strict mode.

like image 77
VPfB Avatar answered Dec 11 '25 13:12

VPfB