pass trough annotated exceptions

This commit is contained in:
Ronny Pfannschmidt
2016-01-23 19:31:17 +01:00
parent 60e9698530
commit b825af2e66
2 changed files with 18 additions and 12 deletions
+15 -9
View File
@@ -2,6 +2,7 @@
import os, sys
import re
import pytest
from py.builtin import _basestring
@@ -52,17 +53,22 @@ def resolve(name):
raise ImportError(
'import error in %s: %s' % (used, ex)
)
try:
found = getattr(found, part)
except AttributeError:
raise AttributeError(
'%r object at %s has no attribute %r' %(
type(found).__name__, used, part
)
)
found = annotated_getattr(found, part, used)
return found
def annotated_getattr(obj, name, ann):
try:
obj = getattr(obj, name)
except AttributeError:
raise AttributeError(
'%r object at %s has no attribute %r' % (
type(obj).__name__, ann, name
)
)
return obj
def derive_importpath(import_path, raising):
if not isinstance(import_path, _basestring) or "." not in import_path:
raise TypeError("must be absolute import path string, not %r" %
@@ -70,7 +76,7 @@ def derive_importpath(import_path, raising):
module, attr = import_path.rsplit('.', 1)
target = resolve(module)
if raising:
getattr(target, attr)
annotated_getattr(target, attr, ann=module)
return attr, target