[Python-ideas] P3k __builtins__ identifiers -> warning

Guido van Rossum guido at python.org
Tue Nov 27 19:43:47 CET 2007


IMO this is a task for tools llike pylint or pychecker (both of which
flag this).

Also, it's controversial -- especially since you're unlikely to want
to use a builtin whose name you can't remember. :-) The builtins were
not made keywords for a reason.

--Guido

On Nov 27, 2007 12:31 AM, Mark Summerfield <mark at qtrac.eu> wrote:
> Here is a nice little Python 3 program, test.py:
>
>     import string
>     buffer = string.ascii_letters
>     bytes = []
>     sum = 0
>     for chr in buffer:
>         int = ord(chr)
>         if 32 <= int < 127:
>             bytes.append(chr)
>             sum += 1
>     str = "".join(bytes)
>     print(sum, str)
>
> If run as:
>
>     python30a -W all test.py
>
> It produces the expected output:
>
>     52 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
>
> But unfortunately it uses as identifiers: buffer, bytes, chr, int, sum,
> and str. None of these are keywords so none of them provokes a
> SyntaxError. In fact there are over 130 such identifiers;
> print(dir(__builtins__)) to see them.
>
> I think many newcomers to Python will find it difficult to remember 160
> identifiers (keywords + __builtins__) and since some of them have
> appealing names (esp. buffer, bytes, min, max, and sum), they may make
> use of them without realising that this could cause them problems later
> on.
>
> My python-idea is that if python is run with -W all then it should
> report uses of __builtins__ as identifiers.
>
> --
> Mark Summerfield, Qtrac Ltd., www.qtrac.eu
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list