On 10/25/2010 12:56 PM, John Nagle wrote:
On 10/25/2010 7:38 AM, Tim Chase wrote:
While a dirty hack for which I'd tend to smack anybody who used it...you
*can* assign to instance.__class__

     That's an implementation detail of CPython.  May not work in
IronPython, Unladen Swallow, PyPy, or Shed Skin.

Curious by your claim, could you confirm this someplace in the docs? From my reading of [1]'s "If x is an instance of a new-style class, then type(x) is typically the same as x.__class__ (although this is not guaranteed - a new-style class instance is permitted to override the value returned for x.__class__)" is that this can be overridden (the definition of "overridden" however may mean different things to different people) and [2] refers to "__class__ assignment works only if both classes have the same __slots__" (that seems pretty clear that __class__ assignment is permissible)

-tkc


[1]
http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes

[2]
http://docs.python.org/reference/datamodel.html#__slots__





--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to