[Python-Dev] ACCEPTED: PEP 285
Delaney, Timothy
tdelaney at avaya.com
Wed Apr 3 18:48:25 EST 2002
> From: Neal Norwitz [mailto:neal at metaslash.com]
>
> This code:
> True = 1
> False = 0
>
> def test(a):
> if a is True: print 'True'
> if a == False: print 'False'
>
> generates these warnings:
> test.py:2: Should not assign to True, it is (or will
> be) a builtin
> test.py:3: Should not assign to False, it is (or will
> be) a builtin
> test.py:6: Comparisions with True are not necessary
> test.py:7: Comparisions with False are not necessary
I would change that to ...
# only generated in Python 2.3 or higher
test.py:2: Should not assign to True, it is a builtin
test.py:3: Should not assign to False, it is a builtin
# only generated in Python 2.3 or higher,
# or if there are constants in scope with the names
# 'TRUE', 'FALSE', 'True', 'False', 'true', 'false'
# and the appropriate name should be included in the
# warning.
test.py:6: Comparisons with [TRUE|True|true] may give incorrect results
^ extra i ;)
test.py:7: Comparisons with [FALSE|False|false] may give incorrect results
^ extra i ;)
and would also add a warning for code in 2.3+ for code like
TRUE = <something>
FALSE = <something>
true = <something>
false = <something>
test.py:2: TRUE appears to be a boolean constant - builtin True should be
used.
test.py:3: FALSE appears to be a boolean constant - builtin False should be
used.
test.py:4: true appears to be a boolean constant - builtin True should be
used.
test.py:5: false appears to be a boolean constant - builtin False should be
used.
Tim Delaney
More information about the Python-list
mailing list