New submission from Terry J. Reedy <[EMAIL PROTECTED]>: 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. ---------- components: Interpreter Core messages: 77343 nosy: tjreedy severity: normal status: open title: __class__ assignment: new-style? heap? == confusing type: behavior versions: Python 3.0 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4600> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com