Are Python's reserved words reserved in places they dont need to be?

Diez B. Roggisch deets at nospam.web.de
Tue Sep 12 10:51:29 EDT 2006


metaperl schrieb:
>   -->  python -i
>>>> class = "algebra"
>   File "<stdin>", line 1
>     class = "algebra"
>           ^
> SyntaxError: invalid syntax
> 
> 
> Why isn' t the parser smart enough to see that class followed by an
> identifier is used for class definition but class followed by equals is
> a simple assignment?
> 
> Also, I had a bug where I tried to set the attributes "user" and "pass"
> in an object but "pass" would not work because it is a reserved word.
> Again pass should be reserved in certain contexts but not others.

Most parsers are written in a way that makes keywords reserved, 
regardless of their occurrence. That is because it is way easier to do 
so. And the few reserved words won't matter usually.

> Is Python 3k going to fix this sort of thing?

Don't think so.

Diez



More information about the Python-list mailing list