this post was submitted on 03 Nov 2025
51 points (100.0% liked)

Python

7623 readers
12 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
 

Barry Warsaw, writing for the Python steering council, has announced that PEP 810 ("Explicit lazy imports") has been approved, unanimously, by the four who could vote. Since Pablo Galindo Salgado was one of the PEP authors, he did not vote. The PEP provides a way to defer importing modules until the names defined in a module are needed by other parts of the program. We covered the PEP and the discussion around it a few weeks back. The council also had "recommendations about some of the PEP's details, a few suggestions for filling a couple of small gaps", including:

Use lazy as the keyword. We debated many of the given alternatives (and some we came up with ourselves), and ultimately agreed with the PEP's choice of the lazy keyword. The closest challenger was defer, but once we tried to use that in all the places where the term is visible, we ultimately didn't think it was as good an overall fit. The same was true with all the other alternative keywords we could come up with, so... lazy it is!

What about from foo lazy import bar? Nope! We like that in both module imports and from-imports that the lazy keyword is the first thing on the line. It helps to visually recognize lazy imports of both varieties.

top 7 comments
sorted by: hot top controversial new old
[–] Midnitte@beehaw.org 6 points 1 month ago

Very cool - wonder how this might impact micropython...

[–] GammaGames@beehaw.org 4 points 1 month ago (2 children)
[–] cyrl@lemmy.world 2 points 1 month ago

This is great news, I've never sat down and benchmarked the importing times (I believe theres a python -X switch or similar) but the more options the merrier!

This is the kinda news want to wake up in the morning and be presented with.

[–] onlinepersona@programming.dev 2 points 1 month ago* (last edited 1 month ago) (1 children)

Before reading it: why not make it the default?

I read the PEP and couldn't find why it's a proposal for an explicit keyword only. Probably backwards compatibility, but maybe it'll become the norm.

It wouldn't surprise me if it became a keyword for module local things too like functions. Then it would make declaring a class that uses other classes in read order i.e class A uses class B which uses class C >>> declaration order is A, B, C instead of the current C, B, A.

[–] Michal@programming.dev 7 points 1 month ago (1 children)

Before reading it: why not make it the default?

Because it breaks a lot of things. Whether it's good practice or not, running module code at import time may be expected to initialize some code, setup listeners, build classes etc.

And that's actually what I want much of the time, since I'd rather pay that cost on startup than throughout a running program's life, esp. for heavy dependencies.

So a keyword is great here, since I can balance startup time and hitching during operation.