PyQt6 Enum implcit conversion

Phil Thompson phil at riverbankcomputing.com
Thu May 25 14:42:28 BST 2023


They are still different types so you need to explicitly convert the 
int.

Phil

On 25/05/2023 14:15, Julien Cabieces wrote:
> Yes, I tried that also with /BaseType=IntEnum/, and I also get the same
> issue even if the pyi generated file seems to be correctly generated
> 
> class MyEnum(enum.IntEnum):
>         VALA = ... # type: Test.MyEnum
>         VALB = ... # type: Test.MyEnum
>         VALC = ... # type: Test.MyEnum
> 
> Regards,
> Julien
> 
>> On 25/05/2023 12:37, Julien Cabieces wrote:
>>> Hi,
>>> With SIP/PyQT5 it was possible to pass directly an int to a function
>>> taking an enum as a parameter. It's no longer possible with PyQt6.
>>> For instance, with the following attached sip/header files, in PyQt5
>>> the
>>> following code works :
>>> $ python -c "from test import Test;test=Test();test.printEnum(2)"
>>> others%
>>> While in PyQt6 it display the following error:
>>> Traceback (most recent call last):
>>>   File "<string>", line 1, in <module>
>>> TypeError: printEnum(self, e: Test.MyEnum): argument 1 has
>>> unexpected type 'int'
>>> I understand that the issue is due to the fact that from now enum
>>> inherit from Python enum.Enum type instead of int, but is this 
>>> behavior
>>> wanted or is it an issue that would be fixed ?
>> 
>> It's wanted. If you want int behaviour then annotate the enum
>> definition...
>> 
>> https://www.riverbankcomputing.com/static/Docs/sip/annotations.html#enum-annotation-BaseType
>> 
>> Phil


More information about the PyQt mailing list