PyQt6 Enum implcit conversion

Phil Thompson phil at riverbankcomputing.com
Thu May 25 15:51:17 BST 2023


On 25/05/2023 15:25, Julien Cabieces wrote:
> The same example is working in pure python
> 
> ---
> class MyEnum(IntEnum):
>    VALA=0
>    VALB=1
>    VALC=2
> 
> def printEnum(an_enum):
>    if an_enum == MyEnum.VALA:
>       print("VALA")
>    else:
>       print("others")
> 
> printEnum(1)
> others
> ---

It works because Python objects are dynamically typed, not because of 
any enum/int conversion.

> It makes sense to me for an IntEnum to be able to convert from/to an
> integer, no?

Explicitly yes, implicitly no. A member of an IntEnum behaves like an 
int but it is not an int.

Phil


More information about the PyQt mailing list