New submission from Peter Williams <pwil3...@bigpond.net.au>:

The built in type() function returns incorrect type names for nested classes 
which in turn causes pickle to crash when used with nested classes as it cannot 
find the nested class definitions from the using the string returned by type().

e.g. if I have an instance "inner" of class Inner which is defined inside 
(nested in) the class Outer:

type(inner) returns <class '__main__.Inner'> instead of <class 
'__main__.Outer.Inner'>

The isinstance() function, as expected, returns True for isinstance(inner, 
Outer.Inner) and raises a NameError exception for isinstance(inner, Inner).

However, isinstance(inner, type(inner)) returns True which indicates the core 
functionality is OK and this conforms to the fact that no problems were 
encountered until I tried to pickle an object containing nested classes.

My system is Fedora 15 x86_64 and Python versions are 2.7.1 and 3.2.

A short program illustrating the problem is attached.

----------
components: None
files: nested_class_bug.py
messages: 139542
nosy: pwil3058
priority: normal
severity: normal
status: open
title: type() returns incorrect type for nested classes
type: crash
versions: Python 2.7, Python 3.2
Added file: http://bugs.python.org/file22531/nested_class_bug.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12457>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to