STINNER Victor <[email protected]> added the comment:
> Lazy import
IMHO moving unparse code to a new _ast_unparse module, and use
ast.__getattr__() to lazily import it and bind it as the ast.unparse() function
is the best option, since __getattr__() alone is enough to implement the
laziness and it should be simple, something like:
def __getattr__(name):
if name == 'unparse':
import _ast_unparse
globals()['unpase'] = _ast_unparse.unparse
return _ast_unparse.unparse
else:
raise AttributeError
I never used a module __getattr__().
So _ast_unparse could use any super slow but cool Python feature, without
having to use dirty hacks to make the code lazy.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue39069>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com