From pykde Sat Nov 13 17:42:37 2021 From: Philippe Fremy Date: Sat, 13 Nov 2021 17:42:37 +0000 To: pykde Subject: Three different enum behavior Message-Id: <1b0ec7815afa337fc2e3589dc1a3c943 () freehackers ! org> X-MARC-Message: https://marc.info/?l=pykde&m=163682535829610 Hi, I am working on improving the typing information of the project PyQt5-stubs for all QFlags classes. While working on this, I discovered some differences between QFlags enums. Basically, QFlags related classes are always composed of two classes: - the enum class which inherits from int - the QFlag classes which represents the composition of one or several enum The differences I noticed are on the behavior of the "or" and "ror" for the enum class. In some cases, it will result in an int, kind of defeating the purpose of enum classes. In some others, it will result in the corresponding QFlag classes. Examples: 1.a Oring two enum results in a QFlag: >>> from PyQt5 import QtWidgets >>> flag = QtWidgets.QAbstractSpinBox.StepEnabledFlag() >>> flag | flag 1.b Oring two enum results in an int: >>> from PyQt5 import QtWidgets >>> flag = QtWidgets.QStyleOptionTab.TabFeature() >>> flag | flag 0 2.a Oring enum with int results in a QFlag >>> from PyQt5 import QtGui >>> flag = QtGui.QTouchEvent.TouchPoint.InfoFlag() >>> flag | 1 2.b Oring enum with int results in an int >>> from PyQt5 import QtCore >>> flag = QtWidgets.QAbstractSpinBox.StepEnabledFlag() >>> flag | 1 1 3.a Oring int with enum results in a QFlag >>> from PyQt5 import QtCore >>> flag = QtCore.QTextBoundaryFinder.BoundaryReason() >>> 1 | flag 3.b Oring int with enum results in an int >>> from PyQt5 import QtWidgets >>> flag = QtWidgets.QStyleOptionTab.TabFeature() >>> 1 | flag 1 Globally, all enum class fall into three categories: - behavior 1.a + 2.a + 3.a - behavior 1.a + 2.b + 3.a - behavior 1.b + 2.b + 3.b I am not sure if this is intended behavior. Anyway, this will be properly handled in the next release of PyQt5-stubs. Have a nice day, Philippe