Skip to content
This repository was archived by the owner on Jun 5, 2023. It is now read-only.

Commit 35f0574

Browse files
author
toby cabot
committed
handle ruby-style Module::Class names
Ruby uses "::" to separate modules from classes, while python uses "." so we'll sniff the queued class name for "::" and if it's there then we're probably handling a job that was queued by Ruby.
1 parent 4f4b282 commit 35f0574

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pyres/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ def my_import(name):
8686

8787
def safe_str_to_class(s):
8888
"""Helper function to map string class names to module classes."""
89-
lst = s.split(".")
89+
# ruby compatibility kludge: ruby uses "::" to separate modules
90+
# from classes, while python uses "." so we'll sniff the string
91+
# for "::" and if it's there then we're probably handling a job
92+
# that was queued by ruby
93+
if "::" in s:
94+
lst = s.split("::")
95+
else:
96+
lst = s.split(".")
9097
klass = lst[-1]
9198
mod_list = lst[:-1]
9299
module = ".".join(mod_list)

tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def test_safe_str_to_class(self):
119119
assert safe_str_to_class('tests.Basic') == Basic
120120
self.assertRaises(ImportError, safe_str_to_class, 'test.Mine')
121121
self.assertRaises(ImportError, safe_str_to_class, 'tests.World')
122+
# test that we can handle Ruby-compatible Module::Class names
123+
assert safe_str_to_class('tests::Basic') == Basic
122124
# test that we'll use the class name as a module name if no
123125
# module name is provided (for Ruby compatibility)
124126
assert safe_str_to_class('tests') == tests

0 commit comments

Comments
 (0)