[Python-Dev] redefining is (original) (raw)
Barry Warsaw barry at python.org
Fri Mar 19 14:48:54 EST 2004
- Previous message: [Python-Dev] redefining is
- Next message: [Python-Dev] redefining is
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, 2004-03-19 at 13:03, Andrew Koenig wrote:
If Tim and Barry are mutable, then an identity test is what they get.
I won't speak for Tim, but my mutability is, er, mutable. :)
I think I know what object equivalence means in a practical sense: It means the same thing as object identity unless both objects are immutable, in which case it is true if and only if the objects have the same type and all of their corresponding attributes are (recursively) equivalent.
I'd be really interested to hear what some of our teachers think about this (not just the definition above, but the whole is-vs-== issue). To me, is vs. == is a very intuitive notion, but I'm wondering if this trips up newbies, and whether something like the above distinction would help.
Understood. The thing is that some people expect expressions such as
"Hello" is "Hello" to yield True under all circumstances, and they don't.
Yep, and I don't mean to downplay that confusion, because teaching why that isn't the correct idiom to use gets into somewhat deep issues. Not identity versus equality, but stuff like interning (what it is and why we have it).
> Maybe we need a 'like' keyword-let to spell equivalence: > > >>> "hello" is like 'hello' > True
Maybe.
Someone other than me will have to write the PEP for this. :)
> PS: 'raise "quit"' doesn't really enter into this for two reasons. > First, string exceptions are going away. Second, there's no 'is' > there. If string exceptions were to stick around, then it might make > sense to redefine the match criteria in terms of object equivalence. > But that's a moot point.
Out of curiosity, why are string exceptions going away? Just to insist that people give explicit types to their exceptions?
Probably, originally, for many of the reasons stated here. That people expected equality tests in the except clause and were tripped up by the identity test performed. I don't remember if changing the except test was ever suggested though.
-Barry
- Previous message: [Python-Dev] redefining is
- Next message: [Python-Dev] redefining is
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]