This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients pablogsal, vstinner
Date 2019-12-16.18:21:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576520497.37.0.933885521556.issue39069@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2019-12-16 18:21:37vstinnersetrecipients: + vstinner, pablogsal
2019-12-16 18:21:37vstinnersetmessageid: <1576520497.37.0.933885521556.issue39069@roundup.psfhosted.org>
2019-12-16 18:21:37vstinnerlinkissue39069 messages
2019-12-16 18:21:37vstinnercreate