[Python-ideas] Making it easy to prepare for PEP479

MRAB python at mrabarnett.plus.com
Tue May 19 02:32:33 CEST 2015


On 2015-05-19 01:22, Chris Angelico wrote:
> On Tue, May 19, 2015 at 9:06 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> Steven D'Aprano wrote:
>>>
>>> After all, I might want to write:
>>>
>>> if sys.version != '3.7' and
>>> read_config('config.ini')['allow_jabberwocky']:
>>>     from __future__ import jabberwocky
>>
>>
>> You might want to, but I would have no qualms about
>> firmly telling you that you can't. Putting try:
>> in front of a future import still doesn't introduce
>> any executable code before it, whereas the above does.
>
> Yes, but imagine what happens if you want to have _two_ future imports
> guarded by try/except. Either something gets completely special-cased
> ("try: from __future__ import foo except: pass", and no other
> except/finally permitted), or you're allowed a maximum of one guarded
> future import (though it might have more than one keyword in it), or
> there's arbitrary code permitted in the "except" clause prior to a
> future import, which would be a major problem.
>
I think that part of the problem is that it looks like an import
statement, but it's really a compiler directive in disguise...



More information about the Python-ideas mailing list