-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid conversion to int_
rhs argument of enum eq/ne
#1912
Conversation
525a3d8
to
2775677
Compare
This change looks reasonable, but shouldn't it also be implemented consistently for the other operations (e.g. less than operator for arithmetic types, etc.)? |
I think the right way is to mock python behavior. Here is test snippet with int, string and custom types: test snippetclass A(object):
def __repr__(self): return "A()"
class B(object):
def __repr__(self): return "B()"
def test_binop(op, f):
try:
result = f()
print("`{} {} {}` = `{}`({})".format(repr(a),op,repr(b),result,type(result)))
except Exception as e:
print("`{} {} {}` raises {}: {}".format(repr(a),op,repr(b),type(e), e))
def test_unop(op, f):
try:
result = f()
print("`{} {}` = `{}`({})".format(op,repr(a),result,type(result)))
except Exception as e:
print("`{} {}` raises {}: {}".format(op,repr(a),type(e), e))
for a,b in [(A(), B()),
(1, 2),
(1, A()),
(A(), 1),
]:
test_binop("!=", lambda: a!=b)
test_binop("==", lambda: a==b)
test_binop("<", lambda: a<b)
test_binop("<=", lambda: a<=b)
test_binop(">", lambda: a>b)
test_binop("&", lambda: a&b)
test_binop("|", lambda: a|b)
test_binop("^", lambda: a^b)
for a in [A(), 1, "string"]:
test_unop("~", lambda: ~a) snippet on repl.it: (python2) (python3)
Current behavior is in line with python3. I've updated tests to check behavior of enum arithmetic and behavior on operations with unsupported types. Should we branch on python version or leave it as is? While current behavior is in line with pytnon3, the exception message is a bit off-putting:
Additional check will duplicate checks inside of |
Enumeration elements may appear in docsting unordered
For some reason enumeration elements order in docstring is not determined. Replaced exact docstring comparison with every-line-exists-in-docstring check. |
I don't think the extra check is needed, and defaulting to Python 3 behavior sounds good to me. |
Fixes #1830