(me): >> There is an idiom (I've seen it more in Lisp than in python) >> of creating a fresh object to act as a sentinel. Greg Ewing: > In those rare cases where None is also a legitimate value, it's not > hard to manufacture some unique object and test for it with 'is'. You > just have to remember that strings and integers are not necessarily > unique, which I don't think is too hard to keep in mind. That is the (occasionally surprising) state today. Since there is no intention of ever actually mutating the object, it is common (if mistaken) to assume that any new object -- even an immutable -- should work. If we changed "is", it would be even more difficult to create a guaranteed unique object. Fortunately, Guido rejected the wholesale change. I'm still a bit worried about a comment (which I can no longer find) suggesting a change for {}, so that >>> {} is {} True I don't see this in 2.3, and would be very surprised (and disappointed) if it started to happen in 2.4, precisely because dictionaries are mutable objects that should work. Even worse, >>> [] is [] False was the recommended idiom; the difference between [] and {} as unique objects is far from clear. I personally like (and have used) Barry's suggestion of a new named object(). Unfortunately, object() is longer to type, not as backwards compatible, and places too emphasis on what the sentinel *is* rather than what is *isn't*. -jJ
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