mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
In load_inst(), when instantiating an instance the old way (i.e. when
there's an __getinitargs__() method), if a TypeError occurs, catch and reraise it but add info to the error about the class name being instantiated. This makes debugging a lot easier if __getinitargs__() returns something bogus (e.g. a string instead of a singleton tuple).
This commit is contained in:
parent
0c92000b7a
commit
743d17e3aa
1 changed files with 7 additions and 4 deletions
|
@ -23,11 +23,11 @@ Misc variables:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "1.9" # Code version
|
__version__ = "$Revision$" # Code version
|
||||||
|
|
||||||
from types import *
|
from types import *
|
||||||
from copy_reg import dispatch_table, safe_constructors
|
from copy_reg import dispatch_table, safe_constructors
|
||||||
import string, marshal
|
import string, marshal, sys
|
||||||
|
|
||||||
format_version = "1.2" # File format version we write
|
format_version = "1.2" # File format version we write
|
||||||
compatible_formats = ["1.0", "1.1"] # Old format versions we can read
|
compatible_formats = ["1.0", "1.1"] # Old format versions we can read
|
||||||
|
@ -465,7 +465,6 @@ def whichmodule(cls, clsname):
|
||||||
"""
|
"""
|
||||||
if classmap.has_key(cls):
|
if classmap.has_key(cls):
|
||||||
return classmap[cls]
|
return classmap[cls]
|
||||||
import sys
|
|
||||||
|
|
||||||
for name, module in sys.modules.items():
|
for name, module in sys.modules.items():
|
||||||
if name != '__main__' and \
|
if name != '__main__' and \
|
||||||
|
@ -620,7 +619,11 @@ class Unpickler:
|
||||||
# prohibited
|
# prohibited
|
||||||
pass
|
pass
|
||||||
if not instantiated:
|
if not instantiated:
|
||||||
|
try:
|
||||||
value = apply(klass, args)
|
value = apply(klass, args)
|
||||||
|
except TypeError, err:
|
||||||
|
raise TypeError, "in constructor for %s: %s" % (
|
||||||
|
klass.__name__, str(err)), sys.exc_info()[2]
|
||||||
self.append(value)
|
self.append(value)
|
||||||
dispatch[INST] = load_inst
|
dispatch[INST] = load_inst
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue