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 BTaskaya
Recipients BTaskaya, gvanrossum, pablogsal, vstinner
Date 2019-12-16.21:36:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CANDBV65tQNuW-3P2Z_xZUWXLnPooGdXOQ=UXqRUJXQtsSZDa9g@mail.gmail.com>
In-reply-to <1576531884.1.0.739316350068.issue39069@roundup.psfhosted.org>
Content
Thanks for having consensus on this. I'll refactor PR 17612 and open
anothor one for reverting PR 17376

On Tue, Dec 17, 2019, 12:31 AM STINNER Victor <report@bugs.python.org>
wrote:

>
> STINNER Victor <vstinner@python.org> added the comment:
>
> Pablo:
> > Victor, are you OK if we close this issue and just use the desired
> imports directly in the PRs for issue 38870?
>
> Yes.
>
> --
>
> *I* don't care of "import ast" performance, since I don't expect it to be
> commonly used by command line applications. I don't know the story of the
> revert, but it seems like you don't bother much anymore.
>
> If tomorrow using "functools" and "enum" becomes a performance bottleneck
> (for import time), maybe we should try to optimize imports and optimize
> these modules instead?
>
> I opened this issue because I would like to use these modules in ast. I'm
> unhappy with the current proposed implementation:
> ---
>
>     class _NoDelimit:
>         def __enter__(self): pass
>         def __exit__(self, *args): pass
>
>     class _Delimit:
>         """A context manager for preparing the source for expressions. It
> adds
>         start of the delimiter  and enters, after exit it adds delimiter
> end."""
>         def __init__(self, unparser, delimiter):
>             self.unparser = unparser
>             self.delimiter = delimiter
>         def __enter__(self):
>             self.unparser.write(self.delimiter[0])
>         def __exit__(self, exc_type, exc_value, traceback):
>             self.unparser.write(self.delimiter[-1])
>
>     def delimit_if(self, condition, delimiter):
>         if condition:
>             return self._Delimit(self, delimiter)
>         else:
>             return self._NoDelimit()
> ---
>
> Having to define two classes just to call the write() method seems
> overkill to me.
>
> Same remark for the pseudo enum in PR 17377:
> ---
>     PRECEDENCE_LEVELS = {
>         "PR_TUPLE": 0,
>         "PR_YIELD": 1,
>         "PR_TEST": 2,
>         "PR_OR": 3,
>         "PR_AND": 4,
>         "PR_NOT": 5,
>         "PR_CMP": 6,
>         "PR_EXPR": 7,
>         "PR_BOR": 7,
>         "PR_BXOR": 8,
>         "PR_BAND": 9,
>         "PR_SHIFT": 10,
>         "PR_ARITH": 11,
>         "PR_TERM": 12,
>         "PR_FACTOR": 13,
>         "PR_POWER": 14,
>         "PR_AWAIT": 15,
>         "PR_ATOM": 16,
>     }
> ---
>
> It's too easy to introduce a duplicated constant with such construction.
> The enum module is designed to define unique constants.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue39069>
> _______________________________________
>
History
Date User Action Args
2019-12-16 21:36:22BTaskayasetrecipients: + BTaskaya, gvanrossum, vstinner, pablogsal
2019-12-16 21:36:22BTaskayalinkissue39069 messages
2019-12-16 21:36:22BTaskayacreate