Message358501
> 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. |
|
Date |
User |
Action |
Args |
2019-12-16 18:21:37 | vstinner | set | recipients:
+ vstinner, pablogsal |
2019-12-16 18:21:37 | vstinner | set | messageid: <1576520497.37.0.933885521556.issue39069@roundup.psfhosted.org> |
2019-12-16 18:21:37 | vstinner | link | issue39069 messages |
2019-12-16 18:21:37 | vstinner | create | |
|