top | item 45476941

(no title)

wmichelin | 4 months ago

This seems unnecessary if we can run imports from functions, right? This feels like a layer of indirection and a potential source for confusion. Rather than implicitly importing a library when the variable is first used, why don't you just explicitly do it?

Edit

> A somewhat common way to delay imports is to move the imports into functions (inline imports), but this practice requires more work to implement and maintain, and can be subverted by a single inadvertent top-level import. Additionally, it obfuscates the full set of dependencies for a module. Analysis of the Python standard library shows that approximately 17% of all imports outside tests (nearly 3500 total imports across 730 files) are already placed inside functions or methods specifically to defer their execution. This demonstrates that developers are already manually implementing lazy imports in performance-sensitive code, but doing so requires scattering imports throughout the codebase and makes the full dependency graph harder to understand at a glance.

I think this is a really weak foundation for this language feature. We don't need it.

discuss

order

tremon|4 months ago

On the contrary, I think "everyone is already doing this in their own way, so we will offer it as a language feature, which brings these extra benefits" is one of the stronger arguments for introducing a language feature.

wsve|4 months ago

> Rather than implicitly importing a library when the variable is first used, why don't you just explicitly do it?

I think it's on you to explain why that's a better approach for everyone's use cases instead of this language feature