[Python-ideas] P3k __builtins__ identifiers -> warning

Mark Summerfield mark at qtrac.eu
Tue Nov 27 09:31:04 CET 2007


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





More information about the Python-ideas mailing list