"as" keyword woes

Mensanator mensanator at aol.com
Wed Dec 3 19:08:23 EST 2008


On Dec 3, 4:38 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Wed, 03 Dec 2008 22:02:24 +0000, Martin P. Hellwig wrote:
> > Warren DeLano wrote:
> >> A bottom line / pragmatic question... hopefully not a FAQ.
>
> >> Why was it necessary to make "as" a reserved keyword?
> > <cut>
> > Because it can be used at the import statement to let the imported thing
> > be known under another name?
> > Something like:
>
> >  >>> import xml.etree.ElementTree as ET
>
> Martin, that doesn't answer the OP's question *at all*. Python 2.5 uses
> "as" in that way, and it is not a keyword.
>
> >>> import math as MATHS
> >>> MATHS
>
> <module 'math' from '/usr/lib/python2.5/lib-dynload/mathmodule.so'>>>> as = 45
>
> <stdin>:1: Warning: 'as' will become a reserved keyword in Python 2.6>>> as
>
> <stdin>:1: Warning: 'as' will become a reserved keyword in Python 2.6
> 45
>
> I'd guess that the change was to simplify the CPython parser. I have no
> idea if it was a tiny change or a significant change, if it made a huge
> difference to Python-dev or a little difference. Perhaps someone on the
> dev team could comment.
>
> While I feel sympathy for the OP, I do have to ask: he's been using
> Python 2.5 for, what, a couple of years now? How many times did he see
> the depreciation warning, and almost certainly the pending depreciation
> warning before that? Python-dev has been talking about making "as" a
> keyword since at least Python 2.3. Why wait until after version 2.6 is
> released before saying anything?

When I brought this up a short while ago (because sympy crashed in
Python 2.6) someone said that there was a bug in Python 2.5 that
prevented the display of the deprecation message (when "as" appeared
inside imported modules).

So apparently, the sympy developers never saw a deprecation warning
in all the years they were using 2.5. There was, however, no excuse
for not testing it in 2.6.

>
> --
> Steven




More information about the Python-list mailing list