Troy Curtis Jr wrote on Sun, 11 Feb 2018 14:27 +0000:
> All this being said, I'm fine reverting the import swap if that is what is
> desired, as all indications are that it works either way now. I simply
> liked the communication of intent better with this order.
I think the primary reason for the 'try: import py3name...' convention
is to make the code a little faster in the common case, which is
presumed to be the newer language version. I'm not sure whether the
difference is significant enough to be worth the churn of another commit
unchanging the order. It certainly isn't significant enough to block the
backport (the bugfix outweighs it by orders of magnitude).
I'm not sure I understand exactly in what way you see the order in HEAD
as better. As I see it, the code wants to import the module that's
known as '__builtin__' on py2 and 'builtins' on py3 because it wants to
call <that module>.open(), an alias of the builtin open() function. I
don't think the code should care whether "import builtins" succeeds
because it runs under py3 or under py2+future, so long as "import
builtins" results in locals()['builtins'] having the semantics it would
have under py3. I view this as a form of duck typing.
This may be an academic question, of course; the important thing is that
the patch is committed so trunk now works with and without future
installed.
Cheers,
Daniel
Received on 2018-02-11 23:29:35 CET