On Wed, Mar 17, 2004 at 03:45:32PM -0800, Guido van Rossum wrote: > > It seems to me that 'is' should never be used for immutables except > for singletons like None. Perhaps PyChecker should warn about > inappropriate use of 'is' to compare two immutable objects, unless one > of them is None? There currently is a check for using 'is' or 'is not' with any literal: def f(x): if x is 505: print "don't do that" def g(x): if x is 'xbc': print "don't do that" def h(x): if x is ('xbc',): print "don't do that" def i(x): if x is ['xbc']: print "don't do that" def none_test(x): if x is None: print "ok, fine, do that" def ok(x): a = ['xbc'] if x is a: print "ok, fine, do that" $ checker.py tt.py tt.py:3: Using is 505, may not always work tt.py:6: Using is xbc, may not always work tt.py:9: Using is (Stack Item: (xbc, <type 'str'>, 1),), may not always work tt.py:12: Using is [Stack Item: (xbc, <type 'str'>, 1)], may not always work It's supposed to work with True/False, but there's a bug. That, the print of StackItems, and many more. :-) Neal
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4