summaryrefslogtreecommitdiff
path: root/constructor.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-08-08 17:38:43 +0200
committerAnthon van der Neut <anthon@mnt.org>2018-08-08 17:38:43 +0200
commitd68c914426b826ff9b076eb870aebdfdef5d82aa (patch)
tree7f00c92a3e5b6554f82197a79120494b77b5c3b3 /constructor.py
parent65c335bcf426d4954c079eda2cc5414259bea4f9 (diff)
downloadruamel.yaml-d68c914426b826ff9b076eb870aebdfdef5d82aa.tar.gz
fix issue #124: incorrect tags for class methods
Diffstat (limited to 'constructor.py')
-rw-r--r--constructor.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/constructor.py b/constructor.py
index 6de5181..ab3ebf5 100644
--- a/constructor.py
+++ b/constructor.py
@@ -773,10 +773,20 @@ class Constructor(SafeConstructor):
mark,
)
if u'.' in name:
- module_name, object_name = name.rsplit('.', 1)
+ lname = name.split('.')
+ lmodule_name, lobject_name = lname, []
+ while len(lmodule_name) > 1:
+ lobject_name.insert(0, lmodule_name.pop())
+ module_name = '.'.join(lmodule_name)
+ try:
+ __import__(module_name)
+ # object_name = '.'.join(object_name)
+ break
+ except ImportError as exc:
+ continue
else:
module_name = builtins_module
- object_name = name
+ object_name = [name]
try:
__import__(module_name)
except ImportError as exc:
@@ -787,14 +797,20 @@ class Constructor(SafeConstructor):
mark,
)
module = sys.modules[module_name]
- if not hasattr(module, object_name):
- raise ConstructorError(
- 'while constructing a Python object',
- mark,
- 'cannot find %r in the module %r' % (utf8(object_name), module.__name__),
- mark,
- )
- return getattr(module, object_name)
+ object_name = '.'.join(lobject_name)
+ obj = module
+ while lobject_name:
+ if not hasattr(obj, lobject_name[0]):
+
+ raise ConstructorError(
+ 'while constructing a Python object',
+ mark,
+ 'cannot find %r in the module %r' % (
+ utf8(object_name), module.__name__),
+ mark,
+ )
+ obj = getattr(obj, lobject_name.pop(0))
+ return obj
def construct_python_name(self, suffix, node):
# type: (Any, Any) -> Any