Permalink
Browse files

Improving pydevd_reload.

  • Loading branch information...
1 parent 0091a24 commit 4e1679f1bc6cbe6b79ecc5bf9d193f5d7cc44dec @fabioz committed Jan 17, 2014
@@ -55,11 +55,11 @@
"""
import imp
+import traceback
import sys
import types
from pydev_imports import Exec
import pydevd_dont_trace
-import traceback
NO_DEBUG = 0
LEVEL1 = 1
@@ -181,7 +181,7 @@ def apply(self):
# Now we get to the hard part
oldnames = set(modns)
newnames = set(new_namespace)
-
+
# Update in-place what we can
for name in oldnames & newnames:
self._update(modns[name], new_namespace[name])
@@ -207,45 +207,48 @@ def _update(self, oldobj, newobj):
oldobj: the object to be updated
newobj: the object used as the source for the update
"""
- Helper.info2('Updating: ', oldobj)
- if oldobj is newobj:
- # Probably something imported
- return newobj
-
- if type(oldobj) is not type(newobj):
- # Cop-out: if the type changed, give up
+ try:
+ Helper.info2('Updating: ', oldobj)
+ if oldobj is newobj:
+ # Probably something imported
+ return newobj
+
+ if type(oldobj) is not type(newobj):
+ # Cop-out: if the type changed, give up
+ return newobj
+
+ if hasattr(newobj, "__reload_update__"):
+ # Provide a hook for updating
+ return newobj.__reload_update__(oldobj)
+
+ if isinstance(newobj, types.FunctionType):
+ return self._update_function(oldobj, newobj)
+
+ if isinstance(newobj, types.MethodType):
+ return self._update_method(oldobj, newobj)
+
+ if isinstance(newobj, classmethod):
+ return self._update_classmethod(oldobj, newobj)
+
+ if isinstance(newobj, staticmethod):
+ return self._update_staticmethod(oldobj, newobj)
+
+ if hasattr(types, 'ClassType'):
+ classtype = (types.ClassType, type) #object is not instance of types.ClassType.
+ else:
+ classtype = type
+
+ if isinstance(newobj, classtype):
+ return self._update_class(oldobj, newobj)
+
+ # New: dealing with metaclasses.
+ if hasattr(newobj, '__metaclass__') and hasattr(newobj, '__class__') and newobj.__metaclass__ == newobj.__class__:
+ return self._update_class(oldobj, newobj)
+
+ # Not something we recognize, just give up
return newobj
-
- if hasattr(newobj, "__reload_update__"):
- # Provide a hook for updating
- return newobj.__reload_update__(oldobj)
-
- if hasattr(types, 'ClassType'):
- classtype = types.ClassType
- else:
- classtype = type
-
- if isinstance(newobj, classtype):
- return self._update_class(oldobj, newobj)
-
- if isinstance(newobj, types.FunctionType):
- return self._update_function(oldobj, newobj)
-
- if isinstance(newobj, types.MethodType):
- return self._update_method(oldobj, newobj)
-
- if isinstance(newobj, classmethod):
- return self._update_classmethod(oldobj, newobj)
-
- if isinstance(newobj, staticmethod):
- return self._update_staticmethod(oldobj, newobj)
-
- # New: dealing with metaclasses.
- if hasattr(newobj, '__metaclass__') and hasattr(newobj, '__class__') and newobj.__metaclass__ == newobj.__class__:
- return self._update_class(oldobj, newobj)
-
- # Not something we recognize, just give up
- return newobj
+ except:
+ traceback.print_exc()
# All of the following functions have the same signature as _update()
@@ -213,6 +213,30 @@ def foo(self):
pydevd_reload.xreload(x)
self.assertEqual(foo().__name__, 'B')
+ def testCreateClass2(self):
+ SAMPLE_CODE1 = """
+class C(object):
+ def foo(self):
+ return 0
+"""
+ # Creating a new class and using it from old class
+ SAMPLE_CODE2 = """
+class B(object):
+ pass
+
+class C(object):
+ def foo(self):
+ return B
+"""
+
+ self.make_mod(sample=SAMPLE_CODE1)
+ import x
+ foo = x.C().foo
+ self.assertEqual(foo(), 0)
+ self.make_mod(sample=SAMPLE_CODE2)
+ pydevd_reload.xreload(x)
+ self.assertEqual(foo().__name__, 'B')
+

0 comments on commit 4e1679f

Please sign in to comment.