Commits

Jason R. Coombs committed be0f62f

Fixed failing test when class was not in a top-level module.
Fixed errors in tests

  • Participants
  • Parent commits 272802d

Comments (0)

Files changed (1)

jaraco/json/main.py

 
 encode = GenericEncoder().encode
 
+def _find_module_by_name(mod_name):
+	mod_sep = '.'
+	parent = __import__(mod_name)
+	parent_name, sep, children = mod_name.partition(mod_sep)
+	if not children: return parent
+	for child in children.split(mod_sep):
+		parent = getattr(parent, child)
+	return parent
+
 def decode_object_hook(object):
 	if '__python_class__' not in object.keys():
 		return object
 	mod_name = object['__python_module__']
 	args = decode(object['args'])
 	state = decode(object['state'])
-	mod = __import__(mod_name)
+	mod = _find_module_by_name(mod_name)
 	cls = getattr(mod, class_name)
 	ob = cls.__new__(cls, *args)
 	ob.__dict__.update(state)