Message77343
| 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:22 | terry.reedy | set | recipients:
+ terry.reedy |
| 2008年12月08日 21:25:22 | terry.reedy | set | messageid: <1228771522.72.0.688992536212.issue4600@psf.upfronthosting.co.za> |
| 2008年12月08日 21:25:21 | terry.reedy | link | issue4600 messages |
| 2008年12月08日 21:25:20 | terry.reedy | create |
|