We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 73c10c6 commit dbdf7ecCopy full SHA for dbdf7ec
1 file changed
javaobj/v1/beans.py
@@ -173,9 +173,14 @@ def __hash__(self):
173
return UNICODE_TYPE.__hash__(self)
174
175
def __eq__(self, other):
176
- if not isinstance(other, UNICODE_TYPE):
+ # 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)):
181
return False
- return UNICODE_TYPE.__eq__(self, other)
182
+ result = UNICODE_TYPE.__eq__(self, other)
183
+ return False if result is NotImplemented else result
184
185
186
class JavaEnum(JavaObject):
0 commit comments