Hmm, checking my code, you are right, the idiom I was actually using (in one very old module still in my codebase, and which still works ;) ) was (paraphrased): NULL = (1,) # why doesn't () work? Get with it Guido ;) As for cheating... no, actually, I didn't feel guilty, I was thinking of () and [] as being calls to constructors which returned shiny new tuple and/or list objects (with the contents being arguments to those constructors). I've learned a lot since then; now I know that the list gnomes and the tuple fairies sneak in and replace the bracket characters with billows of cotton candy. Problems arise when the cotton candy is soaked by over optimisation by the evil language wizards, though I discovered that the resulting solution is quite tasty when carbonated. In some weird way, I like the is statement. It appears in thousands of places throughout my code. I check object identity far more often than object equivalence, as many of my libraries, in order to do a decent equality check might have to do a recursive search through thousands of nodes (and since they can have references to their parents, the equality becomes quite ugly). Still, carbonation makes it all quite palatable. Just because something is explicitly forbidden, goes against all laws of nature, offends half the population, destroys one's life and family, and casts one into the deepest pits of Tartarus doesn't necessarily mean that thing should be avoided... Or so I tell myself... Mike PS: Pointing out that it's in a document with the official disclaimer: "for language lawyers" , is like pointing out ''There's no point in acting all surprised about it. All the planning charts and demolition orders have been on display in your local planning department on Alpha Centauri for fifty of your Earth years, so you've had plenty of time to lodge any formal complaint and it's far too late to start making a fuss about it now.'' ;) -----Original Message----- From: Tim Peters [mailto:tim.one at home.com] Sent: Wednesday, April 18, 2001 03:51 To: Python List (E-mail) Subject: RE: Idiom gone, or did it really ever exist? () is () ... It has never worked by design. It stopped working by accident when Guido added empty-tuple caching in revision 2.9 of tupleobject.c. He did that in October of 1993. Have you been in a time warp <wink>? Any code relying on unique object identity for literals of any object of any immutable type is simply wrong. The language doesn't guarantee anything here, and the implementation can & does vary across releases, or even bugfixes. The Reference Manual has always said (section "Objects, values and types"): ... I don't know what accounts for this. Do users not understand how object identity works in Python, or are they so fanatically devoted to tricks that they're willing to chance it despite knowing it isn't safe? 'Fess up, Mike: my bet is that when you *started* using this trick, you knew you were cheating. ... More generally, people using "is" without knowing what they're doing should simply stop using it, tuples or not. How to tell if you're one of them: if when you use "is", you feel a twinge of pride in being clever <0.5 wink>. Safe (intended, documented and supported) uses for "is" are dull as dog food. ...
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