<div dir="ltr"><div>After getting some help from Nyall, I have boiled it down to the following:</div><div><br></div><div>SIP 4/5: translates C++ enum into regular Python classes inheriting from 'int'. And furthermore, because of the way SIP works, __dir__ does not reveal the members.<br><br></div><div>SIP 6: translates C++ enums into enum.Enum, which works properly with __iter__ and __members__ (and maybe __dir__ too). </div><div><br></div><div>Qt6 depends on SIP 6, so any version of QGIS built with Qt6 will end up having proper enum.Enum objects.</div><div><br></div><div>When building QGIS, it will first attempt to use SIP 6, but if not available it will fall back to SIP 4/5. This happens in FindSIP.py. So if building QGIS Qt5, but with SIP6 available, I expect the result will be proper enum.Enums. But I have not tried.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 2, 2025 at 2:19 PM Julien Cabieces <<a href="mailto:julien.cabieces@oslandia.com" target="_blank">julien.cabieces@oslandia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
You're right, the actual code doesn't work in my environment either.<br>
<br>
PyQt is also a wrapper of Qt made with sip, so we should get the same<br>
result in sip.<br>
<br>
QCborSimpleType is actually and exception because it fails also with<br>
other Qt enums that I have tested (Qt.ItemDataRole for instance).<br>
<br>
I don't get what happen here, the script supposedly not work like it<br>
should. But it worked before, so I'm wondering what happened. Maybe SIP<br>
changed things and introduced the mappingproxy thing.<br>
<br>
I'd have to investigate a bit...<br>
<br>
If anyone has information on this, please share :)<br>
<br>
Regards,<br>
Julien<br>
<br>
<br>
<br>
> Thanks. And that function works well for e.g. qgis.qgis.PyQt.Qt.QCborSimpleType. Which by the way has type<br>
> enum.EnumType, and is defined in QGIS/share/qgis/python/qgis/PyQt/Qt.py.<br>
><br>
> But Im talking about an "enum" created by SIP. Such an "enum" is a class definition, with 'int' as its only parent class. It<br>
> has around 14 enum-members, e.g. "Symbology". But there is no way of getting a complete list of them. Neither with _<br>
> _dict__ nor dir. <br>
><br>
>>>> from qgis.core import QgsMapLayer<br>
>>>> QgsMapLayer.StyleCategory<br>
> <class 'qgis._core.QgsMapLayer.StyleCategory'><br>
>>>> type(QgsMapLayer.StyleCategory)<br>
> <class 'sip.enumtype'><br>
>>>> QgsMapLayer.StyleCategory.__dict__<br>
> mappingproxy({'__module__': 'qgis._core', '__or__': <slot wrapper '__or__' of 'StyleCategory' objects>, '__ror__': <slot<br>
> wrapper '__ror__' of 'StyleCategory' objects>, '__dict__': <attribute '__dict__' of 'StyleCategory' objects>, '__doc__': None,<br>
> '__reduce__': <method '_pickle_enum' of 'StyleCategory' objects>, 'baseClass': <class 'qgis._core.QgsMapLayer'>})<br>
>>>> dir(QgsMapLayer.StyleCategory)<br>
> ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dict__', '__dir__', '__divmod__', '__doc__',<br>
> '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__getstate__',<br>
> '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__',<br>
> '__module__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__',<br>
> '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__',<br>
> '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__',<br>
> '__truediv__', '__trunc__', '__xor__', 'as_integer_ratio', 'baseClass', 'bit_count', 'bit_length', 'conjugate', 'denominator',<br>
> 'from_bytes', 'imag', 'is_integer', 'numerator', 'real', 'to_bytes']<br>
>>>> QgsMapLayer.StyleCategory.Symbology # but the members are there !<br>
> 2<br>
><br>
> On Wed, Jul 2, 2025 at 10:00 AM Julien Cabieces <<a href="mailto:julien.cabieces@oslandia.com" target="_blank">julien.cabieces@oslandia.com</a>> wrote:<br>
><br>
>  Hi,<br>
><br>
>  If you want an example, it has been done here: <br>
>  <a href="https://github.com/qgis/QGIS/blob/cb48529abf5bd81e3c97d09809e3d56e51c943bd/scripts/pyqt5_to_pyqt6/pyqt5_to_pyqt6.py#L796" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/blob/cb48529abf5bd81e3c97d09809e3d56e51c943bd/scripts/pyqt5_to_pyqt6/pyqt5_to_pyqt6.py#L796</a><br>
>  <br>
><br>
>  You have to use __dict__. But I'm not sure this is a good thing to use<br>
>  this in a plugin. The script I mention is an helper for migration from<br>
>  qt5 to qt6, so it's kind of special.<br>
><br>
>  Regards,<br>
>  Julien<br>
><br>
>  > Happy summer to all of you :)<br>
>  ><br>
>  > It seems in the Python bindings produced by SIP, a C++ enum is just a Python class with a certain structure. And<br>
>  with little/none possibility of<br>
>  > introspection.<br>
>  ><br>
>  > But how can I get a list with all enum-members (e.g. Symbology, Fields) of that enum?<br>
>  ><br>
>  > dir(QgsMapLayer.StyleCategory) does not list them, and QgsMapLayer.StyleCategory.__members__ is undefined. <br>
>  ><br>
>  > Do I really have to hard code the member names into my plugin, if I want to iterate over all of them?<br>
>  ><br>
>  > Sincerely, Thomas<br>
>  ><br>
>  > _______________________________________________<br>
>  > QGIS-Developer mailing list<br>
>  > <a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
>  > List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
>  > Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
><br>
>  -- <br>
><br>
>  Julien Cabieces<br>
>  Senior Developer at Oslandia<br>
>  <a href="mailto:julien.cabieces@oslandia.com" target="_blank">julien.cabieces@oslandia.com</a><br>
<br>
-- <br>
<br>
Julien Cabieces<br>
Senior Developer at Oslandia<br>
<a href="mailto:julien.cabieces@oslandia.com" target="_blank">julien.cabieces@oslandia.com</a><br>
</blockquote></div>