Skip to content

Commit 90032af

Browse files
Modified new log message slightly to make the names of types on Python2.7 and Python3.5 consistent.
Fixed Github issue #28 by explicitly adding str to the list of types to be wrapped in a list.
1 parent f77df2d commit 90032af

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

cluster/matrix.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,30 @@ def _encapsulate_item_for_combinfunc(item):
3131
before the invocation of combinfunc.
3232
if not hasattr(item, '__iter__') or isinstance(item, tuple):
3333
item = [item]
34-
Logging has been added to the original two lines
35-
and shows that the behaviour of this snippet
34+
Logging was added to the original two lines
35+
and shows that the outcome of this snippet
3636
has changed between Python2.7 and Python3.5.
37+
This logging showed that the difference in
38+
outcome consisted of the handling of the builtin
39+
str class, which was encapsulated into a list in
40+
Python2.7 but returned naked in Python3.5.
41+
Adding a test for this specific class to the
42+
set of conditions appears to give correct behaviour
43+
under both versions.
3744
"""
3845
encapsulated_item = None
39-
if not hasattr(item, '__iter__') or isinstance(item, tuple):
46+
if (
47+
not hasattr(item, '__iter__') or
48+
isinstance(item, tuple) or
49+
isinstance(item, str)
50+
):
4051
encapsulated_item = [item]
4152
else:
4253
encapsulated_item = item
4354
logging.debug(
4455
"item class:%s encapsulated as:%s ",
45-
item.__class__, encapsulated_item.__class__
56+
item.__class__.__name__,
57+
encapsulated_item.__class__.__name__
4658
)
4759
return encapsulated_item
4860

0 commit comments

Comments
 (0)