On Wed, 2 Dec 2020 02:39:38 +1100 Chris Angelico firstname.lastname@example.org wrote:
On Wed, Dec 2, 2020 at 2:29 AM Paul Sokolovsky email@example.com wrote:
def fun(): # Imports are not allowed at run-time import mod2 # But you can re-import module previously imported at import-time. import mod
Then it's luck that ALL versions and dialects of Python aren't under your control ;-).
system, including the ability for a module to be imported only when it's actually needed. Imports inside functions allow a program to have optional dependencies, or dependencies that might be slow to load (eg numpy), and without that, even running your script with "--help" has to process every single import in the entire file.
But didn't you you already spotted a line which says that the strict mode also aspires to improve on the Python module practices? Under strict mode's firm but benevolent rule, there won't be slowly-loading modules any more. All imports will be fast. And modules which want to be slow will do that in their module.init() function.
I also forgot to mention very important point in the intro: when you read this proposal, please don't think about "CPython". That for sure will send you the wrong vibes. Think about "Python". ;-)