This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients terry.reedy
Date 2008-12-08.21:25:19
SpamBayes Score 9.320502e-10
Marked as misclassified No
Message-id <1228771522.72.0.688992536212.issue4600@psf.upfronthosting.co.za>
In-reply-to
Content
ob.__class__ = ob2
gives some confusing TypeError messages.

>>> c.__class__ = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __class__ must be set to new-style class, not 'int' object

Problem: 'new-style' is obsolete in 3.0. It is also too inclusive...

>>> c.__class__ = object
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __class__ assignment: only for heap types

object *is* 'new-style'.  I presume 'heap type' means 'class defined by
class statement'.  If so, let us say so, since beginning programmers may
not know what a 'heap type' is.  If the above is incorrect, then this
experienced programmer also does not know what it means in Python
context ;-).

Proposal: when someone tries to set __class__ to an inappropriate
object, give similar error message for instances and heap classes.

TypeError: __class__ must be set to a class defined by a class
statement, not 'xxx' [object].

where 'object', without the brackets, is added for non-classes, as it is
today.

>>> c.__class__ = object
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __class__ assignment: only for heap types

C, the class of c, *is* a heap type.  The different problem, the target
being an instance of heap class, should get a different message.  'Heap'
is still possibly confusing. Proposal:

TypeError: __class__ assignment: only for instances of classes defined
by class statements.
History
Date User Action Args
2008-12-08 21:25:22terry.reedysetrecipients: + terry.reedy
2008-12-08 21:25:22terry.reedysetmessageid: <1228771522.72.0.688992536212.issue4600@psf.upfronthosting.co.za>
2008-12-08 21:25:21terry.reedylinkissue4600 messages
2008-12-08 21:25:20terry.reedycreate