PyQt6 Enum implcit conversion
Phil Thompson
phil at riverbankcomputing.com
Thu May 25 12:53:40 BST 2023
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