Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Lazy Import is not default in Python?

Tags:

python

I am trying to understand few things with respect to design.

I see a number of the code where Lazy Import features is used.By Lazy Import, I mean a facility provided by certain recipes, packages and modules which support "LazyImport" style. Those implementation in general aim to import the module only when it is used and provide some extra hooks for different things. I know there the error condition is delayed over here, but I am trying to understand why Lazy Import is not a default strategy in Python.

What could it's (other) drawbacks be which prevent it from making a general useful case. Or are there languages which use this as a default import mechanism strategy.

like image 655
Senthil Kumaran Avatar asked Feb 03 '23 06:02

Senthil Kumaran


1 Answers

Python, unlike e.g. PHP, is rarely used in a way where every request/action/... causes the whole application to be started again.
So importing everything at startup has the advantage of not having to perform imports while the application is doing something where delays are annoying.
The only advantage of local/lazy imports is that you won't have problems with circular imports.

like image 106
ThiefMaster Avatar answered Feb 12 '23 01:02

ThiefMaster