Skip to content

Commit

Permalink
Merge pull request #85 from ottogroup/feature/resolve-dotted-name-mod…
Browse files Browse the repository at this point in the history
…ules

resolve_dotted_names can now resolve module names, such as 'pickle'
  • Loading branch information
alattner committed May 29, 2018
2 parents 1909827 + 9a5bfb3 commit 8fb6b3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions palladium/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def test_with_dots(self, resolve_dotted_name):
assert (resolve_dotted_name(dotted) is
TestResolveDottedName)

def test_module(self, resolve_dotted_name):
resolve_dotted_name('threading') is threading


def test_args_from_config(config):
from palladium.util import args_from_config
Expand Down
9 changes: 6 additions & 3 deletions palladium/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
def resolve_dotted_name(dotted_name):
if ':' in dotted_name:
module, name = dotted_name.split(':')
else:
elif '.' in dotted_name:
module, name = dotted_name.rsplit('.', 1)
else:
module, name = dotted_name, None

attr = import_module(module)
for name in name.split('.'):
attr = getattr(attr, name)
if name:
for name in name.split('.'):
attr = getattr(attr, name)

return attr

Expand Down

0 comments on commit 8fb6b3d

Please sign in to comment.