Other situations like this (was RE: [Python-Dev] Nested scopes resolution -- you can breathe again!)

Tim Peters tim.one@home.com
Sat, 24 Feb 2001 01:06:30 -0500


[Thomas Wouters]
> ...
> Right, I don't really want them in if/else blocks, you're right.
> Try/except would be nice, though.

Can you give a specific example of why it would be nice?  Since this is a
compile-time gimmick, I can't imagine that it would do anything but confuse
the essential nature of this gimmick.

Note that you *can* do excuciating stuff like:

try:
    import __future__
except:
    import real_old_fangled_code as guacamole
else:
    if hasattr(__future__, "nested_scopes"):
        import new_fangled_code as guacamole
     else:
        import old_fangled_code as guacamole

but in such a case I expect I'd be much happier just keying off
sys.hexversion, or, even better, running a tiny inline test case to *see*
what the semantics are.

[Jeremy]
>> Presumably all versions of Python after and including 2.1 will know
>> about __future__.  In those cases, the compiler will complain if
>> feature is no defined.  The complaint can be fairly specific:
>> "__future__ feature curly_braces is not defined."

[back to Thomas]
> Will this be a warning, or an error/exception ?

A compile-time exception:  when you're asking for semantics the compiler
can't give you, the presumption has to favor that you're in big trouble.
You can't catch such an exception directly in the same module (because it
occurs at compile time), but can catch it if you import the module from
elsewhere.

But I *suspect* you're trying to solve a problem this stuff isn't intended
to address, which is why a specific example would really help.