question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Comparison issue for Enum

See original GitHub issue

Since Enum use is operator to check equality, it will fail if the other value is not the same object as Enum.value.

Code:

from graphene import Enum

big_value = 99999999999999
big_string = 'hello' * 100


class MyEnum(Enum):
    TypeA = 99999999999999
    TypeB = 'hello' * 100

assert MyEnum.TypeA == big_value
assert MyEnum.TypeB == big_string

Expect result: Everything works fine.

Result:

assertion failed for both.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jkimbocommented, Aug 25, 2018

@Fity you need to do:

assert MyEnum.TypeA.value == big_value
assert MyEnum.TypeB.value == big_string
0reactions
jkimbocommented, Aug 28, 2018

Ah I didn’t know about that. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Comparing Java enum members: == or equals()?
Because there is only one instance of each enum constant, it is permissible to use the == operator in place of the equals...
Read more >
Comparing enum members in Java - GeeksforGeeks
When we use == operator for comparison, then we are not getting any Exception whereas when we use .equals() method then we are...
Read more >
Comparing enum members in Java - Tutorialspoint
Using Enum.compareTo() method. compareTo() method compares this enum with the specified object for order. · Using Enum.equals() method. · Using == ...
Read more >
Javarevisited: How to Compare Two Enum in Java? Equals vs ...
Though you can compare two Enum using equals() and == method for equality check, there is subtle difference between them.
Read more >
Comparing Enum values in Java - Medium
Comparing Enum values in Java ... The common sense rule in Java is that when comparing things, objects always get compared with objectA.equals(objectB)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found