[Tim Peters] > >> Type objects are also singletons (e.g., type(True) returns the same > >> object as type(False); ditto type("True") and type("False") and > >> type("xyz"); etc). > [Guido] > > But types are not immutable, so their semantics are different anyway. > I never thought of type objects as being mutable [...] I'm not sure of the meaning of "immutability of a type". Looking around, I found out this other message from Guido (quoted in its entirety in case the context changes the wanted meaning of words): ----------------------------------------------------------------------> From: Guido van Rossum <guido at python.org> Date: Thu, 18 Oct 2001 21:00:28 GMT Subject: Re: hashval and Numpy To: python-list at python.org Newsgroups: comp.lang.python > Michael Hudson <mwh at python.net> wrote: > > |>>> a = Numeric.array([1,2]) > |>>> hash(a) > | 56 > |>>> d = {a:1} # a will be in the 56%8-th slot (in 2.2, anyway) > |>>> a[0] = 2 > |>>> hash(a) > | 57 > |>>> d[a] # looks in 57%8-th slot - which is empty > | KeyError > |>>> b = Numeric.array([1,2]) > |>>> hash(b) > | 56 > |>>> d[b] # looks in 56%8-th slot - but what's there is not __eq__ to b! > | KeyError > > | Moral: don't use mutable objects as dictionary keys. Hm. The Numeric.array object should not have defined __hash__ or tp_hash. It's wrong if a mutable object defines a hash function, for exactly this reason. ----------------------------------------------------------------------< However, all types derive from object, and object has `__hash__'. Consequently, I would be tempted to think that under the new system, everything deriving from object is immutable by construction, unless tricks are used against it, like maybe, an intermediate class overriding `__hash__' with some function with the specific goal of raising an exception. Is that so? What means a "mutable type" then?
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