Skip to content

Commit dbdf7ec

Browse files
committed
Support str/unicode comparison in JavaString
Adds back Python 2.7 support Signed-off-by: Thomas Calmant <thomas.calmant@gmail.com>
1 parent 73c10c6 commit dbdf7ec

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

javaobj/v1/beans.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,14 @@ def __hash__(self):
173173
return UNICODE_TYPE.__hash__(self)
174174

175175
def __eq__(self, other):
176-
if not isinstance(other, UNICODE_TYPE):
176+
# Accept both UNICODE_TYPE and plain str.
177+
# In Python 2, UNICODE_TYPE is unicode while str literals are bytes;
178+
# including str here lets assertEqual(java_string, "literal") work
179+
# in Python 2 as well as Python 3 (where str == UNICODE_TYPE).
180+
if not isinstance(other, (UNICODE_TYPE, str)):
177181
return False
178-
return UNICODE_TYPE.__eq__(self, other)
182+
result = UNICODE_TYPE.__eq__(self, other)
183+
return False if result is NotImplemented else result
179184

180185

181186
class JavaEnum(JavaObject):

0 commit comments

Comments
 (0)