On Sun, Apr 10, 2022 at 2:31 AM Daniel Pope <lord.mauve@gmail.com> wrote:
On Fri, 8 Apr 2022, 17:44 Guido van Rossum, <guido@python.org> wrote:
The interesting idea here seems to make "lazy imports" easier to implement by making them explicit in the code. So far, most lazy import frameworks for Python have done hacks with `__getattribute__` overrides. 

The value is more than ease of implementation. Having syntax for import expressions makes them statically analysable, which is needed for type checkers and IDE autocompletion.

This has been brought up a few times and I don't get it. Currently a use of an imported module is perfectly analyzable by all the static type checkers I know of (e.g. mypy, Pyre, pyright). For the static analyzer it makes no difference if I have

import re
.
.
.
def foo(x):
    if re.match(r"blah", x): ...

or the hypothetical inline form:

def foo(x):
    if @re.match(r"blah", x): ...
 
But I also see value in being able to type out code that uses modules not yet imported without breaking my flow to add an import statement. I don't yet trust IDEs to do this because I've been bitten by them doing so incorrectly in the past.

I have too.

--
--Guido van Rossum (python.org/~guido)