On Thu, 26 Apr 2012 11:31:39 -0700, John Nagle wrote:
> I would suggest that "is" raise ValueError for the ambiguous cases.
> If both operands are immutable, "is" should raise ValueError. That's the
> case where the internal representation of immutables shows through.
You've already made this suggestion before. Unfortunately you failed to
think it through: it would break *nearly all Python code*, and not just
"broken" code. It would break code that relies on documented language
features. It would break code that applies a standard Python idiom. I
count at least 638 places where your suggestion would break the standard
library.
[steve@ando ~]$ cd /usr/local/lib/python3.2/
[steve@ando python3.2]$ grep "if .* is None:" *.py | wc -l
638
That's an average of four breakages per module.
> If this breaks a program, it was broken anyway.
Incorrect. Your suggestion breaks working code for no good reason.
Astonishingly, your suggestion doesn't break code that actually is broken:
def spam(arg=None):
if arg == None:
...
actually is broken, since it doesn't correctly test for the sentinel. You
can break it by passing an object which compares equal to None but isn't
actually None.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list