[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: PyQt6 Enum implcit conversion
From: Phil Thompson <phil () riverbankcomputing ! com>
Date: 2023-05-25 14:51:17
Message-ID: a23dee7f426649beeeaf35c46d1f1bb8 () riverbankcomputing ! com
[Download RAW message or body]
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic