Almost keywords
Duncan Booth
duncan.booth at invalid.invalid
Mon Jul 21 13:59:22 EDT 2008
bearophileHUGS at lycos.com wrote:
> A possible way to avoid such bugs is to turn all those names like
> "list", "map", "filter", "self", etc into keywords. But this may have
> some disadvantages (well, I think I'd like to have "self" as keyword,
> seen how all Python books strong suggest to not use a name different
> from "self").
I'm not convinced by making 'self' a keyword. Forcing the first argument of
a method to be named 'self' fails for many reasons (e.g.
classmethod/staticmethod) so I don't really see a benefit to making it
special in any way.
For the other names though, this would have the advantage of allowing the
compiler to optimise access to builtins which should provide a slight speed
improvement and I think would also make life easier for some
implementations (especially things like 'locals()').
A half-way house would be to generate a warning for any use of a name which
masks one of the reserved builtins, but only optimise lookups in scopes
where no such masking is seen by the compiler: this would prevent you
overriding builtins by injecting a name into the global namespace from
outside a module but not otherwise break existing code.
Of course any of this would break some existing code and therefore isn't
going to happen.
More information about the Python-list
mailing list