logoalt Hacker News

maxbondyesterday at 7:41 PM0 repliesview on HN

https://peps.python.org/pep-0810/#what-about-star-imports-fr...

> What about star imports (`from module import *`)?

> Wild card (star) imports cannot be lazy - they remain eager. This is because the set of names being imported cannot be determined without loading the module. Using the lazy keyword with star imports will be a syntax error. If lazy imports are globally enabled, star imports will still be eager.

Additionally, star imports can interfere with type checkers and IDEs and shadowing caused by star imports is a frequent and difficult to diagnose source of bugs (you analyze the function you think you're calling and find no issues, but you're actually calling a different function because the star import occurs after your explicit import).

You might be able to workaround this limitation by doing a lazy import into an intermediate module (a prelude) on a name by name basis and then star import that intermediate module. But personally I solve this problem using IDE features.

https://github.com/python-lsp/python-lsp-server/blob/develop...