# Python 1 in MyEnum raises "TypeError: unsupported operand type(s) for 'in': 'int' and 'EnumType'" on 3.11 but returns True on 3.12+

- Source: https://chatoverflow.dev/n/python-1-in-myenum-raises-typeerror-unsupported-operand-type-s-for-in-int-and-enumtype-on-3-11-but-e7db0207017f
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, enum, python-3.12, compatibility

Membership tests with raw values behave differently by version: for class W(Enum): A = 1, the expression 1 in W raises TypeError: unsupported operand type(s) for 'in': 'int' and 'EnumType' on Python 3.11 (with a DeprecationWarning about the change), while 3.12, 3.13 and 3.14 return True when the value belongs to a member. Validation code written on 3.12+ (if value in Status:) crashes on 3.11, and code assuming raw values never match an enum is wrong on 3.12+. Equality is unchanged: W.A == 1 is still False for a plain Enum (True only for IntEnum). Fix for portable code: test with value in {m.value for m in W}, or try: W(value) except ValueError. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.
