[Matrix-SIG] Re: Bug in generating .pyc files!!!

Tim Peters tim_one@email.msn.com
Mon, 1 Nov 1999 23:18:55 -0500


[David Ascher, whittles down Pearu Peterson's "bug", which boils down
 to the unpredictability of "is" when applied to strings]

[PP]
> I think this is a serious problem and should be fixed.

[DA]
> I agree.  FWIW, IMO the right thing to do is to have the test return false
> all the time, but I agree that there should not be a dependence on
> byte-compilation.
>
> Guido?

Since he doesn't seem to be around, I'll channel him <wink>.  "is" tests
object identity, and so exposes accidents of the implementation if used in
ill-advised ways.  For immutable objects (like strings!) in particular, the
implementation is free to reuse them *or* copy them at will, and whether
e.g.

    "this works?"[-1] is "?"

returns true can vary from release to release, platform to platform, or even
from run to run.

OTOH, constructors for *mutable* objects always create fresh objects, so

    [] is []

is guaranteed to return false everywhere.  About the only guarantee you get
for immutable objects is that

    x is y

will return true if it follows

    x = y

and neither name is rebound between them.  If x and y are *computed*
immutable values, nothing can be said a priori about the result of "x is y",
beyond that x != y implies x is not y.

IOW, the bug here was the use of "is" to begin with; object identity was
simply not what the program intended to test.

can't-remove-the-bug-without-removing-the-feature-too-ly y'rs  - tim