[issue12457] type() returns incorrect type for nested classes

Peter Williams report at bugs.python.org
Sat Jul 2 02:26:24 CEST 2011


Peter Williams <pwil3058 at bigpond.net.au> added the comment:

The class I was pickling was a top level class but a field inside that class had an instance of a nested class set as its value.  The error message produced indicated that the reason for failure was the inability of pickle to find the class definition and (I think) that was caused by the problem with type()'s returned value.

Perhaps fixing the problem with type() would allow the restriction on pickling nested classes to be removed?  Was that restriction a deliberate design decision (illogical) or the result of not being able to get it to work?

Re whether the behaviour of type() is a problem:  I believe it is as, in addition to the inconsistencies between type() and isinstance() that I described in my original report, there is the confusion that arises if two separate classes have nested classes with the same name (see mini program confusion.py as an example).  This seems to compromise the whole purpose of namespaces and is inconsistent with the way modules are treated in determining the name reported by type().

----------
type: behavior -> crash
Added file: http://bugs.python.org/file22544/confusion.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12457>
_______________________________________


More information about the Python-bugs-list mailing list