diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d746d422..0cfb4b4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,15 +24,13 @@ jobs: os: - name: Linux runs-on: ubuntu-latest - matrix: linux -# https://github.com/python-qt-tools/PyQt5-stubs/issues/122 -# - name: Windows -# runs-on: windows-latest -# matrix: windows -# https://github.com/python-qt-tools/PyQt5-stubs/issues/122 -# - name: macOS -# runs-on: macos-latest -# matrix: macos + tox: linux + - name: macOS + runs-on: macos-latest + tox: macos + - name: Windows + runs-on: windows-latest + tox: windows python: - name: CPython 3.6 tox: py36 @@ -46,6 +44,9 @@ jobs: - name: CPython 3.9 tox: py39 action: 3.9 + - name: CPython 3.10 + tox: py310 + action: '3.10' steps: - uses: actions/checkout@v2 - name: Set up ${{ matrix.python.name }} @@ -55,7 +56,7 @@ jobs: architecture: x64 - uses: twisted/python-info-action@v1.0.1 - name: Install Linux Qt5 dependencies - if: matrix.os.matrix == 'linux' + if: matrix.os.name == 'Linux' run: | sudo apt-get update --yes sudo apt-get install --yes libgl1 @@ -67,7 +68,7 @@ jobs: pip install tox - name: Test run: | - tox -v -e ${{ matrix.python.tox }} + tox -v -e ${{ matrix.python.tox }}-${{ matrix.os.tox }} all: name: All diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b68289d..f3d0302e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] ### Added +* [#179](https://github.com/python-qt-tools/PyQt5-stubs/pull/179) update to PyQt5 5.15.6 +* [#176](https://github.com/python-qt-tools/PyQt5-stubs/pull/176) update to PyQt5 5.15.5 +* [#175](https://github.com/python-qt-tools/PyQt5-stubs/pull/175) catch up PyQtNetworkAuth with the 5.15.4 release +* [#149](https://github.com/python-qt-tools/PyQt5-stubs/pull/149) update to PyQt5 5.15.4 * [#138](https://github.com/python-qt-tools/PyQt5-stubs/pull/138) update to PyQt5 5.15.3 +* [#145](https://github.com/python-qt-tools/PyQt5-stubs/pull/145) Support all implemented arithmetic operations between Qt.WindowType and Qt.WindowFlags and int * [#144](https://github.com/python-qt-tools/PyQt5-stubs/pull/144) add `QTreeWidgetItem.__lt__()` to allow sorting of items in a QTreeWidget * [#143](https://github.com/python-qt-tools/PyQt5-stubs/pull/143) make `bytes(QByteArray())` valid by incorrectly adding `.__bytes__()` until a proper solution is developed upstream +* [#152](https://github.com/python-qt-tools/PyQt5-stubs/pull/152) add `.__or__()` for `QDialogButtonBox.StandardButton` and `QDialogButtonBox.StandardButtons` +* [#156](https://github.com/python-qt-tools/PyQt5-stubs/pull/156) add operators to `QSize` and `QSizeF` +* [#153](https://github.com/python-qt-tools/PyQt5-stubs/pull/153) Support all implemented arithmetic operations for QFlags + based classes in modules QtCore, QtWidgets, QtGui, QtNetwork, QtDBus, QtOpenGL, QtPrintsupport, QtSql, QtTest, QtXml +* [#162](https://github.com/python-qt-tools/PyQt5-stubs/pull/162) fixes all method not declared as signals +* [#184](https://github.com/python-qt-tools/PyQt5-stubs/pull/184) Fix missing module variable + detected by latest mypy 0.930 +* [#183](https://github.com/python-qt-tools/PyQt5-stubs/pull/183) Add missing operations on QSize +* [#189](https://github.com/python-qt-tools/PyQt5-stubs/pull/189) Fix QListWidget, QTreeWidget and QTableWidget so that their respective items are now optional in many places when used as argument or return value +* [#165](https://github.com/python-qt-tools/PyQt5-stubs/pull/165) allow `None` as argument for `QLineEdit.setText()` ## 5.15.2.0 diff --git a/Dockerfile b/Dockerfile index 6d481693..347da1ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,18 +2,19 @@ # https://hub.docker.com/_/archlinux?tab=tags&page=1&ordering=last_updated # BUILD_DATE is a path from: # https://archive.archlinux.org/repos/ -ARG ARCH_VERSION="base-20210221.0.15908" -ARG BUILD_DATE="2021/02/25" - -ARG SIP_VERSION="6.0.2" -# Also the major.minor of PyQt5-sip -ARG SIP_ABI_VERSION="12.8" -ARG PYQT_VERSION="5.15.3" -ARG PYQT_3D_VERSION="5.15.3" -ARG PYQT_CHART_VERSION="5.15.3" -ARG PYQT_DATA_VISUALIZATION_VERSION="5.15.3" -ARG PYQT_PURCHASING_VERSION="5.15.3" -ARG PYQT_WEB_ENGINE_VERSION="5.15.3" +ARG ARCH_VERSION="base-20211121.0.39613" +ARG BUILD_DATE="2021/11/29" + +ARG SIP_VERSION="6.4.0" +# Also the major of PyQt5-sip +ARG SIP_ABI_VERSION="12" +ARG PYQT_VERSION="5.15.6" +ARG PYQT_3D_VERSION="5.15.5" +ARG PYQT_CHART_VERSION="5.15.5" +ARG PYQT_DATA_VISUALIZATION_VERSION="5.15.5" +ARG PYQT_PURCHASING_VERSION="5.15.5" +ARG PYQT_WEB_ENGINE_VERSION="5.15.5" +ARG PYQT_NETWORK_AUTH_VERSION="5.15.5" ARG MAKEFLAGS="" @@ -301,6 +302,39 @@ RUN sip-install \ WORKDIR /output/ RUN find /upstream/ -name \*.pyi -exec cp {} . \; +################################################################################ +# PyQtNetworkAuth +################################################################################ + +FROM build-dep AS pyqt-network-auth + +# Reuse arguments from previous build scope +ARG MAKEFLAGS +ARG PYQT_NETWORK_AUTH_VERSION + +# Download source tar +RUN wget --no-verbose \ + --output-document upstream.tar.gz \ + https://pypi.io/packages/source/p/pyqtnetworkauth/PyQtNetworkAuth-${PYQT_NETWORK_AUTH_VERSION}.tar.gz +RUN mkdir /upstream/ && \ + tar -xf \ + upstream.tar.gz \ + --directory /upstream/ \ + --strip-components 1 + +# Build PyQtNetworkAuth with stubs +# TODO: Find way to build only stubs +WORKDIR /upstream/ +RUN sip-install \ + --qmake /usr/bin/qmake-qt5 \ + --pep484-pyi \ + --build-dir ./build \ + --verbose + +# Copy all .pyi files to output dir +WORKDIR /output/ +RUN find /upstream/ -name \*.pyi -exec cp {} . \; + ################################################################################ # Output ################################################################################ @@ -316,6 +350,7 @@ COPY --from=pyqt-chart /output/* ./ COPY --from=pyqt-data-visualization /output/* ./ COPY --from=pyqt-purchasing /output/* ./ COPY --from=pyqt-web-engine /output/* ./ +COPY --from=pyqt-network-auth /output/* ./ # Required to run the image (which we need to do to get the files) CMD /bin/true diff --git a/PyQt5-stubs/Qt3DAnimation.pyi b/PyQt5-stubs/Qt3DAnimation.pyi index 90a0c766..46f08f17 100644 --- a/PyQt5-stubs/Qt3DAnimation.pyi +++ b/PyQt5-stubs/Qt3DAnimation.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the Qt3DAnimation module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -52,9 +52,9 @@ class QAbstractAnimation(QtCore.QObject): MorphingAnimation = ... # type: QAbstractAnimation.AnimationType VertexBlendAnimation = ... # type: QAbstractAnimation.AnimationType - def durationChanged(self, duration: float) -> None: ... - def positionChanged(self, position: float) -> None: ... - def animationNameChanged(self, name: str) -> None: ... + durationChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + animationNameChanged: typing.ClassVar[QtCore.pyqtSignal] def setDuration(self, duration: float) -> None: ... def setPosition(self, position: float) -> None: ... def setAnimationName(self, name: str) -> None: ... @@ -66,14 +66,14 @@ class QAbstractAnimation(QtCore.QObject): class QAbstractAnimationClip(Qt3DCore.QNode): def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def durationChanged(self, duration: float) -> None: ... + durationChanged: typing.ClassVar[QtCore.pyqtSignal] def duration(self) -> float: ... class QAbstractChannelMapping(Qt3DCore.QNode): ... class QAbstractClipAnimator(Qt3DCore.QComponent): - class Loops(int): + class Loops(int): Infinite = ... # type: QAbstractClipAnimator.Loops Infinite = ... # type: QAbstractClipAnimator.Loops @@ -81,11 +81,11 @@ class QAbstractClipAnimator(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def normalizedTimeChanged(self, index: float) -> None: ... - def clockChanged(self, clock: 'QClock') -> None: ... - def loopCountChanged(self, loops: int) -> None: ... - def channelMapperChanged(self, channelMapper: 'QChannelMapper') -> None: ... - def runningChanged(self, running: bool) -> None: ... + normalizedTimeChanged: typing.ClassVar[QtCore.pyqtSignal] + clockChanged: typing.ClassVar[QtCore.pyqtSignal] + loopCountChanged: typing.ClassVar[QtCore.pyqtSignal] + channelMapperChanged: typing.ClassVar[QtCore.pyqtSignal] + runningChanged: typing.ClassVar[QtCore.pyqtSignal] def stop(self) -> None: ... def start(self) -> None: ... def setNormalizedTime(self, timeFraction: float) -> None: ... @@ -107,9 +107,9 @@ class QAdditiveClipBlend('QAbstractClipBlendNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def additiveClipChanged(self, additiveClip: 'QAbstractClipBlendNode') -> None: ... - def baseClipChanged(self, baseClip: 'QAbstractClipBlendNode') -> None: ... - def additiveFactorChanged(self, additiveFactor: float) -> None: ... + additiveClipChanged: typing.ClassVar[QtCore.pyqtSignal] + baseClipChanged: typing.ClassVar[QtCore.pyqtSignal] + additiveFactorChanged: typing.ClassVar[QtCore.pyqtSignal] def setAdditiveClip(self, additiveClip: 'QAbstractClipBlendNode') -> None: ... def setBaseClip(self, baseClip: 'QAbstractClipBlendNode') -> None: ... def setAdditiveFactor(self, additiveFactor: float) -> None: ... @@ -125,7 +125,7 @@ class QAnimationClip('QAbstractAnimationClip'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def clipDataChanged(self, clipData: 'QAnimationClipData') -> None: ... + clipDataChanged: typing.ClassVar[QtCore.pyqtSignal] def setClipData(self, clipData: 'QAnimationClipData') -> None: ... def clipData(self) -> 'QAnimationClipData': ... @@ -147,7 +147,7 @@ class QAnimationClipData(sip.simplewrapper): class QAnimationClipLoader('QAbstractAnimationClip'): - class Status(int): + class Status(int): NotReady = ... # type: QAnimationClipLoader.Status Ready = ... # type: QAnimationClipLoader.Status Error = ... # type: QAnimationClipLoader.Status @@ -162,8 +162,8 @@ class QAnimationClipLoader('QAbstractAnimationClip'): def __init__(self, source: QtCore.QUrl, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def statusChanged(self, status: 'QAnimationClipLoader.Status') -> None: ... - def sourceChanged(self, source: QtCore.QUrl) -> None: ... + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] def setSource(self, source: QtCore.QUrl) -> None: ... def status(self) -> 'QAnimationClipLoader.Status': ... def source(self) -> QtCore.QUrl: ... @@ -172,12 +172,12 @@ class QAnimationController(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def recursiveChanged(self, recursive: bool) -> None: ... - def entityChanged(self, entity: Qt3DCore.QEntity) -> None: ... - def positionOffsetChanged(self, offset: float) -> None: ... - def positionScaleChanged(self, scale: float) -> None: ... - def positionChanged(self, position: float) -> None: ... - def activeAnimationGroupChanged(self, index: int) -> None: ... + recursiveChanged: typing.ClassVar[QtCore.pyqtSignal] + entityChanged: typing.ClassVar[QtCore.pyqtSignal] + positionOffsetChanged: typing.ClassVar[QtCore.pyqtSignal] + positionScaleChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + activeAnimationGroupChanged: typing.ClassVar[QtCore.pyqtSignal] def setRecursive(self, recursive: bool) -> None: ... def setEntity(self, entity: Qt3DCore.QEntity) -> None: ... def setPositionOffset(self, offset: float) -> None: ... @@ -201,9 +201,9 @@ class QAnimationGroup(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def durationChanged(self, duration: float) -> None: ... - def positionChanged(self, position: float) -> None: ... - def nameChanged(self, name: str) -> None: ... + durationChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + nameChanged: typing.ClassVar[QtCore.pyqtSignal] def setPosition(self, position: float) -> None: ... def setName(self, name: str) -> None: ... def removeAnimation(self, animation: 'QAbstractAnimation') -> None: ... @@ -218,7 +218,7 @@ class QBlendedClipAnimator('QAbstractClipAnimator'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def blendTreeChanged(self, blendTree: 'QAbstractClipBlendNode') -> None: ... + blendTreeChanged: typing.ClassVar[QtCore.pyqtSignal] def setBlendTree(self, blendTree: 'QAbstractClipBlendNode') -> None: ... def blendTree(self) -> 'QAbstractClipBlendNode': ... @@ -270,9 +270,9 @@ class QChannelMapping('QAbstractChannelMapping'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def propertyChanged(self, property: str) -> None: ... - def targetChanged(self, target: Qt3DCore.QNode) -> None: ... - def channelNameChanged(self, channelName: str) -> None: ... + propertyChanged: typing.ClassVar[QtCore.pyqtSignal] + targetChanged: typing.ClassVar[QtCore.pyqtSignal] + channelNameChanged: typing.ClassVar[QtCore.pyqtSignal] def setProperty(self, property: str) -> None: ... # type: ignore[override] def setTarget(self, target: Qt3DCore.QNode) -> None: ... def setChannelName(self, channelName: str) -> None: ... @@ -284,7 +284,7 @@ class QClipAnimator('QAbstractClipAnimator'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def clipChanged(self, clip: 'QAbstractAnimationClip') -> None: ... + clipChanged: typing.ClassVar[QtCore.pyqtSignal] def setClip(self, clip: 'QAbstractAnimationClip') -> None: ... def clip(self) -> 'QAbstractAnimationClip': ... @@ -299,7 +299,7 @@ class QClipBlendValue('QAbstractClipBlendNode'): @typing.overload def __init__(self, clip: 'QAbstractAnimationClip', parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def clipChanged(self, clip: 'QAbstractAnimationClip') -> None: ... + clipChanged: typing.ClassVar[QtCore.pyqtSignal] def setClip(self, clip: 'QAbstractAnimationClip') -> None: ... def clip(self) -> 'QAbstractAnimationClip': ... @@ -307,13 +307,13 @@ class QClock(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def playbackRateChanged(self, playbackRate: float) -> None: ... + playbackRateChanged: typing.ClassVar[QtCore.pyqtSignal] def setPlaybackRate(self, playbackRate: float) -> None: ... def playbackRate(self) -> float: ... class QKeyFrame(sip.simplewrapper): - class InterpolationType(int): + class InterpolationType(int): ConstantInterpolation = ... # type: QKeyFrame.InterpolationType LinearInterpolation = ... # type: QKeyFrame.InterpolationType BezierInterpolation = ... # type: QKeyFrame.InterpolationType @@ -342,7 +342,7 @@ class QKeyFrame(sip.simplewrapper): class QKeyframeAnimation('QAbstractAnimation'): - class RepeatMode(int): + class RepeatMode(int): None_ = ... # type: QKeyframeAnimation.RepeatMode Constant = ... # type: QKeyframeAnimation.RepeatMode Repeat = ... # type: QKeyframeAnimation.RepeatMode @@ -353,12 +353,12 @@ class QKeyframeAnimation('QAbstractAnimation'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def endModeChanged(self, endMode: 'QKeyframeAnimation.RepeatMode') -> None: ... - def startModeChanged(self, startMode: 'QKeyframeAnimation.RepeatMode') -> None: ... - def targetNameChanged(self, name: str) -> None: ... - def easingChanged(self, easing: typing.Union[QtCore.QEasingCurve, QtCore.QEasingCurve.Type]) -> None: ... - def targetChanged(self, target: Qt3DCore.QTransform) -> None: ... - def framePositionsChanged(self, positions: typing.Iterable[float]) -> None: ... + endModeChanged: typing.ClassVar[QtCore.pyqtSignal] + startModeChanged: typing.ClassVar[QtCore.pyqtSignal] + targetNameChanged: typing.ClassVar[QtCore.pyqtSignal] + easingChanged: typing.ClassVar[QtCore.pyqtSignal] + targetChanged: typing.ClassVar[QtCore.pyqtSignal] + framePositionsChanged: typing.ClassVar[QtCore.pyqtSignal] def setEndMode(self, mode: 'QKeyframeAnimation.RepeatMode') -> None: ... def setStartMode(self, mode: 'QKeyframeAnimation.RepeatMode') -> None: ... def setTargetName(self, name: str) -> None: ... @@ -380,9 +380,9 @@ class QLerpClipBlend('QAbstractClipBlendNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def endClipChanged(self, endClip: 'QAbstractClipBlendNode') -> None: ... - def startClipChanged(self, startClip: 'QAbstractClipBlendNode') -> None: ... - def blendFactorChanged(self, blendFactor: float) -> None: ... + endClipChanged: typing.ClassVar[QtCore.pyqtSignal] + startClipChanged: typing.ClassVar[QtCore.pyqtSignal] + blendFactorChanged: typing.ClassVar[QtCore.pyqtSignal] def setEndClip(self, endClip: 'QAbstractClipBlendNode') -> None: ... def setStartClip(self, startClip: 'QAbstractClipBlendNode') -> None: ... def setBlendFactor(self, blendFactor: float) -> None: ... @@ -401,12 +401,12 @@ class QMorphingAnimation('QAbstractAnimation'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def easingChanged(self, easing: typing.Union[QtCore.QEasingCurve, QtCore.QEasingCurve.Type]) -> None: ... - def methodChanged(self, method: 'QMorphingAnimation.Method') -> None: ... - def targetNameChanged(self, name: str) -> None: ... - def targetChanged(self, target: Qt3DRender.QGeometryRenderer) -> None: ... - def interpolatorChanged(self, interpolator: float) -> None: ... - def targetPositionsChanged(self, targetPositions: typing.Iterable[float]) -> None: ... + easingChanged: typing.ClassVar[QtCore.pyqtSignal] + methodChanged: typing.ClassVar[QtCore.pyqtSignal] + targetNameChanged: typing.ClassVar[QtCore.pyqtSignal] + targetChanged: typing.ClassVar[QtCore.pyqtSignal] + interpolatorChanged: typing.ClassVar[QtCore.pyqtSignal] + targetPositionsChanged: typing.ClassVar[QtCore.pyqtSignal] def setEasing(self, easing: typing.Union[QtCore.QEasingCurve, QtCore.QEasingCurve.Type]) -> None: ... def setMethod(self, method: 'QMorphingAnimation.Method') -> None: ... def setTargetName(self, name: str) -> None: ... @@ -429,7 +429,7 @@ class QMorphTarget(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def attributeNamesChanged(self, attributeNames: typing.Iterable[str]) -> None: ... + attributeNamesChanged: typing.ClassVar[QtCore.pyqtSignal] @staticmethod def fromGeometry(geometry: Qt3DRender.QGeometry, attributes: typing.Iterable[str]) -> 'QMorphTarget': ... def removeAttribute(self, attribute: Qt3DRender.QAttribute) -> None: ... @@ -442,7 +442,7 @@ class QSkeletonMapping('QAbstractChannelMapping'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def skeletonChanged(self, skeleton: Qt3DCore.QAbstractSkeleton) -> None: ... + skeletonChanged: typing.ClassVar[QtCore.pyqtSignal] def setSkeleton(self, skeleton: Qt3DCore.QAbstractSkeleton) -> None: ... def skeleton(self) -> Qt3DCore.QAbstractSkeleton: ... @@ -450,10 +450,10 @@ class QVertexBlendAnimation('QAbstractAnimation'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def targetNameChanged(self, name: str) -> None: ... - def targetChanged(self, target: Qt3DRender.QGeometryRenderer) -> None: ... - def interpolatorChanged(self, interpolator: float) -> None: ... - def targetPositionsChanged(self, targetPositions: typing.Iterable[float]) -> None: ... + targetNameChanged: typing.ClassVar[QtCore.pyqtSignal] + targetChanged: typing.ClassVar[QtCore.pyqtSignal] + interpolatorChanged: typing.ClassVar[QtCore.pyqtSignal] + targetPositionsChanged: typing.ClassVar[QtCore.pyqtSignal] def setTargetName(self, name: str) -> None: ... def setTarget(self, target: Qt3DRender.QGeometryRenderer) -> None: ... def setTargetPositions(self, targetPositions: typing.Iterable[float]) -> None: ... diff --git a/PyQt5-stubs/Qt3DCore.pyi b/PyQt5-stubs/Qt3DCore.pyi index 66970665..80a70fb4 100644 --- a/PyQt5-stubs/Qt3DCore.pyi +++ b/PyQt5-stubs/Qt3DCore.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the Qt3DCore module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -40,6 +40,9 @@ PYQT_OPENGL_BOUND_ARRAY = typing.Union[typing.Sequence[int], class ChangeFlag(int): + def __or__ (self, other: 'ChangeFlag') -> 'ChangeFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'ChangeFlags': ... # type: ignore[override, misc] + NodeCreated = ... # type: ChangeFlag NodeDeleted = ... # type: ChangeFlag PropertyUpdated = ... # type: ChangeFlag @@ -115,7 +118,7 @@ class QNode(QtCore.QObject): def sendReply(self, command: 'QNodeCommand') -> None: ... def sendCommand(self, name: str, data: typing.Any = ..., replyTo: int = ...) -> int: ... - def defaultPropertyTrackingModeChanged(self, mode: 'QNode.PropertyTrackingMode') -> None: ... + defaultPropertyTrackingModeChanged: typing.ClassVar[QtCore.pyqtSignal] def setDefaultPropertyTrackingMode(self, mode: 'QNode.PropertyTrackingMode') -> None: ... def clearPropertyTrackings(self) -> None: ... def clearPropertyTracking(self, propertyName: str) -> None: ... @@ -124,9 +127,9 @@ class QNode(QtCore.QObject): def defaultPropertyTrackingMode(self) -> 'QNode.PropertyTrackingMode': ... def sceneChangeEvent(self, change: 'QSceneChange') -> None: ... def notifyObservers(self, change: 'QSceneChange') -> None: ... - def nodeDestroyed(self) -> None: ... - def enabledChanged(self, enabled: bool) -> None: ... - def parentChanged(self, parent: QtCore.QObject) -> None: ... + nodeDestroyed: typing.ClassVar[QtCore.pyqtSignal] + enabledChanged: typing.ClassVar[QtCore.pyqtSignal] + parentChanged: typing.ClassVar[QtCore.pyqtSignal] def setEnabled(self, isEnabled: bool) -> None: ... def setParent(self, parent: 'QNode') -> None: ... # type: ignore[override] def isEnabled(self) -> bool: ... @@ -139,16 +142,16 @@ class QNode(QtCore.QObject): class QAbstractSkeleton('QNode'): def sceneChangeEvent(self, change: 'QSceneChange') -> None: ... - def jointCountChanged(self, jointCount: int) -> None: ... + jointCountChanged: typing.ClassVar[QtCore.pyqtSignal] def jointCount(self) -> int: ... class QComponent('QNode'): def __init__(self, parent: typing.Optional['QNode'] = ...) -> None: ... - def removedFromEntity(self, entity: 'QEntity') -> None: ... - def addedToEntity(self, entity: 'QEntity') -> None: ... - def shareableChanged(self, isShareable: bool) -> None: ... + removedFromEntity: typing.ClassVar[QtCore.pyqtSignal] + addedToEntity: typing.ClassVar[QtCore.pyqtSignal] + shareableChanged: typing.ClassVar[QtCore.pyqtSignal] def setShareable(self, isShareable: bool) -> None: ... def entities(self) -> typing.List['QEntity']: ... def isShareable(self) -> bool: ... @@ -157,7 +160,7 @@ class QArmature('QComponent'): def __init__(self, parent: typing.Optional['QNode'] = ...) -> None: ... - def skeletonChanged(self, skeleton: 'QAbstractSkeleton') -> None: ... + skeletonChanged: typing.ClassVar[QtCore.pyqtSignal] def setSkeleton(self, skeleton: 'QAbstractSkeleton') -> None: ... def skeleton(self) -> 'QAbstractSkeleton': ... @@ -195,6 +198,9 @@ class QBackendNode(sip.simplewrapper): class QSceneChange(sip.simplewrapper): class DeliveryFlag(int): + def __or__ (self, other: 'QSceneChange.DeliveryFlag') -> 'QSceneChange.DeliveryFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSceneChange.DeliveryFlags': ... # type: ignore[override, misc] + BackendNodes = ... # type: QSceneChange.DeliveryFlag Nodes = ... # type: QSceneChange.DeliveryFlag DeliverToAll = ... # type: QSceneChange.DeliveryFlag @@ -211,12 +217,20 @@ class QSceneChange(sip.simplewrapper): def __init__(self, f: typing.Union['QSceneChange.DeliveryFlags', 'QSceneChange.DeliveryFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QSceneChange.DeliveryFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSceneChange.DeliveryFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSceneChange.DeliveryFlags', 'QSceneChange.DeliveryFlag', int]) -> 'QSceneChange.DeliveryFlags': ... + def __and__(self, other: typing.Union['QSceneChange.DeliveryFlags', 'QSceneChange.DeliveryFlag', int]) -> 'QSceneChange.DeliveryFlags': ... + def __xor__(self, other: typing.Union['QSceneChange.DeliveryFlags', 'QSceneChange.DeliveryFlag', int]) -> 'QSceneChange.DeliveryFlags': ... + def __ror__ (self, other: 'QSceneChange.DeliveryFlag') -> 'QSceneChange.DeliveryFlags': ... + def __rand__(self, other: 'QSceneChange.DeliveryFlag') -> 'QSceneChange.DeliveryFlags': ... + def __rxor__(self, other: 'QSceneChange.DeliveryFlag') -> 'QSceneChange.DeliveryFlags': ... def __init__(self, type: 'ChangeFlag', subjectId: 'QNodeId') -> None: ... @@ -273,14 +287,14 @@ class QJoint('QNode'): def __init__(self, parent: typing.Optional['QNode'] = ...) -> None: ... - def nameChanged(self, name: str) -> None: ... - def rotationZChanged(self, rotationZ: float) -> None: ... - def rotationYChanged(self, rotationY: float) -> None: ... - def rotationXChanged(self, rotationX: float) -> None: ... - def inverseBindMatrixChanged(self, inverseBindMatrix: QtGui.QMatrix4x4) -> None: ... - def translationChanged(self, translation: QtGui.QVector3D) -> None: ... - def rotationChanged(self, rotation: QtGui.QQuaternion) -> None: ... - def scaleChanged(self, scale: QtGui.QVector3D) -> None: ... + nameChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationZChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationYChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationXChanged: typing.ClassVar[QtCore.pyqtSignal] + inverseBindMatrixChanged: typing.ClassVar[QtCore.pyqtSignal] + translationChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationChanged: typing.ClassVar[QtCore.pyqtSignal] + scaleChanged: typing.ClassVar[QtCore.pyqtSignal] def setToIdentity(self) -> None: ... def setName(self, name: str) -> None: ... def setRotationZ(self, rotationZ: float) -> None: ... @@ -426,18 +440,26 @@ class ChangeFlags(sip.simplewrapper): def __init__(self, f: typing.Union['ChangeFlags', 'ChangeFlag']) -> None: ... @typing.overload def __init__(self, a0: 'ChangeFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'ChangeFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['ChangeFlags', 'ChangeFlag', int]) -> 'ChangeFlags': ... + def __and__(self, other: typing.Union['ChangeFlags', 'ChangeFlag', int]) -> 'ChangeFlags': ... + def __xor__(self, other: typing.Union['ChangeFlags', 'ChangeFlag', int]) -> 'ChangeFlags': ... + def __ror__ (self, other: 'ChangeFlag') -> 'ChangeFlags': ... + def __rand__(self, other: 'ChangeFlag') -> 'ChangeFlags': ... + def __rxor__(self, other: 'ChangeFlag') -> 'ChangeFlags': ... class QSkeleton('QAbstractSkeleton'): def __init__(self, parent: typing.Optional['QNode'] = ...) -> None: ... - def rootJointChanged(self, rootJoint: 'QJoint') -> None: ... + rootJointChanged: typing.ClassVar[QtCore.pyqtSignal] def setRootJoint(self, rootJoint: 'QJoint') -> None: ... def rootJoint(self) -> 'QJoint': ... @@ -458,10 +480,10 @@ class QSkeletonLoader('QAbstractSkeleton'): def __init__(self, source: QtCore.QUrl, parent: typing.Optional['QNode'] = ...) -> None: ... def sceneChangeEvent(self, change: 'QSceneChange') -> None: ... - def rootJointChanged(self, rootJoint: 'QJoint') -> None: ... - def createJointsEnabledChanged(self, createJointsEnabled: bool) -> None: ... - def statusChanged(self, status: 'QSkeletonLoader.Status') -> None: ... - def sourceChanged(self, source: QtCore.QUrl) -> None: ... + rootJointChanged: typing.ClassVar[QtCore.pyqtSignal] + createJointsEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] def setCreateJointsEnabled(self, enabled: bool) -> None: ... def setSource(self, source: QtCore.QUrl) -> None: ... def rootJoint(self) -> 'QJoint': ... @@ -474,16 +496,16 @@ class QTransform('QComponent'): def __init__(self, parent: typing.Optional['QNode'] = ...) -> None: ... def sceneChangeEvent(self, change: 'QSceneChange') -> None: ... - def worldMatrixChanged(self, worldMatrix: QtGui.QMatrix4x4) -> None: ... + worldMatrixChanged: typing.ClassVar[QtCore.pyqtSignal] def worldMatrix(self) -> QtGui.QMatrix4x4: ... - def rotationZChanged(self, rotationZ: float) -> None: ... - def rotationYChanged(self, rotationY: float) -> None: ... - def rotationXChanged(self, rotationX: float) -> None: ... - def matrixChanged(self) -> None: ... - def translationChanged(self, translation: QtGui.QVector3D) -> None: ... - def rotationChanged(self, rotation: QtGui.QQuaternion) -> None: ... - def scale3DChanged(self, scale: QtGui.QVector3D) -> None: ... - def scaleChanged(self, scale: float) -> None: ... + rotationZChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationYChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationXChanged: typing.ClassVar[QtCore.pyqtSignal] + matrixChanged: typing.ClassVar[QtCore.pyqtSignal] + translationChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationChanged: typing.ClassVar[QtCore.pyqtSignal] + scale3DChanged: typing.ClassVar[QtCore.pyqtSignal] + scaleChanged: typing.ClassVar[QtCore.pyqtSignal] def setRotationZ(self, rotationZ: float) -> None: ... def setRotationY(self, rotationY: float) -> None: ... def setRotationX(self, rotationX: float) -> None: ... diff --git a/PyQt5-stubs/Qt3DExtras.pyi b/PyQt5-stubs/Qt3DExtras.pyi index 1c3d4358..8f83e807 100644 --- a/PyQt5-stubs/Qt3DExtras.pyi +++ b/PyQt5-stubs/Qt3DExtras.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the Qt3DExtras module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -48,11 +48,11 @@ class QAbstractCameraController(Qt3DCore.QEntity): def mouseDevice(self) -> Qt3DInput.QMouseDevice: ... def keyboardDevice(self) -> Qt3DInput.QKeyboardDevice: ... - def decelerationChanged(self, deceleration: float) -> None: ... - def accelerationChanged(self, acceleration: float) -> None: ... - def lookSpeedChanged(self) -> None: ... - def linearSpeedChanged(self) -> None: ... - def cameraChanged(self) -> None: ... + decelerationChanged: typing.ClassVar[QtCore.pyqtSignal] + accelerationChanged: typing.ClassVar[QtCore.pyqtSignal] + lookSpeedChanged: typing.ClassVar[QtCore.pyqtSignal] + linearSpeedChanged: typing.ClassVar[QtCore.pyqtSignal] + cameraChanged: typing.ClassVar[QtCore.pyqtSignal] def setDeceleration(self, deceleration: float) -> None: ... def setAcceleration(self, acceleration: float) -> None: ... def setLookSpeed(self, lookSpeed: float) -> None: ... @@ -66,9 +66,9 @@ class QAbstractCameraController(Qt3DCore.QEntity): class QAbstractSpriteSheet(Qt3DCore.QNode): - def currentIndexChanged(self, currentIndex: int) -> None: ... - def textureTransformChanged(self, textureTransform: QtGui.QMatrix3x3) -> None: ... - def textureChanged(self, texture: Qt3DRender.QAbstractTexture) -> None: ... + currentIndexChanged: typing.ClassVar[QtCore.pyqtSignal] + textureTransformChanged: typing.ClassVar[QtCore.pyqtSignal] + textureChanged: typing.ClassVar[QtCore.pyqtSignal] def setCurrentIndex(self, currentIndex: int) -> None: ... def setTexture(self, texture: Qt3DRender.QAbstractTexture) -> None: ... def currentIndex(self) -> int: ... @@ -79,13 +79,13 @@ class QConeGeometry(Qt3DRender.QGeometry): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def lengthChanged(self, length: float) -> None: ... - def slicesChanged(self, slices: int) -> None: ... - def ringsChanged(self, rings: int) -> None: ... - def bottomRadiusChanged(self, bottomRadius: float) -> None: ... - def topRadiusChanged(self, topRadius: float) -> None: ... - def hasBottomEndcapChanged(self, hasBottomEndcap: bool) -> None: ... - def hasTopEndcapChanged(self, hasTopEndcap: bool) -> None: ... + lengthChanged: typing.ClassVar[QtCore.pyqtSignal] + slicesChanged: typing.ClassVar[QtCore.pyqtSignal] + ringsChanged: typing.ClassVar[QtCore.pyqtSignal] + bottomRadiusChanged: typing.ClassVar[QtCore.pyqtSignal] + topRadiusChanged: typing.ClassVar[QtCore.pyqtSignal] + hasBottomEndcapChanged: typing.ClassVar[QtCore.pyqtSignal] + hasTopEndcapChanged: typing.ClassVar[QtCore.pyqtSignal] def setLength(self, length: float) -> None: ... def setSlices(self, slices: int) -> None: ... def setRings(self, rings: int) -> None: ... @@ -111,13 +111,13 @@ class QConeMesh(Qt3DRender.QGeometryRenderer): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def lengthChanged(self, length: float) -> None: ... - def slicesChanged(self, slices: int) -> None: ... - def ringsChanged(self, rings: int) -> None: ... - def bottomRadiusChanged(self, bottomRadius: float) -> None: ... - def topRadiusChanged(self, topRadius: float) -> None: ... - def hasBottomEndcapChanged(self, hasBottomEndcap: bool) -> None: ... - def hasTopEndcapChanged(self, hasTopEndcap: bool) -> None: ... + lengthChanged: typing.ClassVar[QtCore.pyqtSignal] + slicesChanged: typing.ClassVar[QtCore.pyqtSignal] + ringsChanged: typing.ClassVar[QtCore.pyqtSignal] + bottomRadiusChanged: typing.ClassVar[QtCore.pyqtSignal] + topRadiusChanged: typing.ClassVar[QtCore.pyqtSignal] + hasBottomEndcapChanged: typing.ClassVar[QtCore.pyqtSignal] + hasTopEndcapChanged: typing.ClassVar[QtCore.pyqtSignal] def setLength(self, length: float) -> None: ... def setSlices(self, slices: int) -> None: ... def setRings(self, rings: int) -> None: ... @@ -137,12 +137,12 @@ class QCuboidGeometry(Qt3DRender.QGeometry): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def xyMeshResolutionChanged(self, xyMeshResolution: QtCore.QSize) -> None: ... - def xzMeshResolutionChanged(self, xzMeshResolution: QtCore.QSize) -> None: ... - def yzMeshResolutionChanged(self, yzMeshResolution: QtCore.QSize) -> None: ... - def zExtentChanged(self, zExtent: float) -> None: ... - def yExtentChanged(self, yExtent: float) -> None: ... - def xExtentChanged(self, xExtent: float) -> None: ... + xyMeshResolutionChanged: typing.ClassVar[QtCore.pyqtSignal] + xzMeshResolutionChanged: typing.ClassVar[QtCore.pyqtSignal] + yzMeshResolutionChanged: typing.ClassVar[QtCore.pyqtSignal] + zExtentChanged: typing.ClassVar[QtCore.pyqtSignal] + yExtentChanged: typing.ClassVar[QtCore.pyqtSignal] + xExtentChanged: typing.ClassVar[QtCore.pyqtSignal] def setXYMeshResolution(self, resolution: QtCore.QSize) -> None: ... def setXZMeshResolution(self, resolution: QtCore.QSize) -> None: ... def setYZMeshResolution(self, resolution: QtCore.QSize) -> None: ... @@ -167,12 +167,12 @@ class QCuboidMesh(Qt3DRender.QGeometryRenderer): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def xyMeshResolutionChanged(self, xyMeshResolution: QtCore.QSize) -> None: ... - def xzMeshResolutionChanged(self, xzMeshResolution: QtCore.QSize) -> None: ... - def yzMeshResolutionChanged(self, yzMeshResolution: QtCore.QSize) -> None: ... - def zExtentChanged(self, zExtent: float) -> None: ... - def yExtentChanged(self, yExtent: float) -> None: ... - def xExtentChanged(self, xExtent: float) -> None: ... + xyMeshResolutionChanged: typing.ClassVar[QtCore.pyqtSignal] + xzMeshResolutionChanged: typing.ClassVar[QtCore.pyqtSignal] + yzMeshResolutionChanged: typing.ClassVar[QtCore.pyqtSignal] + zExtentChanged: typing.ClassVar[QtCore.pyqtSignal] + yExtentChanged: typing.ClassVar[QtCore.pyqtSignal] + xExtentChanged: typing.ClassVar[QtCore.pyqtSignal] def setXYMeshResolution(self, resolution: QtCore.QSize) -> None: ... def setXZMeshResolution(self, resolution: QtCore.QSize) -> None: ... def setYZMeshResolution(self, resolution: QtCore.QSize) -> None: ... @@ -190,10 +190,10 @@ class QCylinderGeometry(Qt3DRender.QGeometry): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def lengthChanged(self, length: float) -> None: ... - def slicesChanged(self, slices: int) -> None: ... - def ringsChanged(self, rings: int) -> None: ... - def radiusChanged(self, radius: float) -> None: ... + lengthChanged: typing.ClassVar[QtCore.pyqtSignal] + slicesChanged: typing.ClassVar[QtCore.pyqtSignal] + ringsChanged: typing.ClassVar[QtCore.pyqtSignal] + radiusChanged: typing.ClassVar[QtCore.pyqtSignal] def setLength(self, length: float) -> None: ... def setRadius(self, radius: float) -> None: ... def setSlices(self, slices: int) -> None: ... @@ -213,10 +213,10 @@ class QCylinderMesh(Qt3DRender.QGeometryRenderer): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def lengthChanged(self, length: float) -> None: ... - def slicesChanged(self, slices: int) -> None: ... - def ringsChanged(self, rings: int) -> None: ... - def radiusChanged(self, radius: float) -> None: ... + lengthChanged: typing.ClassVar[QtCore.pyqtSignal] + slicesChanged: typing.ClassVar[QtCore.pyqtSignal] + ringsChanged: typing.ClassVar[QtCore.pyqtSignal] + radiusChanged: typing.ClassVar[QtCore.pyqtSignal] def setLength(self, length: float) -> None: ... def setRadius(self, radius: float) -> None: ... def setSlices(self, slices: int) -> None: ... @@ -230,11 +230,11 @@ class QDiffuseMapMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def textureScaleChanged(self, textureScale: float) -> None: ... - def shininessChanged(self, shininess: float) -> None: ... - def specularChanged(self, specular: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def diffuseChanged(self, diffuse: Qt3DRender.QAbstractTexture) -> None: ... - def ambientChanged(self, ambient: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + textureScaleChanged: typing.ClassVar[QtCore.pyqtSignal] + shininessChanged: typing.ClassVar[QtCore.pyqtSignal] + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + diffuseChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientChanged: typing.ClassVar[QtCore.pyqtSignal] def setTextureScale(self, textureScale: float) -> None: ... def setDiffuse(self, diffuse: Qt3DRender.QAbstractTexture) -> None: ... def setShininess(self, shininess: float) -> None: ... @@ -250,11 +250,11 @@ class QDiffuseSpecularMapMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def textureScaleChanged(self, textureScale: float) -> None: ... - def shininessChanged(self, shininess: float) -> None: ... - def specularChanged(self, specular: Qt3DRender.QAbstractTexture) -> None: ... - def diffuseChanged(self, diffuse: Qt3DRender.QAbstractTexture) -> None: ... - def ambientChanged(self, ambient: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + textureScaleChanged: typing.ClassVar[QtCore.pyqtSignal] + shininessChanged: typing.ClassVar[QtCore.pyqtSignal] + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + diffuseChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientChanged: typing.ClassVar[QtCore.pyqtSignal] def setTextureScale(self, textureScale: float) -> None: ... def setShininess(self, shininess: float) -> None: ... def setSpecular(self, specular: Qt3DRender.QAbstractTexture) -> None: ... @@ -270,13 +270,13 @@ class QDiffuseSpecularMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def alphaBlendingEnabledChanged(self, enabled: bool) -> None: ... - def textureScaleChanged(self, textureScale: float) -> None: ... - def normalChanged(self, normal: typing.Any) -> None: ... - def shininessChanged(self, shininess: float) -> None: ... - def specularChanged(self, specular: typing.Any) -> None: ... - def diffuseChanged(self, diffuse: typing.Any) -> None: ... - def ambientChanged(self, ambient: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + alphaBlendingEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + textureScaleChanged: typing.ClassVar[QtCore.pyqtSignal] + normalChanged: typing.ClassVar[QtCore.pyqtSignal] + shininessChanged: typing.ClassVar[QtCore.pyqtSignal] + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + diffuseChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientChanged: typing.ClassVar[QtCore.pyqtSignal] def setAlphaBlendingEnabled(self, enabled: bool) -> None: ... def setTextureScale(self, textureScale: float) -> None: ... def setNormal(self, normal: typing.Any) -> None: ... @@ -296,9 +296,9 @@ class QExtrudedTextGeometry(Qt3DRender.QGeometry): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def depthChanged(self, extrusionLength: float) -> None: ... - def fontChanged(self, font: QtGui.QFont) -> None: ... - def textChanged(self, text: str) -> None: ... + depthChanged: typing.ClassVar[QtCore.pyqtSignal] + fontChanged: typing.ClassVar[QtCore.pyqtSignal] + textChanged: typing.ClassVar[QtCore.pyqtSignal] def setDepth(self, extrusionLength: float) -> None: ... def setFont(self, font: QtGui.QFont) -> None: ... def setText(self, text: str) -> None: ... @@ -313,9 +313,9 @@ class QExtrudedTextMesh(Qt3DRender.QGeometryRenderer): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def depthChanged(self, depth: float) -> None: ... - def fontChanged(self, font: QtGui.QFont) -> None: ... - def textChanged(self, text: str) -> None: ... + depthChanged: typing.ClassVar[QtCore.pyqtSignal] + fontChanged: typing.ClassVar[QtCore.pyqtSignal] + textChanged: typing.ClassVar[QtCore.pyqtSignal] def setDepth(self, depth: float) -> None: ... def setFont(self, font: QtGui.QFont) -> None: ... def setText(self, text: str) -> None: ... @@ -331,23 +331,23 @@ class QForwardRenderer(Qt3DRender.QTechniqueFilter): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def showDebugOverlayChanged(self, showDebugOverlay: bool) -> None: ... + showDebugOverlayChanged: typing.ClassVar[QtCore.pyqtSignal] def setShowDebugOverlay(self, showDebugOverlay: bool) -> None: ... def showDebugOverlay(self) -> bool: ... - def buffersToClearChanged(self, a0: Qt3DRender.QClearBuffers.BufferType) -> None: ... + buffersToClearChanged: typing.ClassVar[QtCore.pyqtSignal] def setBuffersToClear(self, a0: Qt3DRender.QClearBuffers.BufferType) -> None: ... def buffersToClear(self) -> Qt3DRender.QClearBuffers.BufferType: ... - def gammaChanged(self, gamma: float) -> None: ... - def frustumCullingEnabledChanged(self, enabled: bool) -> None: ... + gammaChanged: typing.ClassVar[QtCore.pyqtSignal] + frustumCullingEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] def setGamma(self, gamma: float) -> None: ... def setFrustumCullingEnabled(self, enabled: bool) -> None: ... def gamma(self) -> float: ... def isFrustumCullingEnabled(self) -> bool: ... - def externalRenderTargetSizeChanged(self, size: QtCore.QSize) -> None: ... - def surfaceChanged(self, surface: QtCore.QObject) -> None: ... - def cameraChanged(self, camera: Qt3DCore.QEntity) -> None: ... - def clearColorChanged(self, clearColor: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def viewportRectChanged(self, viewportRect: QtCore.QRectF) -> None: ... + externalRenderTargetSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + surfaceChanged: typing.ClassVar[QtCore.pyqtSignal] + cameraChanged: typing.ClassVar[QtCore.pyqtSignal] + clearColorChanged: typing.ClassVar[QtCore.pyqtSignal] + viewportRectChanged: typing.ClassVar[QtCore.pyqtSignal] def setExternalRenderTargetSize(self, size: QtCore.QSize) -> None: ... def setSurface(self, surface: QtCore.QObject) -> None: ... def setCamera(self, camera: Qt3DCore.QEntity) -> None: ... @@ -363,13 +363,13 @@ class QGoochMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def shininessChanged(self, shininess: float) -> None: ... - def betaChanged(self, beta: float) -> None: ... - def alphaChanged(self, alpha: float) -> None: ... - def warmChanged(self, warm: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def coolChanged(self, cool: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def specularChanged(self, specular: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def diffuseChanged(self, diffuse: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + shininessChanged: typing.ClassVar[QtCore.pyqtSignal] + betaChanged: typing.ClassVar[QtCore.pyqtSignal] + alphaChanged: typing.ClassVar[QtCore.pyqtSignal] + warmChanged: typing.ClassVar[QtCore.pyqtSignal] + coolChanged: typing.ClassVar[QtCore.pyqtSignal] + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + diffuseChanged: typing.ClassVar[QtCore.pyqtSignal] def setShininess(self, shininess: float) -> None: ... def setBeta(self, beta: float) -> None: ... def setAlpha(self, alpha: float) -> None: ... @@ -389,12 +389,12 @@ class QMetalRoughMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def textureScaleChanged(self, textureScale: float) -> None: ... - def normalChanged(self, normal: typing.Any) -> None: ... - def ambientOcclusionChanged(self, ambientOcclusion: typing.Any) -> None: ... - def roughnessChanged(self, roughness: typing.Any) -> None: ... - def metalnessChanged(self, metalness: typing.Any) -> None: ... - def baseColorChanged(self, baseColor: typing.Any) -> None: ... + textureScaleChanged: typing.ClassVar[QtCore.pyqtSignal] + normalChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientOcclusionChanged: typing.ClassVar[QtCore.pyqtSignal] + roughnessChanged: typing.ClassVar[QtCore.pyqtSignal] + metalnessChanged: typing.ClassVar[QtCore.pyqtSignal] + baseColorChanged: typing.ClassVar[QtCore.pyqtSignal] def setTextureScale(self, textureScale: float) -> None: ... def setNormal(self, normal: typing.Any) -> None: ... def setAmbientOcclusion(self, ambientOcclusion: typing.Any) -> None: ... @@ -412,11 +412,11 @@ class QMorphPhongMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def interpolatorChanged(self, interpolator: float) -> None: ... - def shininessChanged(self, shininess: float) -> None: ... - def specularChanged(self, specular: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def diffuseChanged(self, diffuse: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def ambientChanged(self, ambient: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + interpolatorChanged: typing.ClassVar[QtCore.pyqtSignal] + shininessChanged: typing.ClassVar[QtCore.pyqtSignal] + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + diffuseChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientChanged: typing.ClassVar[QtCore.pyqtSignal] def setInterpolator(self, interpolator: float) -> None: ... def setShininess(self, shininess: float) -> None: ... def setSpecular(self, specular: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... @@ -432,12 +432,12 @@ class QNormalDiffuseMapMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def textureScaleChanged(self, textureScale: float) -> None: ... - def shininessChanged(self, shininess: float) -> None: ... - def specularChanged(self, specular: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def normalChanged(self, normal: Qt3DRender.QAbstractTexture) -> None: ... - def diffuseChanged(self, diffuse: Qt3DRender.QAbstractTexture) -> None: ... - def ambientChanged(self, ambient: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + textureScaleChanged: typing.ClassVar[QtCore.pyqtSignal] + shininessChanged: typing.ClassVar[QtCore.pyqtSignal] + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + normalChanged: typing.ClassVar[QtCore.pyqtSignal] + diffuseChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientChanged: typing.ClassVar[QtCore.pyqtSignal] def setTextureScale(self, textureScale: float) -> None: ... def setShininess(self, shininess: float) -> None: ... def setNormal(self, normal: Qt3DRender.QAbstractTexture) -> None: ... @@ -459,12 +459,12 @@ class QNormalDiffuseSpecularMapMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def textureScaleChanged(self, textureScale: float) -> None: ... - def shininessChanged(self, shininess: float) -> None: ... - def specularChanged(self, specular: Qt3DRender.QAbstractTexture) -> None: ... - def normalChanged(self, normal: Qt3DRender.QAbstractTexture) -> None: ... - def diffuseChanged(self, diffuse: Qt3DRender.QAbstractTexture) -> None: ... - def ambientChanged(self, ambient: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + textureScaleChanged: typing.ClassVar[QtCore.pyqtSignal] + shininessChanged: typing.ClassVar[QtCore.pyqtSignal] + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + normalChanged: typing.ClassVar[QtCore.pyqtSignal] + diffuseChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientChanged: typing.ClassVar[QtCore.pyqtSignal] def setTextureScale(self, textureScale: float) -> None: ... def setShininess(self, shininess: float) -> None: ... def setSpecular(self, specular: Qt3DRender.QAbstractTexture) -> None: ... @@ -482,7 +482,7 @@ class QOrbitCameraController('QAbstractCameraController'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def zoomInLimitChanged(self) -> None: ... + zoomInLimitChanged: typing.ClassVar[QtCore.pyqtSignal] def setZoomInLimit(self, zoomInLimit: float) -> None: ... def zoomInLimit(self) -> float: ... @@ -494,11 +494,11 @@ class QPhongAlphaMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def blendFunctionArgChanged(self, blendFunctionArg: Qt3DRender.QBlendEquation.BlendFunction) -> None: ... - def destinationAlphaArgChanged(self, destinationAlphaArg: Qt3DRender.QBlendEquationArguments.Blending) -> None: ... - def sourceAlphaArgChanged(self, sourceAlphaArg: Qt3DRender.QBlendEquationArguments.Blending) -> None: ... - def destinationRgbArgChanged(self, destinationRgbArg: Qt3DRender.QBlendEquationArguments.Blending) -> None: ... - def sourceRgbArgChanged(self, sourceRgbArg: Qt3DRender.QBlendEquationArguments.Blending) -> None: ... + blendFunctionArgChanged: typing.ClassVar[QtCore.pyqtSignal] + destinationAlphaArgChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceAlphaArgChanged: typing.ClassVar[QtCore.pyqtSignal] + destinationRgbArgChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceRgbArgChanged: typing.ClassVar[QtCore.pyqtSignal] def setBlendFunctionArg(self, blendFunctionArg: Qt3DRender.QBlendEquation.BlendFunction) -> None: ... def setDestinationAlphaArg(self, destinationAlphaArg: Qt3DRender.QBlendEquationArguments.Blending) -> None: ... def setSourceAlphaArg(self, sourceAlphaArg: Qt3DRender.QBlendEquationArguments.Blending) -> None: ... @@ -509,11 +509,11 @@ class QPhongAlphaMaterial(Qt3DRender.QMaterial): def sourceAlphaArg(self) -> Qt3DRender.QBlendEquationArguments.Blending: ... def destinationRgbArg(self) -> Qt3DRender.QBlendEquationArguments.Blending: ... def sourceRgbArg(self) -> Qt3DRender.QBlendEquationArguments.Blending: ... - def alphaChanged(self, alpha: float) -> None: ... - def shininessChanged(self, shininess: float) -> None: ... - def specularChanged(self, specular: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def diffuseChanged(self, diffuse: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def ambientChanged(self, ambient: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + alphaChanged: typing.ClassVar[QtCore.pyqtSignal] + shininessChanged: typing.ClassVar[QtCore.pyqtSignal] + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + diffuseChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientChanged: typing.ClassVar[QtCore.pyqtSignal] def setAlpha(self, alpha: float) -> None: ... def setShininess(self, shininess: float) -> None: ... def setSpecular(self, specular: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... @@ -529,10 +529,10 @@ class QPhongMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def shininessChanged(self, shininess: float) -> None: ... - def specularChanged(self, specular: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def diffuseChanged(self, diffuse: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def ambientChanged(self, ambient: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + shininessChanged: typing.ClassVar[QtCore.pyqtSignal] + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + diffuseChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientChanged: typing.ClassVar[QtCore.pyqtSignal] def setShininess(self, shininess: float) -> None: ... def setSpecular(self, specular: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... def setDiffuse(self, diffuse: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... @@ -546,12 +546,12 @@ class QPlaneGeometry(Qt3DRender.QGeometry): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def mirroredChanged(self, mirrored: bool) -> None: ... + mirroredChanged: typing.ClassVar[QtCore.pyqtSignal] def setMirrored(self, mirrored: bool) -> None: ... def mirrored(self) -> bool: ... - def heightChanged(self, height: float) -> None: ... - def widthChanged(self, width: float) -> None: ... - def resolutionChanged(self, resolution: QtCore.QSize) -> None: ... + heightChanged: typing.ClassVar[QtCore.pyqtSignal] + widthChanged: typing.ClassVar[QtCore.pyqtSignal] + resolutionChanged: typing.ClassVar[QtCore.pyqtSignal] def setHeight(self, height: float) -> None: ... def setWidth(self, width: float) -> None: ... def setResolution(self, resolution: QtCore.QSize) -> None: ... @@ -570,12 +570,12 @@ class QPlaneMesh(Qt3DRender.QGeometryRenderer): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def mirroredChanged(self, mirrored: bool) -> None: ... + mirroredChanged: typing.ClassVar[QtCore.pyqtSignal] def setMirrored(self, mirrored: bool) -> None: ... def mirrored(self) -> bool: ... - def heightChanged(self, height: float) -> None: ... - def widthChanged(self, width: float) -> None: ... - def meshResolutionChanged(self, meshResolution: QtCore.QSize) -> None: ... + heightChanged: typing.ClassVar[QtCore.pyqtSignal] + widthChanged: typing.ClassVar[QtCore.pyqtSignal] + meshResolutionChanged: typing.ClassVar[QtCore.pyqtSignal] def setMeshResolution(self, resolution: QtCore.QSize) -> None: ... def setHeight(self, height: float) -> None: ... def setWidth(self, width: float) -> None: ... @@ -587,11 +587,11 @@ class QSkyboxEntity(Qt3DCore.QEntity): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def gammaCorrectEnabledChanged(self, enabled: bool) -> None: ... - def baseNameChanged(self, path: str) -> None: ... + gammaCorrectEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + baseNameChanged: typing.ClassVar[QtCore.pyqtSignal] def setGammaCorrectEnabled(self, enabled: bool) -> None: ... def isGammaCorrectEnabled(self) -> bool: ... - def extensionChanged(self, extension: str) -> None: ... + extensionChanged: typing.ClassVar[QtCore.pyqtSignal] def extension(self) -> str: ... def setExtension(self, extension: str) -> None: ... def baseName(self) -> str: ... @@ -601,10 +601,10 @@ class QSphereGeometry(Qt3DRender.QGeometry): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def generateTangentsChanged(self, generateTangents: bool) -> None: ... - def slicesChanged(self, slices: int) -> None: ... - def ringsChanged(self, rings: int) -> None: ... - def radiusChanged(self, radius: float) -> None: ... + generateTangentsChanged: typing.ClassVar[QtCore.pyqtSignal] + slicesChanged: typing.ClassVar[QtCore.pyqtSignal] + ringsChanged: typing.ClassVar[QtCore.pyqtSignal] + radiusChanged: typing.ClassVar[QtCore.pyqtSignal] def setGenerateTangents(self, gen: bool) -> None: ... def setRadius(self, radius: float) -> None: ... def setSlices(self, slices: int) -> None: ... @@ -625,10 +625,10 @@ class QSphereMesh(Qt3DRender.QGeometryRenderer): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def generateTangentsChanged(self, generateTangents: bool) -> None: ... - def slicesChanged(self, slices: int) -> None: ... - def ringsChanged(self, rings: int) -> None: ... - def radiusChanged(self, radius: float) -> None: ... + generateTangentsChanged: typing.ClassVar[QtCore.pyqtSignal] + slicesChanged: typing.ClassVar[QtCore.pyqtSignal] + ringsChanged: typing.ClassVar[QtCore.pyqtSignal] + radiusChanged: typing.ClassVar[QtCore.pyqtSignal] def setGenerateTangents(self, gen: bool) -> None: ... def setRadius(self, radius: float) -> None: ... def setSlices(self, slices: int) -> None: ... @@ -642,8 +642,8 @@ class QSpriteGrid('QAbstractSpriteSheet'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def columnsChanged(self, columns: int) -> None: ... - def rowsChanged(self, rows: int) -> None: ... + columnsChanged: typing.ClassVar[QtCore.pyqtSignal] + rowsChanged: typing.ClassVar[QtCore.pyqtSignal] def setColumns(self, columns: int) -> None: ... def setRows(self, rows: int) -> None: ... def columns(self) -> int: ... @@ -653,7 +653,7 @@ class QSpriteSheet('QAbstractSpriteSheet'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def spritesChanged(self, sprites: typing.Iterable['QSpriteSheetItem']) -> None: ... + spritesChanged: typing.ClassVar[QtCore.pyqtSignal] def setSprites(self, sprites: typing.Iterable['QSpriteSheetItem']) -> None: ... def removeSprite(self, sprite: 'QSpriteSheetItem') -> None: ... @typing.overload @@ -666,10 +666,10 @@ class QSpriteSheetItem(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def heightChanged(self, height: int) -> None: ... - def widthChanged(self, width: int) -> None: ... - def yChanged(self, y: int) -> None: ... - def xChanged(self, x: int) -> None: ... + heightChanged: typing.ClassVar[QtCore.pyqtSignal] + widthChanged: typing.ClassVar[QtCore.pyqtSignal] + yChanged: typing.ClassVar[QtCore.pyqtSignal] + xChanged: typing.ClassVar[QtCore.pyqtSignal] def setHeight(self, height: int) -> None: ... def setWidth(self, width: int) -> None: ... def setY(self, y: int) -> None: ... @@ -701,11 +701,11 @@ class QText2DEntity(Qt3DCore.QEntity): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def heightChanged(self, height: float) -> None: ... - def widthChanged(self, width: float) -> None: ... - def textChanged(self, text: str) -> None: ... - def colorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def fontChanged(self, font: QtGui.QFont) -> None: ... + heightChanged: typing.ClassVar[QtCore.pyqtSignal] + widthChanged: typing.ClassVar[QtCore.pyqtSignal] + textChanged: typing.ClassVar[QtCore.pyqtSignal] + colorChanged: typing.ClassVar[QtCore.pyqtSignal] + fontChanged: typing.ClassVar[QtCore.pyqtSignal] def setHeight(self, height: float) -> None: ... def setWidth(self, width: float) -> None: ... def height(self) -> float: ... @@ -721,17 +721,17 @@ class QTexturedMetalRoughMaterial('QMetalRoughMaterial'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def normalChanged(self, normal: typing.Any) -> None: ... - def ambientOcclusionChanged(self, ambientOcclusion: typing.Any) -> None: ... + normalChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientOcclusionChanged: typing.ClassVar[QtCore.pyqtSignal] class QTextureMaterial(Qt3DRender.QMaterial): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def alphaBlendingEnabledChanged(self, enabled: bool) -> None: ... - def textureTransformChanged(self, textureTransform: QtGui.QMatrix3x3) -> None: ... - def textureOffsetChanged(self, textureOffset: QtGui.QVector2D) -> None: ... - def textureChanged(self, texture: Qt3DRender.QAbstractTexture) -> None: ... + alphaBlendingEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + textureTransformChanged: typing.ClassVar[QtCore.pyqtSignal] + textureOffsetChanged: typing.ClassVar[QtCore.pyqtSignal] + textureChanged: typing.ClassVar[QtCore.pyqtSignal] def setAlphaBlendingEnabled(self, enabled: bool) -> None: ... def setTextureTransform(self, matrix: QtGui.QMatrix3x3) -> None: ... def setTextureOffset(self, textureOffset: QtGui.QVector2D) -> None: ... @@ -745,10 +745,10 @@ class QTorusGeometry(Qt3DRender.QGeometry): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def minorRadiusChanged(self, minorRadius: float) -> None: ... - def slicesChanged(self, slices: int) -> None: ... - def ringsChanged(self, rings: int) -> None: ... - def radiusChanged(self, radius: float) -> None: ... + minorRadiusChanged: typing.ClassVar[QtCore.pyqtSignal] + slicesChanged: typing.ClassVar[QtCore.pyqtSignal] + ringsChanged: typing.ClassVar[QtCore.pyqtSignal] + radiusChanged: typing.ClassVar[QtCore.pyqtSignal] def setMinorRadius(self, minorRadius: float) -> None: ... def setRadius(self, radius: float) -> None: ... def setSlices(self, slices: int) -> None: ... @@ -768,10 +768,10 @@ class QTorusMesh(Qt3DRender.QGeometryRenderer): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def minorRadiusChanged(self, minorRadius: float) -> None: ... - def slicesChanged(self, slices: int) -> None: ... - def ringsChanged(self, rings: int) -> None: ... - def radiusChanged(self, radius: float) -> None: ... + minorRadiusChanged: typing.ClassVar[QtCore.pyqtSignal] + slicesChanged: typing.ClassVar[QtCore.pyqtSignal] + ringsChanged: typing.ClassVar[QtCore.pyqtSignal] + radiusChanged: typing.ClassVar[QtCore.pyqtSignal] def setMinorRadius(self, minorRadius: float) -> None: ... def setRadius(self, radius: float) -> None: ... def setSlices(self, slices: int) -> None: ... diff --git a/PyQt5-stubs/Qt3DInput.pyi b/PyQt5-stubs/Qt3DInput.pyi index 5c6a8256..4fc5806d 100644 --- a/PyQt5-stubs/Qt3DInput.pyi +++ b/PyQt5-stubs/Qt3DInput.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the Qt3DInput module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -44,7 +44,7 @@ class QAbstractActionInput(Qt3DCore.QNode): ... class QAbstractAxisInput(Qt3DCore.QNode): - def sourceDeviceChanged(self, sourceDevice: 'QAbstractPhysicalDevice') -> None: ... + sourceDeviceChanged: typing.ClassVar[QtCore.pyqtSignal] def setSourceDevice(self, sourceDevice: 'QAbstractPhysicalDevice') -> None: ... def sourceDevice(self) -> 'QAbstractPhysicalDevice': ... @@ -67,7 +67,7 @@ class QAction(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def activeChanged(self, isActive: bool) -> None: ... + activeChanged: typing.ClassVar[QtCore.pyqtSignal] def inputs(self) -> typing.List['QAbstractActionInput']: ... def removeInput(self, input: 'QAbstractActionInput') -> None: ... def addInput(self, input: 'QAbstractActionInput') -> None: ... @@ -77,8 +77,8 @@ class QActionInput('QAbstractActionInput'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def buttonsChanged(self, buttons: typing.Iterable[int]) -> None: ... - def sourceDeviceChanged(self, sourceDevice: 'QAbstractPhysicalDevice') -> None: ... + buttonsChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceDeviceChanged: typing.ClassVar[QtCore.pyqtSignal] def setButtons(self, buttons: typing.Iterable[int]) -> None: ... def setSourceDevice(self, sourceDevice: 'QAbstractPhysicalDevice') -> None: ... def buttons(self) -> typing.List[int]: ... @@ -88,7 +88,7 @@ class QAnalogAxisInput('QAbstractAxisInput'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def axisChanged(self, axis: int) -> None: ... + axisChanged: typing.ClassVar[QtCore.pyqtSignal] def setAxis(self, axis: int) -> None: ... def axis(self) -> int: ... @@ -97,7 +97,7 @@ class QAxis(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def valueChanged(self, value: float) -> None: ... + valueChanged: typing.ClassVar[QtCore.pyqtSignal] def value(self) -> float: ... def inputs(self) -> typing.List['QAbstractAxisInput']: ... def removeInput(self, input: 'QAbstractAxisInput') -> None: ... @@ -115,11 +115,11 @@ class QAxisAccumulator(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def scaleChanged(self, scale: float) -> None: ... - def velocityChanged(self, value: float) -> None: ... - def valueChanged(self, value: float) -> None: ... - def sourceAxisTypeChanged(self, sourceAxisType: 'QAxisAccumulator.SourceAxisType') -> None: ... - def sourceAxisChanged(self, sourceAxis: 'QAxis') -> None: ... + scaleChanged: typing.ClassVar[QtCore.pyqtSignal] + velocityChanged: typing.ClassVar[QtCore.pyqtSignal] + valueChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceAxisTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceAxisChanged: typing.ClassVar[QtCore.pyqtSignal] def setScale(self, scale: float) -> None: ... def setSourceAxisType(self, sourceAxisType: 'QAxisAccumulator.SourceAxisType') -> None: ... def setSourceAxis(self, sourceAxis: 'QAxis') -> None: ... @@ -133,9 +133,9 @@ class QAxisSetting(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def smoothChanged(self, smooth: bool) -> None: ... - def axesChanged(self, axes: typing.Iterable[int]) -> None: ... - def deadZoneRadiusChanged(self, deadZoneRadius: float) -> None: ... + smoothChanged: typing.ClassVar[QtCore.pyqtSignal] + axesChanged: typing.ClassVar[QtCore.pyqtSignal] + deadZoneRadiusChanged: typing.ClassVar[QtCore.pyqtSignal] def setSmoothEnabled(self, enabled: bool) -> None: ... def setAxes(self, axes: typing.Iterable[int]) -> None: ... def setDeadZoneRadius(self, deadZoneRadius: float) -> None: ... @@ -147,10 +147,10 @@ class QButtonAxisInput('QAbstractAxisInput'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def decelerationChanged(self, deceleration: float) -> None: ... - def accelerationChanged(self, acceleration: float) -> None: ... - def buttonsChanged(self, buttons: typing.Iterable[int]) -> None: ... - def scaleChanged(self, scale: float) -> None: ... + decelerationChanged: typing.ClassVar[QtCore.pyqtSignal] + accelerationChanged: typing.ClassVar[QtCore.pyqtSignal] + buttonsChanged: typing.ClassVar[QtCore.pyqtSignal] + scaleChanged: typing.ClassVar[QtCore.pyqtSignal] def setDeceleration(self, deceleration: float) -> None: ... def setAcceleration(self, acceleration: float) -> None: ... def setButtons(self, buttons: typing.Iterable[int]) -> None: ... @@ -171,7 +171,7 @@ class QInputChord('QAbstractActionInput'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def timeoutChanged(self, timeout: int) -> None: ... + timeoutChanged: typing.ClassVar[QtCore.pyqtSignal] def setTimeout(self, timeout: int) -> None: ... def chords(self) -> typing.List['QAbstractActionInput']: ... def removeChord(self, input: 'QAbstractActionInput') -> None: ... @@ -182,8 +182,8 @@ class QInputSequence('QAbstractActionInput'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def buttonIntervalChanged(self, buttonInterval: int) -> None: ... - def timeoutChanged(self, timeout: int) -> None: ... + buttonIntervalChanged: typing.ClassVar[QtCore.pyqtSignal] + timeoutChanged: typing.ClassVar[QtCore.pyqtSignal] def setButtonInterval(self, buttonInterval: int) -> None: ... def setTimeout(self, timeout: int) -> None: ... def sequences(self) -> typing.List['QAbstractActionInput']: ... @@ -196,7 +196,7 @@ class QInputSettings(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def eventSourceChanged(self, a0: QtCore.QObject) -> None: ... + eventSourceChanged: typing.ClassVar[QtCore.pyqtSignal] def setEventSource(self, eventSource: QtCore.QObject) -> None: ... def eventSource(self) -> QtCore.QObject: ... @@ -204,7 +204,7 @@ class QKeyboardDevice('QAbstractPhysicalDevice'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def activeInputChanged(self, activeInput: 'QKeyboardHandler') -> None: ... + activeInputChanged: typing.ClassVar[QtCore.pyqtSignal] def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... def buttonIdentifier(self, name: str) -> int: ... def axisIdentifier(self, name: str) -> int: ... @@ -219,48 +219,48 @@ class QKeyboardHandler(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def released(self, event: 'QKeyEvent') -> None: ... - def pressed(self, event: 'QKeyEvent') -> None: ... - def volumeDownPressed(self, event: 'QKeyEvent') -> None: ... - def volumeUpPressed(self, event: 'QKeyEvent') -> None: ... - def menuPressed(self, event: 'QKeyEvent') -> None: ... - def flipPressed(self, event: 'QKeyEvent') -> None: ... - def hangupPressed(self, event: 'QKeyEvent') -> None: ... - def callPressed(self, event: 'QKeyEvent') -> None: ... - def context4Pressed(self, event: 'QKeyEvent') -> None: ... - def context3Pressed(self, event: 'QKeyEvent') -> None: ... - def context2Pressed(self, event: 'QKeyEvent') -> None: ... - def context1Pressed(self, event: 'QKeyEvent') -> None: ... - def noPressed(self, event: 'QKeyEvent') -> None: ... - def yesPressed(self, event: 'QKeyEvent') -> None: ... - def selectPressed(self, event: 'QKeyEvent') -> None: ... - def cancelPressed(self, event: 'QKeyEvent') -> None: ... - def backPressed(self, event: 'QKeyEvent') -> None: ... - def spacePressed(self, event: 'QKeyEvent') -> None: ... - def deletePressed(self, event: 'QKeyEvent') -> None: ... - def enterPressed(self, event: 'QKeyEvent') -> None: ... - def returnPressed(self, event: 'QKeyEvent') -> None: ... - def escapePressed(self, event: 'QKeyEvent') -> None: ... - def numberSignPressed(self, event: 'QKeyEvent') -> None: ... - def asteriskPressed(self, event: 'QKeyEvent') -> None: ... - def backtabPressed(self, event: 'QKeyEvent') -> None: ... - def tabPressed(self, event: 'QKeyEvent') -> None: ... - def downPressed(self, event: 'QKeyEvent') -> None: ... - def upPressed(self, event: 'QKeyEvent') -> None: ... - def rightPressed(self, event: 'QKeyEvent') -> None: ... - def leftPressed(self, event: 'QKeyEvent') -> None: ... - def digit9Pressed(self, event: 'QKeyEvent') -> None: ... - def digit8Pressed(self, event: 'QKeyEvent') -> None: ... - def digit7Pressed(self, event: 'QKeyEvent') -> None: ... - def digit6Pressed(self, event: 'QKeyEvent') -> None: ... - def digit5Pressed(self, event: 'QKeyEvent') -> None: ... - def digit4Pressed(self, event: 'QKeyEvent') -> None: ... - def digit3Pressed(self, event: 'QKeyEvent') -> None: ... - def digit2Pressed(self, event: 'QKeyEvent') -> None: ... - def digit1Pressed(self, event: 'QKeyEvent') -> None: ... - def digit0Pressed(self, event: 'QKeyEvent') -> None: ... - def focusChanged(self, focus: bool) -> None: ... - def sourceDeviceChanged(self, keyboardDevice: 'QKeyboardDevice') -> None: ... + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + volumeDownPressed: typing.ClassVar[QtCore.pyqtSignal] + volumeUpPressed: typing.ClassVar[QtCore.pyqtSignal] + menuPressed: typing.ClassVar[QtCore.pyqtSignal] + flipPressed: typing.ClassVar[QtCore.pyqtSignal] + hangupPressed: typing.ClassVar[QtCore.pyqtSignal] + callPressed: typing.ClassVar[QtCore.pyqtSignal] + context4Pressed: typing.ClassVar[QtCore.pyqtSignal] + context3Pressed: typing.ClassVar[QtCore.pyqtSignal] + context2Pressed: typing.ClassVar[QtCore.pyqtSignal] + context1Pressed: typing.ClassVar[QtCore.pyqtSignal] + noPressed: typing.ClassVar[QtCore.pyqtSignal] + yesPressed: typing.ClassVar[QtCore.pyqtSignal] + selectPressed: typing.ClassVar[QtCore.pyqtSignal] + cancelPressed: typing.ClassVar[QtCore.pyqtSignal] + backPressed: typing.ClassVar[QtCore.pyqtSignal] + spacePressed: typing.ClassVar[QtCore.pyqtSignal] + deletePressed: typing.ClassVar[QtCore.pyqtSignal] + enterPressed: typing.ClassVar[QtCore.pyqtSignal] + returnPressed: typing.ClassVar[QtCore.pyqtSignal] + escapePressed: typing.ClassVar[QtCore.pyqtSignal] + numberSignPressed: typing.ClassVar[QtCore.pyqtSignal] + asteriskPressed: typing.ClassVar[QtCore.pyqtSignal] + backtabPressed: typing.ClassVar[QtCore.pyqtSignal] + tabPressed: typing.ClassVar[QtCore.pyqtSignal] + downPressed: typing.ClassVar[QtCore.pyqtSignal] + upPressed: typing.ClassVar[QtCore.pyqtSignal] + rightPressed: typing.ClassVar[QtCore.pyqtSignal] + leftPressed: typing.ClassVar[QtCore.pyqtSignal] + digit9Pressed: typing.ClassVar[QtCore.pyqtSignal] + digit8Pressed: typing.ClassVar[QtCore.pyqtSignal] + digit7Pressed: typing.ClassVar[QtCore.pyqtSignal] + digit6Pressed: typing.ClassVar[QtCore.pyqtSignal] + digit5Pressed: typing.ClassVar[QtCore.pyqtSignal] + digit4Pressed: typing.ClassVar[QtCore.pyqtSignal] + digit3Pressed: typing.ClassVar[QtCore.pyqtSignal] + digit2Pressed: typing.ClassVar[QtCore.pyqtSignal] + digit1Pressed: typing.ClassVar[QtCore.pyqtSignal] + digit0Pressed: typing.ClassVar[QtCore.pyqtSignal] + focusChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceDeviceChanged: typing.ClassVar[QtCore.pyqtSignal] def setFocus(self, focus: bool) -> None: ... def setSourceDevice(self, keyboardDevice: 'QKeyboardDevice') -> None: ... def focus(self) -> bool: ... @@ -310,11 +310,11 @@ class QMouseDevice('QAbstractPhysicalDevice'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def updateAxesContinuouslyChanged(self, updateAxesContinuously: bool) -> None: ... + updateAxesContinuouslyChanged: typing.ClassVar[QtCore.pyqtSignal] def setUpdateAxesContinuously(self, updateAxesContinuously: bool) -> None: ... def updateAxesContinuously(self) -> bool: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def sensitivityChanged(self, value: float) -> None: ... + sensitivityChanged: typing.ClassVar[QtCore.pyqtSignal] def setSensitivity(self, value: float) -> None: ... def sensitivity(self) -> float: ... def buttonIdentifier(self, name: str) -> int: ... @@ -412,17 +412,17 @@ class QMouseHandler(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def wheel(self, wheel: 'QWheelEvent') -> None: ... - def positionChanged(self, mouse: 'QMouseEvent') -> None: ... - def pressAndHold(self, mouse: 'QMouseEvent') -> None: ... - def released(self, mouse: 'QMouseEvent') -> None: ... - def pressed(self, mouse: 'QMouseEvent') -> None: ... - def exited(self) -> None: ... - def entered(self) -> None: ... - def doubleClicked(self, mouse: 'QMouseEvent') -> None: ... - def clicked(self, mouse: 'QMouseEvent') -> None: ... - def containsMouseChanged(self, containsMouse: bool) -> None: ... - def sourceDeviceChanged(self, mouseDevice: 'QMouseDevice') -> None: ... + wheel: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + pressAndHold: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + exited: typing.ClassVar[QtCore.pyqtSignal] + entered: typing.ClassVar[QtCore.pyqtSignal] + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] + containsMouseChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceDeviceChanged: typing.ClassVar[QtCore.pyqtSignal] def setSourceDevice(self, mouseDevice: 'QMouseDevice') -> None: ... def containsMouse(self) -> bool: ... def sourceDevice(self) -> 'QMouseDevice': ... diff --git a/PyQt5-stubs/Qt3DLogic.pyi b/PyQt5-stubs/Qt3DLogic.pyi index dd8cabb8..e4e541b8 100644 --- a/PyQt5-stubs/Qt3DLogic.pyi +++ b/PyQt5-stubs/Qt3DLogic.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the Qt3DLogic module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -43,7 +43,7 @@ class QFrameAction(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def triggered(self, dt: float) -> None: ... + triggered: typing.ClassVar[QtCore.pyqtSignal] class QLogicAspect(Qt3DCore.QAbstractAspect): diff --git a/PyQt5-stubs/Qt3DRender.pyi b/PyQt5-stubs/Qt3DRender.pyi index 43b9e810..fa531c7d 100644 --- a/PyQt5-stubs/Qt3DRender.pyi +++ b/PyQt5-stubs/Qt3DRender.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the Qt3DRender module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -55,8 +55,8 @@ class QAbstractLight(Qt3DCore.QComponent): DirectionalLight = ... # type: QAbstractLight.Type SpotLight = ... # type: QAbstractLight.Type - def intensityChanged(self, intensity: float) -> None: ... - def colorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... + intensityChanged: typing.ClassVar[QtCore.pyqtSignal] + colorChanged: typing.ClassVar[QtCore.pyqtSignal] def setIntensity(self, intensity: float) -> None: ... def setColor(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... def intensity(self) -> float: ... @@ -86,9 +86,9 @@ class QAbstractRayCaster(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def filterModeChanged(self, filterMode: 'QAbstractRayCaster.FilterMode') -> None: ... - def hitsChanged(self, hits: typing.Iterable['QRayCasterHit']) -> None: ... - def runModeChanged(self, runMode: 'QAbstractRayCaster.RunMode') -> None: ... + filterModeChanged: typing.ClassVar[QtCore.pyqtSignal] + hitsChanged: typing.ClassVar[QtCore.pyqtSignal] + runModeChanged: typing.ClassVar[QtCore.pyqtSignal] def setFilterMode(self, filterMode: 'QAbstractRayCaster.FilterMode') -> None: ... def setRunMode(self, runMode: 'QAbstractRayCaster.RunMode') -> None: ... def layers(self) -> typing.List['QLayer']: ... @@ -412,25 +412,25 @@ class QAbstractTexture(Qt3DCore.QNode): def __init__(self, target: 'QAbstractTexture.Target', parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def updateData(self, update: 'QTextureDataUpdate') -> None: ... - def handleChanged(self, handle: typing.Any) -> None: ... - def handleTypeChanged(self, handleType: 'QAbstractTexture.HandleType') -> None: ... + handleChanged: typing.ClassVar[QtCore.pyqtSignal] + handleTypeChanged: typing.ClassVar[QtCore.pyqtSignal] def handle(self) -> typing.Any: ... def handleType(self) -> 'QAbstractTexture.HandleType': ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... def setStatus(self, status: 'QAbstractTexture.Status') -> None: ... - def samplesChanged(self, samples: int) -> None: ... - def layersChanged(self, layers: int) -> None: ... - def comparisonModeChanged(self, comparisonMode: 'QAbstractTexture.ComparisonMode') -> None: ... - def comparisonFunctionChanged(self, comparisonFunction: 'QAbstractTexture.ComparisonFunction') -> None: ... - def maximumAnisotropyChanged(self, maximumAnisotropy: float) -> None: ... - def minificationFilterChanged(self, minificationFilter: 'QAbstractTexture.Filter') -> None: ... - def magnificationFilterChanged(self, magnificationFilter: 'QAbstractTexture.Filter') -> None: ... - def depthChanged(self, depth: int) -> None: ... - def heightChanged(self, height: int) -> None: ... - def widthChanged(self, width: int) -> None: ... - def generateMipMapsChanged(self, generateMipMaps: bool) -> None: ... - def statusChanged(self, status: 'QAbstractTexture.Status') -> None: ... - def formatChanged(self, format: 'QAbstractTexture.TextureFormat') -> None: ... + samplesChanged: typing.ClassVar[QtCore.pyqtSignal] + layersChanged: typing.ClassVar[QtCore.pyqtSignal] + comparisonModeChanged: typing.ClassVar[QtCore.pyqtSignal] + comparisonFunctionChanged: typing.ClassVar[QtCore.pyqtSignal] + maximumAnisotropyChanged: typing.ClassVar[QtCore.pyqtSignal] + minificationFilterChanged: typing.ClassVar[QtCore.pyqtSignal] + magnificationFilterChanged: typing.ClassVar[QtCore.pyqtSignal] + depthChanged: typing.ClassVar[QtCore.pyqtSignal] + heightChanged: typing.ClassVar[QtCore.pyqtSignal] + widthChanged: typing.ClassVar[QtCore.pyqtSignal] + generateMipMapsChanged: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + formatChanged: typing.ClassVar[QtCore.pyqtSignal] def setSamples(self, samples: int) -> None: ... def setLayers(self, layers: int) -> None: ... def setComparisonMode(self, mode: 'QAbstractTexture.ComparisonMode') -> None: ... @@ -471,9 +471,9 @@ class QAbstractTextureImage(Qt3DCore.QNode): def dataGenerator(self) -> 'QTextureImageDataGenerator': ... def notifyDataGeneratorChanged(self) -> None: ... - def faceChanged(self, face: 'QAbstractTexture.CubeMapFace') -> None: ... - def layerChanged(self, layer: int) -> None: ... - def mipLevelChanged(self, mipLevel: int) -> None: ... + faceChanged: typing.ClassVar[QtCore.pyqtSignal] + layerChanged: typing.ClassVar[QtCore.pyqtSignal] + mipLevelChanged: typing.ClassVar[QtCore.pyqtSignal] def setFace(self, face: 'QAbstractTexture.CubeMapFace') -> None: ... def setLayer(self, layer: int) -> None: ... def setMipLevel(self, level: int) -> None: ... @@ -510,8 +510,8 @@ class QAlphaTest('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def referenceValueChanged(self, referenceValue: float) -> None: ... - def alphaFunctionChanged(self, alphaFunction: 'QAlphaTest.AlphaFunction') -> None: ... + referenceValueChanged: typing.ClassVar[QtCore.pyqtSignal] + alphaFunctionChanged: typing.ClassVar[QtCore.pyqtSignal] def setReferenceValue(self, referenceValue: float) -> None: ... def setAlphaFunction(self, alphaFunction: 'QAlphaTest.AlphaFunction') -> None: ... def referenceValue(self) -> float: ... @@ -556,17 +556,17 @@ class QAttribute(Qt3DCore.QNode): @typing.overload def __init__(self, buf: 'QBuffer', name: str, vertexBaseType: 'QAttribute.VertexBaseType', vertexSize: int, count: int, offset: int = ..., stride: int = ..., parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def vertexSizeChanged(self, vertexSize: int) -> None: ... - def vertexBaseTypeChanged(self, vertexBaseType: 'QAttribute.VertexBaseType') -> None: ... - def attributeTypeChanged(self, attributeType: 'QAttribute.AttributeType') -> None: ... - def divisorChanged(self, divisor: int) -> None: ... - def byteOffsetChanged(self, byteOffset: int) -> None: ... - def byteStrideChanged(self, byteStride: int) -> None: ... - def countChanged(self, count: int) -> None: ... - def dataSizeChanged(self, vertexSize: int) -> None: ... - def dataTypeChanged(self, vertexBaseType: 'QAttribute.VertexBaseType') -> None: ... - def nameChanged(self, name: str) -> None: ... - def bufferChanged(self, buffer: 'QBuffer') -> None: ... + vertexSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + vertexBaseTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + attributeTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + divisorChanged: typing.ClassVar[QtCore.pyqtSignal] + byteOffsetChanged: typing.ClassVar[QtCore.pyqtSignal] + byteStrideChanged: typing.ClassVar[QtCore.pyqtSignal] + countChanged: typing.ClassVar[QtCore.pyqtSignal] + dataSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + dataTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + nameChanged: typing.ClassVar[QtCore.pyqtSignal] + bufferChanged: typing.ClassVar[QtCore.pyqtSignal] def setVertexSize(self, size: int) -> None: ... def setVertexBaseType(self, type: 'QAttribute.VertexBaseType') -> None: ... def setAttributeType(self, attributeType: 'QAttribute.AttributeType') -> None: ... @@ -623,7 +623,7 @@ class QBlendEquation('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def blendFunctionChanged(self, blendFunction: 'QBlendEquation.BlendFunction') -> None: ... + blendFunctionChanged: typing.ClassVar[QtCore.pyqtSignal] def setBlendFunction(self, blendFunction: 'QBlendEquation.BlendFunction') -> None: ... def blendFunction(self) -> 'QBlendEquation.BlendFunction': ... @@ -674,13 +674,13 @@ class QBlendEquationArguments('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def bufferIndexChanged(self, index: int) -> None: ... - def destinationRgbaChanged(self, destinationRgba: 'QBlendEquationArguments.Blending') -> None: ... - def sourceRgbaChanged(self, sourceRgba: 'QBlendEquationArguments.Blending') -> None: ... - def destinationAlphaChanged(self, destinationAlpha: 'QBlendEquationArguments.Blending') -> None: ... - def destinationRgbChanged(self, destinationRgb: 'QBlendEquationArguments.Blending') -> None: ... - def sourceAlphaChanged(self, sourceAlpha: 'QBlendEquationArguments.Blending') -> None: ... - def sourceRgbChanged(self, sourceRgb: 'QBlendEquationArguments.Blending') -> None: ... + bufferIndexChanged: typing.ClassVar[QtCore.pyqtSignal] + destinationRgbaChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceRgbaChanged: typing.ClassVar[QtCore.pyqtSignal] + destinationAlphaChanged: typing.ClassVar[QtCore.pyqtSignal] + destinationRgbChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceAlphaChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceRgbChanged: typing.ClassVar[QtCore.pyqtSignal] def setBufferIndex(self, index: int) -> None: ... def setDestinationRgba(self, destinationRgba: 'QBlendEquationArguments.Blending') -> None: ... def setSourceRgba(self, sourceRgba: 'QBlendEquationArguments.Blending') -> None: ... @@ -711,13 +711,13 @@ class QBlitFramebuffer('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def interpolationMethodChanged(self) -> None: ... - def destinationAttachmentPointChanged(self) -> None: ... - def sourceAttachmentPointChanged(self) -> None: ... - def destinationRectChanged(self) -> None: ... - def sourceRectChanged(self) -> None: ... - def destinationChanged(self) -> None: ... - def sourceChanged(self) -> None: ... + interpolationMethodChanged: typing.ClassVar[QtCore.pyqtSignal] + destinationAttachmentPointChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceAttachmentPointChanged: typing.ClassVar[QtCore.pyqtSignal] + destinationRectChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceRectChanged: typing.ClassVar[QtCore.pyqtSignal] + destinationChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] def setInterpolationMethod(self, interpolationMethod: 'QBlitFramebuffer.InterpolationMethod') -> None: ... def setDestinationAttachmentPoint(self, destinationAttachmentPoint: 'QRenderTargetOutput.AttachmentPoint') -> None: ... def setSourceAttachmentPoint(self, sourceAttachmentPoint: 'QRenderTargetOutput.AttachmentPoint') -> None: ... @@ -787,16 +787,16 @@ class QBuffer(Qt3DCore.QNode): @typing.overload def __init__(self, ty: 'QBuffer.BufferType', parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def dataAvailable(self) -> None: ... - def accessTypeChanged(self, access: 'QBuffer.AccessType') -> None: ... + dataAvailable: typing.ClassVar[QtCore.pyqtSignal] + accessTypeChanged: typing.ClassVar[QtCore.pyqtSignal] def setAccessType(self, access: 'QBuffer.AccessType') -> None: ... def accessType(self) -> 'QBuffer.AccessType': ... def updateData(self, offset: int, bytes: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def syncDataChanged(self, syncData: bool) -> None: ... - def usageChanged(self, usage: 'QBuffer.UsageType') -> None: ... - def typeChanged(self, type: 'QBuffer.BufferType') -> None: ... - def dataChanged(self, bytes: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... + syncDataChanged: typing.ClassVar[QtCore.pyqtSignal] + usageChanged: typing.ClassVar[QtCore.pyqtSignal] + typeChanged: typing.ClassVar[QtCore.pyqtSignal] + dataChanged: typing.ClassVar[QtCore.pyqtSignal] def setSyncData(self, syncData: bool) -> None: ... def setUsage(self, usage: 'QBuffer.UsageType') -> None: ... def setType(self, type: 'QBuffer.BufferType') -> None: ... @@ -826,24 +826,24 @@ class QCamera(Qt3DCore.QEntity): def viewEntity(self, entity: Qt3DCore.QEntity) -> None: ... def viewSphere(self, center: QtGui.QVector3D, radius: float) -> None: ... def viewAll(self) -> None: ... - def exposureChanged(self, exposure: float) -> None: ... + exposureChanged: typing.ClassVar[QtCore.pyqtSignal] def setExposure(self, exposure: float) -> None: ... def exposure(self) -> float: ... - def viewMatrixChanged(self) -> None: ... - def viewVectorChanged(self, viewVector: QtGui.QVector3D) -> None: ... - def viewCenterChanged(self, viewCenter: QtGui.QVector3D) -> None: ... - def upVectorChanged(self, upVector: QtGui.QVector3D) -> None: ... - def positionChanged(self, position: QtGui.QVector3D) -> None: ... - def projectionMatrixChanged(self, projectionMatrix: QtGui.QMatrix4x4) -> None: ... - def topChanged(self, top: float) -> None: ... - def bottomChanged(self, bottom: float) -> None: ... - def rightChanged(self, right: float) -> None: ... - def leftChanged(self, left: float) -> None: ... - def aspectRatioChanged(self, aspectRatio: float) -> None: ... - def fieldOfViewChanged(self, fieldOfView: float) -> None: ... - def farPlaneChanged(self, farPlane: float) -> None: ... - def nearPlaneChanged(self, nearPlane: float) -> None: ... - def projectionTypeChanged(self, projectionType: 'QCameraLens.ProjectionType') -> None: ... + viewMatrixChanged: typing.ClassVar[QtCore.pyqtSignal] + viewVectorChanged: typing.ClassVar[QtCore.pyqtSignal] + viewCenterChanged: typing.ClassVar[QtCore.pyqtSignal] + upVectorChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + projectionMatrixChanged: typing.ClassVar[QtCore.pyqtSignal] + topChanged: typing.ClassVar[QtCore.pyqtSignal] + bottomChanged: typing.ClassVar[QtCore.pyqtSignal] + rightChanged: typing.ClassVar[QtCore.pyqtSignal] + leftChanged: typing.ClassVar[QtCore.pyqtSignal] + aspectRatioChanged: typing.ClassVar[QtCore.pyqtSignal] + fieldOfViewChanged: typing.ClassVar[QtCore.pyqtSignal] + farPlaneChanged: typing.ClassVar[QtCore.pyqtSignal] + nearPlaneChanged: typing.ClassVar[QtCore.pyqtSignal] + projectionTypeChanged: typing.ClassVar[QtCore.pyqtSignal] def setViewCenter(self, viewCenter: QtGui.QVector3D) -> None: ... def setUpVector(self, upVector: QtGui.QVector3D) -> None: ... def setPosition(self, position: QtGui.QVector3D) -> None: ... @@ -910,22 +910,22 @@ class QCameraLens(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def viewSphere(self, center: QtGui.QVector3D, radius: float) -> None: ... + viewSphere: typing.ClassVar[QtCore.pyqtSignal] def viewEntity(self, entityId: Qt3DCore.QNodeId, cameraId: Qt3DCore.QNodeId) -> None: ... def viewAll(self, cameraId: Qt3DCore.QNodeId) -> None: ... - def exposureChanged(self, exposure: float) -> None: ... + exposureChanged: typing.ClassVar[QtCore.pyqtSignal] def setExposure(self, exposure: float) -> None: ... def exposure(self) -> float: ... - def projectionMatrixChanged(self, projectionMatrix: QtGui.QMatrix4x4) -> None: ... - def topChanged(self, top: float) -> None: ... - def bottomChanged(self, bottom: float) -> None: ... - def rightChanged(self, right: float) -> None: ... - def leftChanged(self, left: float) -> None: ... - def aspectRatioChanged(self, aspectRatio: float) -> None: ... - def fieldOfViewChanged(self, fieldOfView: float) -> None: ... - def farPlaneChanged(self, farPlane: float) -> None: ... - def nearPlaneChanged(self, nearPlane: float) -> None: ... - def projectionTypeChanged(self, projectionType: 'QCameraLens.ProjectionType') -> None: ... + projectionMatrixChanged: typing.ClassVar[QtCore.pyqtSignal] + topChanged: typing.ClassVar[QtCore.pyqtSignal] + bottomChanged: typing.ClassVar[QtCore.pyqtSignal] + rightChanged: typing.ClassVar[QtCore.pyqtSignal] + leftChanged: typing.ClassVar[QtCore.pyqtSignal] + aspectRatioChanged: typing.ClassVar[QtCore.pyqtSignal] + fieldOfViewChanged: typing.ClassVar[QtCore.pyqtSignal] + farPlaneChanged: typing.ClassVar[QtCore.pyqtSignal] + nearPlaneChanged: typing.ClassVar[QtCore.pyqtSignal] + projectionTypeChanged: typing.ClassVar[QtCore.pyqtSignal] def setProjectionMatrix(self, projectionMatrix: QtGui.QMatrix4x4) -> None: ... def setTop(self, top: float) -> None: ... def setBottom(self, bottom: float) -> None: ... @@ -954,7 +954,7 @@ class QCameraSelector('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def cameraChanged(self, camera: Qt3DCore.QEntity) -> None: ... + cameraChanged: typing.ClassVar[QtCore.pyqtSignal] def setCamera(self, camera: Qt3DCore.QEntity) -> None: ... def camera(self) -> Qt3DCore.QEntity: ... @@ -987,20 +987,28 @@ class QClearBuffers('QFrameGraphNode'): def __init__(self, f: typing.Union['QClearBuffers.BufferTypeFlags', 'QClearBuffers.BufferType']) -> None: ... @typing.overload def __init__(self, a0: 'QClearBuffers.BufferTypeFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QClearBuffers.BufferTypeFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QClearBuffers.BufferTypeFlags', 'QClearBuffers.BufferType', int]) -> 'QClearBuffers.BufferTypeFlags': ... + def __and__(self, other: typing.Union['QClearBuffers.BufferTypeFlags', 'QClearBuffers.BufferType', int]) -> 'QClearBuffers.BufferTypeFlags': ... + def __xor__(self, other: typing.Union['QClearBuffers.BufferTypeFlags', 'QClearBuffers.BufferType', int]) -> 'QClearBuffers.BufferTypeFlags': ... + def __ror__ (self, other: 'QClearBuffers.BufferType') -> 'QClearBuffers.BufferTypeFlags': ... + def __rand__(self, other: 'QClearBuffers.BufferType') -> 'QClearBuffers.BufferTypeFlags': ... + def __rxor__(self, other: 'QClearBuffers.BufferType') -> 'QClearBuffers.BufferTypeFlags': ... def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def colorBufferChanged(self, buffer: 'QRenderTargetOutput') -> None: ... - def clearStencilValueChanged(self, clearStencilValue: int) -> None: ... - def clearDepthValueChanged(self, clearDepthValue: float) -> None: ... - def clearColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def buffersChanged(self, buffers: 'QClearBuffers.BufferType') -> None: ... + colorBufferChanged: typing.ClassVar[QtCore.pyqtSignal] + clearStencilValueChanged: typing.ClassVar[QtCore.pyqtSignal] + clearDepthValueChanged: typing.ClassVar[QtCore.pyqtSignal] + clearColorChanged: typing.ClassVar[QtCore.pyqtSignal] + buffersChanged: typing.ClassVar[QtCore.pyqtSignal] def setColorBuffer(self, buffer: 'QRenderTargetOutput') -> None: ... def setClearStencilValue(self, clearStencilValue: int) -> None: ... def setClearDepthValue(self, clearDepthValue: float) -> None: ... @@ -1016,9 +1024,9 @@ class QClipPlane('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def distanceChanged(self, distance: float) -> None: ... - def normalChanged(self, normal: QtGui.QVector3D) -> None: ... - def planeIndexChanged(self, planeIndex: int) -> None: ... + distanceChanged: typing.ClassVar[QtCore.pyqtSignal] + normalChanged: typing.ClassVar[QtCore.pyqtSignal] + planeIndexChanged: typing.ClassVar[QtCore.pyqtSignal] def setDistance(self, a0: float) -> None: ... def setNormal(self, a0: QtGui.QVector3D) -> None: ... def setPlaneIndex(self, a0: int) -> None: ... @@ -1037,16 +1045,16 @@ class QComputeCommand(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def runTypeChanged(self) -> None: ... + runTypeChanged: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def trigger(self, frameCount: int = ...) -> None: ... @typing.overload def trigger(self, workGroupX: int, workGroupY: int, workGroupZ: int, frameCount: int = ...) -> None: ... def setRunType(self, runType: 'QComputeCommand.RunType') -> None: ... def runType(self) -> 'QComputeCommand.RunType': ... - def workGroupZChanged(self) -> None: ... - def workGroupYChanged(self) -> None: ... - def workGroupXChanged(self) -> None: ... + workGroupZChanged: typing.ClassVar[QtCore.pyqtSignal] + workGroupYChanged: typing.ClassVar[QtCore.pyqtSignal] + workGroupXChanged: typing.ClassVar[QtCore.pyqtSignal] def setWorkGroupZ(self, workGroupZ: int) -> None: ... def setWorkGroupY(self, workGroupY: int) -> None: ... def setWorkGroupX(self, workGroupX: int) -> None: ... @@ -1058,10 +1066,10 @@ class QColorMask('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def alphaMaskedChanged(self, alphaMasked: bool) -> None: ... - def blueMaskedChanged(self, blueMasked: bool) -> None: ... - def greenMaskedChanged(self, greenMasked: bool) -> None: ... - def redMaskedChanged(self, redMasked: bool) -> None: ... + alphaMaskedChanged: typing.ClassVar[QtCore.pyqtSignal] + blueMaskedChanged: typing.ClassVar[QtCore.pyqtSignal] + greenMaskedChanged: typing.ClassVar[QtCore.pyqtSignal] + redMaskedChanged: typing.ClassVar[QtCore.pyqtSignal] def setAlphaMasked(self, alphaMasked: bool) -> None: ... def setBlueMasked(self, blueMasked: bool) -> None: ... def setGreenMasked(self, greenMasked: bool) -> None: ... @@ -1086,7 +1094,7 @@ class QCullFace('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def modeChanged(self, mode: 'QCullFace.CullingMode') -> None: ... + modeChanged: typing.ClassVar[QtCore.pyqtSignal] def setMode(self, mode: 'QCullFace.CullingMode') -> None: ... def mode(self) -> 'QCullFace.CullingMode': ... @@ -1094,8 +1102,8 @@ class QDepthRange('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def farValueChanged(self, farValue: float) -> None: ... - def nearValueChanged(self, nearValue: float) -> None: ... + farValueChanged: typing.ClassVar[QtCore.pyqtSignal] + nearValueChanged: typing.ClassVar[QtCore.pyqtSignal] def setFarValue(self, value: float) -> None: ... def setNearValue(self, value: float) -> None: ... def farValue(self) -> float: ... @@ -1124,7 +1132,7 @@ class QDepthTest('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def depthFunctionChanged(self, depthFunction: 'QDepthTest.DepthFunction') -> None: ... + depthFunctionChanged: typing.ClassVar[QtCore.pyqtSignal] def setDepthFunction(self, depthFunction: 'QDepthTest.DepthFunction') -> None: ... def depthFunction(self) -> 'QDepthTest.DepthFunction': ... @@ -1132,7 +1140,7 @@ class QDirectionalLight('QAbstractLight'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def worldDirectionChanged(self, worldDirection: QtGui.QVector3D) -> None: ... + worldDirectionChanged: typing.ClassVar[QtCore.pyqtSignal] def setWorldDirection(self, worldDirection: QtGui.QVector3D) -> None: ... def worldDirection(self) -> QtGui.QVector3D: ... @@ -1140,9 +1148,9 @@ class QDispatchCompute('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def workGroupZChanged(self) -> None: ... - def workGroupYChanged(self) -> None: ... - def workGroupXChanged(self) -> None: ... + workGroupZChanged: typing.ClassVar[QtCore.pyqtSignal] + workGroupYChanged: typing.ClassVar[QtCore.pyqtSignal] + workGroupXChanged: typing.ClassVar[QtCore.pyqtSignal] def setWorkGroupZ(self, workGroupZ: int) -> None: ... def setWorkGroupY(self, workGroupY: int) -> None: ... def setWorkGroupX(self, workGroupX: int) -> None: ... @@ -1169,8 +1177,8 @@ class QEnvironmentLight(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def specularChanged(self, environmentSpecular: 'QAbstractTexture') -> None: ... - def irradianceChanged(self, environmentIrradiance: 'QAbstractTexture') -> None: ... + specularChanged: typing.ClassVar[QtCore.pyqtSignal] + irradianceChanged: typing.ClassVar[QtCore.pyqtSignal] def setSpecular(self, specular: 'QAbstractTexture') -> None: ... def setIrradiance(self, irradiance: 'QAbstractTexture') -> None: ... def specular(self) -> 'QAbstractTexture': ... @@ -1180,8 +1188,8 @@ class QFilterKey(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def valueChanged(self, value: typing.Any) -> None: ... - def nameChanged(self, name: str) -> None: ... + valueChanged: typing.ClassVar[QtCore.pyqtSignal] + nameChanged: typing.ClassVar[QtCore.pyqtSignal] def setName(self, customType: str) -> None: ... def setValue(self, value: typing.Any) -> None: ... def name(self) -> str: ... @@ -1198,7 +1206,7 @@ class QFrontFace('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def directionChanged(self, direction: 'QFrontFace.WindingDirection') -> None: ... + directionChanged: typing.ClassVar[QtCore.pyqtSignal] def setDirection(self, direction: 'QFrontFace.WindingDirection') -> None: ... def direction(self) -> 'QFrontFace.WindingDirection': ... @@ -1211,11 +1219,11 @@ class QGeometry(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def maxExtentChanged(self, maxExtent: QtGui.QVector3D) -> None: ... - def minExtentChanged(self, minExtent: QtGui.QVector3D) -> None: ... + maxExtentChanged: typing.ClassVar[QtCore.pyqtSignal] + minExtentChanged: typing.ClassVar[QtCore.pyqtSignal] def maxExtent(self) -> QtGui.QVector3D: ... def minExtent(self) -> QtGui.QVector3D: ... - def boundingVolumePositionAttributeChanged(self, boundingVolumePositionAttribute: 'QAttribute') -> None: ... + boundingVolumePositionAttributeChanged: typing.ClassVar[QtCore.pyqtSignal] def setBoundingVolumePositionAttribute(self, boundingVolumePositionAttribute: 'QAttribute') -> None: ... def boundingVolumePositionAttribute(self) -> 'QAttribute': ... def removeAttribute(self, attribute: 'QAttribute') -> None: ... @@ -1258,19 +1266,19 @@ class QGeometryRenderer(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def indexBufferByteOffsetChanged(self, offset: int) -> None: ... + indexBufferByteOffsetChanged: typing.ClassVar[QtCore.pyqtSignal] def setIndexBufferByteOffset(self, offset: int) -> None: ... def indexBufferByteOffset(self) -> int: ... - def primitiveTypeChanged(self, primitiveType: 'QGeometryRenderer.PrimitiveType') -> None: ... - def geometryChanged(self, geometry: 'QGeometry') -> None: ... - def primitiveRestartEnabledChanged(self, primitiveRestartEnabled: bool) -> None: ... - def verticesPerPatchChanged(self, verticesPerPatch: int) -> None: ... - def restartIndexValueChanged(self, restartIndexValue: int) -> None: ... - def firstVertexChanged(self, firstVertex: int) -> None: ... - def firstInstanceChanged(self, firstInstance: int) -> None: ... - def indexOffsetChanged(self, indexOffset: int) -> None: ... - def vertexCountChanged(self, vertexCount: int) -> None: ... - def instanceCountChanged(self, instanceCount: int) -> None: ... + primitiveTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + geometryChanged: typing.ClassVar[QtCore.pyqtSignal] + primitiveRestartEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + verticesPerPatchChanged: typing.ClassVar[QtCore.pyqtSignal] + restartIndexValueChanged: typing.ClassVar[QtCore.pyqtSignal] + firstVertexChanged: typing.ClassVar[QtCore.pyqtSignal] + firstInstanceChanged: typing.ClassVar[QtCore.pyqtSignal] + indexOffsetChanged: typing.ClassVar[QtCore.pyqtSignal] + vertexCountChanged: typing.ClassVar[QtCore.pyqtSignal] + instanceCountChanged: typing.ClassVar[QtCore.pyqtSignal] def setPrimitiveType(self, primitiveType: 'QGeometryRenderer.PrimitiveType') -> None: ... def setGeometry(self, geometry: 'QGeometry') -> None: ... def setPrimitiveRestartEnabled(self, enabled: bool) -> None: ... @@ -1320,13 +1328,13 @@ class QGraphicsApiFilter(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def graphicsApiFilterChanged(self) -> None: ... - def vendorChanged(self, vendor: str) -> None: ... - def extensionsChanged(self, extensions: typing.Iterable[str]) -> None: ... - def majorVersionChanged(self, majorVersion: int) -> None: ... - def minorVersionChanged(self, minorVersion: int) -> None: ... - def profileChanged(self, profile: 'QGraphicsApiFilter.OpenGLProfile') -> None: ... - def apiChanged(self, api: 'QGraphicsApiFilter.Api') -> None: ... + graphicsApiFilterChanged: typing.ClassVar[QtCore.pyqtSignal] + vendorChanged: typing.ClassVar[QtCore.pyqtSignal] + extensionsChanged: typing.ClassVar[QtCore.pyqtSignal] + majorVersionChanged: typing.ClassVar[QtCore.pyqtSignal] + minorVersionChanged: typing.ClassVar[QtCore.pyqtSignal] + profileChanged: typing.ClassVar[QtCore.pyqtSignal] + apiChanged: typing.ClassVar[QtCore.pyqtSignal] def setVendor(self, vendor: str) -> None: ... def setExtensions(self, extensions: typing.Iterable[str]) -> None: ... def setMajorVersion(self, majorVersion: int) -> None: ... @@ -1344,7 +1352,7 @@ class QLayer(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def recursiveChanged(self) -> None: ... + recursiveChanged: typing.ClassVar[QtCore.pyqtSignal] def setRecursive(self, recursive: bool) -> None: ... def recursive(self) -> bool: ... @@ -1363,7 +1371,7 @@ class QLayerFilter('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def filterModeChanged(self, filterMode: 'QLayerFilter.FilterMode') -> None: ... + filterModeChanged: typing.ClassVar[QtCore.pyqtSignal] def setFilterMode(self, filterMode: 'QLayerFilter.FilterMode') -> None: ... def filterMode(self) -> 'QLayerFilter.FilterMode': ... def layers(self) -> typing.List['QLayer']: ... @@ -1382,11 +1390,11 @@ class QLevelOfDetail(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def volumeOverrideChanged(self, volumeOverride: 'QLevelOfDetailBoundingSphere') -> None: ... - def thresholdsChanged(self, thresholds: typing.Iterable[float]) -> None: ... - def thresholdTypeChanged(self, thresholdType: 'QLevelOfDetail.ThresholdType') -> None: ... - def currentIndexChanged(self, currentIndex: int) -> None: ... - def cameraChanged(self, camera: 'QCamera') -> None: ... + volumeOverrideChanged: typing.ClassVar[QtCore.pyqtSignal] + thresholdsChanged: typing.ClassVar[QtCore.pyqtSignal] + thresholdTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + currentIndexChanged: typing.ClassVar[QtCore.pyqtSignal] + cameraChanged: typing.ClassVar[QtCore.pyqtSignal] def setVolumeOverride(self, volumeOverride: 'QLevelOfDetailBoundingSphere') -> None: ... def setThresholds(self, thresholds: typing.Iterable[float]) -> None: ... def setThresholdType(self, thresholdType: 'QLevelOfDetail.ThresholdType') -> None: ... @@ -1420,8 +1428,8 @@ class QLineWidth('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def smoothChanged(self, enabled: bool) -> None: ... - def valueChanged(self, value: float) -> None: ... + smoothChanged: typing.ClassVar[QtCore.pyqtSignal] + valueChanged: typing.ClassVar[QtCore.pyqtSignal] def setSmooth(self, enabled: bool) -> None: ... def setValue(self, value: float) -> None: ... def smooth(self) -> bool: ... @@ -1431,7 +1439,7 @@ class QMaterial(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def effectChanged(self, effect: 'QEffect') -> None: ... + effectChanged: typing.ClassVar[QtCore.pyqtSignal] def setEffect(self, effect: 'QEffect') -> None: ... def parameters(self) -> typing.List['QParameter']: ... def removeParameter(self, parameter: 'QParameter') -> None: ... @@ -1483,16 +1491,24 @@ class QMemoryBarrier('QFrameGraphNode'): def __init__(self, f: typing.Union['QMemoryBarrier.Operations', 'QMemoryBarrier.Operation']) -> None: ... @typing.overload def __init__(self, a0: 'QMemoryBarrier.Operations') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QMemoryBarrier.Operations': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QMemoryBarrier.Operations', 'QMemoryBarrier.Operation', int]) -> 'QMemoryBarrier.Operations': ... + def __and__(self, other: typing.Union['QMemoryBarrier.Operations', 'QMemoryBarrier.Operation', int]) -> 'QMemoryBarrier.Operations': ... + def __xor__(self, other: typing.Union['QMemoryBarrier.Operations', 'QMemoryBarrier.Operation', int]) -> 'QMemoryBarrier.Operations': ... + def __ror__ (self, other: 'QMemoryBarrier.Operation') -> 'QMemoryBarrier.Operations': ... + def __rand__(self, other: 'QMemoryBarrier.Operation') -> 'QMemoryBarrier.Operations': ... + def __rxor__(self, other: 'QMemoryBarrier.Operation') -> 'QMemoryBarrier.Operations': ... def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def waitOperationsChanged(self, barrierTypes: typing.Union['QMemoryBarrier.Operations', 'QMemoryBarrier.Operation']) -> None: ... + waitOperationsChanged: typing.ClassVar[QtCore.pyqtSignal] def setWaitOperations(self, operations: typing.Union['QMemoryBarrier.Operations', 'QMemoryBarrier.Operation']) -> None: ... def waitOperations(self) -> 'QMemoryBarrier.Operations': ... @@ -1512,10 +1528,10 @@ class QMesh('QGeometryRenderer'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def statusChanged(self, status: 'QMesh.Status') -> None: ... + statusChanged: typing.ClassVar[QtCore.pyqtSignal] def status(self) -> 'QMesh.Status': ... - def meshNameChanged(self, meshName: str) -> None: ... - def sourceChanged(self, source: QtCore.QUrl) -> None: ... + meshNameChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] def setMeshName(self, meshName: str) -> None: ... def setSource(self, source: QtCore.QUrl) -> None: ... def meshName(self) -> str: ... @@ -1541,20 +1557,20 @@ class QObjectPicker(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def priorityChanged(self, priority: int) -> None: ... + priorityChanged: typing.ClassVar[QtCore.pyqtSignal] def setPriority(self, priority: int) -> None: ... def priority(self) -> int: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def containsMouseChanged(self, containsMouse: bool) -> None: ... - def pressedChanged(self, pressed: bool) -> None: ... - def dragEnabledChanged(self, dragEnabled: bool) -> None: ... - def hoverEnabledChanged(self, hoverEnabled: bool) -> None: ... - def exited(self) -> None: ... - def entered(self) -> None: ... - def moved(self, pick: 'QPickEvent') -> None: ... - def clicked(self, pick: 'QPickEvent') -> None: ... - def released(self, pick: 'QPickEvent') -> None: ... - def pressed(self, pick: 'QPickEvent') -> None: ... + containsMouseChanged: typing.ClassVar[QtCore.pyqtSignal] + pressedChanged: typing.ClassVar[QtCore.pyqtSignal] + dragEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + hoverEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + exited: typing.ClassVar[QtCore.pyqtSignal] + entered: typing.ClassVar[QtCore.pyqtSignal] + moved: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] def setDragEnabled(self, dragEnabled: bool) -> None: ... def setHoverEnabled(self, hoverEnabled: bool) -> None: ... def isPressed(self) -> bool: ... @@ -1567,9 +1583,9 @@ class QPaintedTextureImage('QAbstractTextureImage'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def paint(self, painter: QtGui.QPainter) -> None: ... - def sizeChanged(self, size: QtCore.QSize) -> None: ... - def heightChanged(self, w: int) -> None: ... - def widthChanged(self, w: int) -> None: ... + sizeChanged: typing.ClassVar[QtCore.pyqtSignal] + heightChanged: typing.ClassVar[QtCore.pyqtSignal] + widthChanged: typing.ClassVar[QtCore.pyqtSignal] def setSize(self, size: QtCore.QSize) -> None: ... def setHeight(self, h: int) -> None: ... def setWidth(self, w: int) -> None: ... @@ -1587,8 +1603,8 @@ class QParameter(Qt3DCore.QNode): @typing.overload def __init__(self, name: str, texture: 'QAbstractTexture', parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def nameChanged(self, name: str) -> None: ... - def valueChanged(self, value: typing.Any) -> None: ... + nameChanged: typing.ClassVar[QtCore.pyqtSignal] + valueChanged: typing.ClassVar[QtCore.pyqtSignal] def setValue(self, dv: typing.Any) -> None: ... def setName(self, name: str) -> None: ... def value(self) -> typing.Any: ... @@ -1636,7 +1652,7 @@ class QPickEvent(QtCore.QObject): def modifiers(self) -> int: ... def buttons(self) -> int: ... def button(self) -> 'QPickEvent.Buttons': ... - def acceptedChanged(self, accepted: bool) -> None: ... + acceptedChanged: typing.ClassVar[QtCore.pyqtSignal] def setAccepted(self, accepted: bool) -> None: ... def localIntersection(self) -> QtGui.QVector3D: ... def worldIntersection(self) -> QtGui.QVector3D: ... @@ -1679,14 +1695,14 @@ class QPickingSettings(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def worldSpaceToleranceChanged(self, worldSpaceTolerance: float) -> None: ... + worldSpaceToleranceChanged: typing.ClassVar[QtCore.pyqtSignal] def setWorldSpaceTolerance(self, worldSpaceTolerance: float) -> None: ... def worldSpaceTolerance(self) -> float: ... - def faceOrientationPickingModeChanged(self, faceOrientationPickingMode: 'QPickingSettings.FaceOrientationPickingMode') -> None: ... + faceOrientationPickingModeChanged: typing.ClassVar[QtCore.pyqtSignal] def setFaceOrientationPickingMode(self, faceOrientationPickingMode: 'QPickingSettings.FaceOrientationPickingMode') -> None: ... def faceOrientationPickingMode(self) -> 'QPickingSettings.FaceOrientationPickingMode': ... - def pickResultModeChanged(self, pickResult: 'QPickingSettings.PickResultMode') -> None: ... - def pickMethodChanged(self, pickMethod: 'QPickingSettings.PickMethod') -> None: ... + pickResultModeChanged: typing.ClassVar[QtCore.pyqtSignal] + pickMethodChanged: typing.ClassVar[QtCore.pyqtSignal] def setPickResultMode(self, pickResultMode: 'QPickingSettings.PickResultMode') -> None: ... def setPickMethod(self, pickMethod: 'QPickingSettings.PickMethod') -> None: ... def pickResultMode(self) -> 'QPickingSettings.PickResultMode': ... @@ -1731,9 +1747,9 @@ class QPointLight('QAbstractLight'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def quadraticAttenuationChanged(self, quadraticAttenuation: float) -> None: ... - def linearAttenuationChanged(self, linearAttenuation: float) -> None: ... - def constantAttenuationChanged(self, constantAttenuation: float) -> None: ... + quadraticAttenuationChanged: typing.ClassVar[QtCore.pyqtSignal] + linearAttenuationChanged: typing.ClassVar[QtCore.pyqtSignal] + constantAttenuationChanged: typing.ClassVar[QtCore.pyqtSignal] def setQuadraticAttenuation(self, value: float) -> None: ... def setLinearAttenuation(self, value: float) -> None: ... def setConstantAttenuation(self, value: float) -> None: ... @@ -1752,8 +1768,8 @@ class QPointSize('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def valueChanged(self, value: float) -> None: ... - def sizeModeChanged(self, sizeMode: 'QPointSize.SizeMode') -> None: ... + valueChanged: typing.ClassVar[QtCore.pyqtSignal] + sizeModeChanged: typing.ClassVar[QtCore.pyqtSignal] def setValue(self, value: float) -> None: ... def setSizeMode(self, sizeMode: 'QPointSize.SizeMode') -> None: ... def value(self) -> float: ... @@ -1763,8 +1779,8 @@ class QPolygonOffset('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def depthStepsChanged(self, depthSteps: float) -> None: ... - def scaleFactorChanged(self, scaleFactor: float) -> None: ... + depthStepsChanged: typing.ClassVar[QtCore.pyqtSignal] + scaleFactorChanged: typing.ClassVar[QtCore.pyqtSignal] def setDepthSteps(self, depthSteps: float) -> None: ... def setScaleFactor(self, scaleFactor: float) -> None: ... def depthSteps(self) -> float: ... @@ -1774,8 +1790,8 @@ class QProximityFilter('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def distanceThresholdChanged(self, distanceThreshold: float) -> None: ... - def entityChanged(self, entity: Qt3DCore.QEntity) -> None: ... + distanceThresholdChanged: typing.ClassVar[QtCore.pyqtSignal] + entityChanged: typing.ClassVar[QtCore.pyqtSignal] def setDistanceThreshold(self, distanceThreshold: float) -> None: ... def setEntity(self, entity: Qt3DCore.QEntity) -> None: ... def distanceThreshold(self) -> float: ... @@ -1803,8 +1819,8 @@ class QRasterMode('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def faceModeChanged(self, faceMode: 'QRasterMode.FaceMode') -> None: ... - def rasterModeChanged(self, rasterMode: 'QRasterMode.RasterMode') -> None: ... + faceModeChanged: typing.ClassVar[QtCore.pyqtSignal] + rasterModeChanged: typing.ClassVar[QtCore.pyqtSignal] def setFaceMode(self, faceMode: 'QRasterMode.FaceMode') -> None: ... def setRasterMode(self, rasterMode: 'QRasterMode.RasterMode') -> None: ... def faceMode(self) -> 'QRasterMode.FaceMode': ... @@ -1814,9 +1830,9 @@ class QRayCaster('QAbstractRayCaster'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def lengthChanged(self, length: float) -> None: ... - def directionChanged(self, direction: QtGui.QVector3D) -> None: ... - def originChanged(self, origin: QtGui.QVector3D) -> None: ... + lengthChanged: typing.ClassVar[QtCore.pyqtSignal] + directionChanged: typing.ClassVar[QtCore.pyqtSignal] + originChanged: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def trigger(self) -> None: ... @typing.overload @@ -1935,9 +1951,9 @@ class QRenderCapabilities(QtCore.QObject): class QRenderCaptureReply(QtCore.QObject): - def completed(self) -> None: ... + completed: typing.ClassVar[QtCore.pyqtSignal] def saveImage(self, fileName: str) -> bool: ... - def completeChanged(self, isComplete: bool) -> None: ... + completeChanged: typing.ClassVar[QtCore.pyqtSignal] def saveToFile(self, fileName: str) -> None: ... def isComplete(self) -> bool: ... def captureId(self) -> int: ... @@ -1959,7 +1975,7 @@ class QRenderPass(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def shaderProgramChanged(self, shaderProgram: 'QShaderProgram') -> None: ... + shaderProgramChanged: typing.ClassVar[QtCore.pyqtSignal] def setShaderProgram(self, shaderProgram: 'QShaderProgram') -> None: ... def parameters(self) -> typing.List['QParameter']: ... def removeParameter(self, p: 'QParameter') -> None: ... @@ -1994,8 +2010,8 @@ class QRenderSettings(Qt3DCore.QComponent): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def renderPolicyChanged(self, renderPolicy: 'QRenderSettings.RenderPolicy') -> None: ... - def activeFrameGraphChanged(self, activeFrameGraph: 'QFrameGraphNode') -> None: ... + renderPolicyChanged: typing.ClassVar[QtCore.pyqtSignal] + activeFrameGraphChanged: typing.ClassVar[QtCore.pyqtSignal] def setRenderPolicy(self, renderPolicy: 'QRenderSettings.RenderPolicy') -> None: ... def setActiveFrameGraph(self, activeFrameGraph: 'QFrameGraphNode') -> None: ... def renderCapabilities(self) -> 'QRenderCapabilities': ... @@ -2015,9 +2031,9 @@ class QRenderSurfaceSelector('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def surfacePixelRatioChanged(self, ratio: float) -> None: ... - def externalRenderTargetSizeChanged(self, size: QtCore.QSize) -> None: ... - def surfaceChanged(self, surface: QtCore.QObject) -> None: ... + surfacePixelRatioChanged: typing.ClassVar[QtCore.pyqtSignal] + externalRenderTargetSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + surfaceChanged: typing.ClassVar[QtCore.pyqtSignal] def setSurfacePixelRatio(self, ratio: float) -> None: ... def setSurface(self, surfaceObject: QtCore.QObject) -> None: ... def setExternalRenderTargetSize(self, size: QtCore.QSize) -> None: ... @@ -2078,11 +2094,11 @@ class QRenderTargetOutput(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def faceChanged(self, face: 'QAbstractTexture.CubeMapFace') -> None: ... - def layerChanged(self, layer: int) -> None: ... - def mipLevelChanged(self, mipLevel: int) -> None: ... - def textureChanged(self, texture: 'QAbstractTexture') -> None: ... - def attachmentPointChanged(self, attachmentPoint: 'QRenderTargetOutput.AttachmentPoint') -> None: ... + faceChanged: typing.ClassVar[QtCore.pyqtSignal] + layerChanged: typing.ClassVar[QtCore.pyqtSignal] + mipLevelChanged: typing.ClassVar[QtCore.pyqtSignal] + textureChanged: typing.ClassVar[QtCore.pyqtSignal] + attachmentPointChanged: typing.ClassVar[QtCore.pyqtSignal] def setFace(self, face: 'QAbstractTexture.CubeMapFace') -> None: ... def setLayer(self, layer: int) -> None: ... def setMipLevel(self, level: int) -> None: ... @@ -2098,7 +2114,7 @@ class QRenderTargetSelector('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def targetChanged(self, target: 'QRenderTarget') -> None: ... + targetChanged: typing.ClassVar[QtCore.pyqtSignal] def setTarget(self, target: 'QRenderTarget') -> None: ... def target(self) -> 'QRenderTarget': ... def outputs(self) -> typing.List[QRenderTargetOutput.AttachmentPoint]: ... @@ -2136,8 +2152,8 @@ class QSceneLoader(Qt3DCore.QComponent): def component(self, entityName: str, componentType: 'QSceneLoader.ComponentType') -> Qt3DCore.QComponent: ... def entityNames(self) -> typing.List[str]: ... def entity(self, entityName: str) -> Qt3DCore.QEntity: ... - def statusChanged(self, status: 'QSceneLoader.Status') -> None: ... - def sourceChanged(self, source: QtCore.QUrl) -> None: ... + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] def setSource(self, arg: QtCore.QUrl) -> None: ... def status(self) -> 'QSceneLoader.Status': ... def source(self) -> QtCore.QUrl: ... @@ -2147,10 +2163,10 @@ class QScissorTest('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def heightChanged(self, height: int) -> None: ... - def widthChanged(self, width: int) -> None: ... - def bottomChanged(self, bottom: int) -> None: ... - def leftChanged(self, left: int) -> None: ... + heightChanged: typing.ClassVar[QtCore.pyqtSignal] + widthChanged: typing.ClassVar[QtCore.pyqtSignal] + bottomChanged: typing.ClassVar[QtCore.pyqtSignal] + leftChanged: typing.ClassVar[QtCore.pyqtSignal] def setHeight(self, height: int) -> None: ... def setWidth(self, width: int) -> None: ... def setBottom(self, bottom: int) -> None: ... @@ -2164,7 +2180,7 @@ class QScreenRayCaster('QAbstractRayCaster'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def positionChanged(self, position: QtCore.QPoint) -> None: ... + positionChanged: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def trigger(self) -> None: ... @typing.overload @@ -2188,8 +2204,8 @@ class QSetFence('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def handleChanged(self, handle: typing.Any) -> None: ... - def handleTypeChanged(self, handleType: 'QSetFence.HandleType') -> None: ... + handleChanged: typing.ClassVar[QtCore.pyqtSignal] + handleTypeChanged: typing.ClassVar[QtCore.pyqtSignal] def handle(self) -> typing.Any: ... def handleType(self) -> 'QSetFence.HandleType': ... @@ -2302,12 +2318,12 @@ class QShaderImage(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def formatChanged(self, format: 'QShaderImage.ImageFormat') -> None: ... - def accessChanged(self, access: 'QShaderImage.Access') -> None: ... - def layerChanged(self, layer: int) -> None: ... - def mipLevelChanged(self, mipLevel: int) -> None: ... - def layeredChanged(self, layered: bool) -> None: ... - def textureChanged(self, texture: 'QAbstractTexture') -> None: ... + formatChanged: typing.ClassVar[QtCore.pyqtSignal] + accessChanged: typing.ClassVar[QtCore.pyqtSignal] + layerChanged: typing.ClassVar[QtCore.pyqtSignal] + mipLevelChanged: typing.ClassVar[QtCore.pyqtSignal] + layeredChanged: typing.ClassVar[QtCore.pyqtSignal] + textureChanged: typing.ClassVar[QtCore.pyqtSignal] def setFormat(self, format: 'QShaderImage.ImageFormat') -> None: ... def setAccess(self, access: 'QShaderImage.Access') -> None: ... def setLayer(self, layer: int) -> None: ... @@ -2356,20 +2372,20 @@ class QShaderProgram(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def formatChanged(self, format: 'QShaderProgram.Format') -> None: ... + formatChanged: typing.ClassVar[QtCore.pyqtSignal] def format(self) -> 'QShaderProgram.Format': ... def setFormat(self, format: 'QShaderProgram.Format') -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def statusChanged(self, status: 'QShaderProgram.Status') -> None: ... - def logChanged(self, log: str) -> None: ... + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + logChanged: typing.ClassVar[QtCore.pyqtSignal] def status(self) -> 'QShaderProgram.Status': ... def log(self) -> str: ... - def computeShaderCodeChanged(self, computeShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def fragmentShaderCodeChanged(self, fragmentShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def geometryShaderCodeChanged(self, geometryShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def tessellationEvaluationShaderCodeChanged(self, tessellationEvaluationShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def tessellationControlShaderCodeChanged(self, tessellationControlShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def vertexShaderCodeChanged(self, vertexShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... + computeShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + fragmentShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + geometryShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + tessellationEvaluationShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + tessellationControlShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + vertexShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] def setComputeShaderCode(self, computeShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... def setFragmentShaderCode(self, fragmentShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... def setGeometryShaderCode(self, geometryShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... @@ -2392,26 +2408,26 @@ class QShaderProgramBuilder(Qt3DCore.QNode): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def computeShaderCodeChanged(self, computeShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def fragmentShaderCodeChanged(self, fragmentShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def geometryShaderCodeChanged(self, geometryShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def tessellationEvaluationShaderCodeChanged(self, tessellationEvaluationShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def tessellationControlShaderCodeChanged(self, tessellationControlShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def vertexShaderCodeChanged(self, vertexShaderCode: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... + computeShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + fragmentShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + geometryShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + tessellationEvaluationShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + tessellationControlShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + vertexShaderCodeChanged: typing.ClassVar[QtCore.pyqtSignal] def computeShaderCode(self) -> QtCore.QByteArray: ... def fragmentShaderCode(self) -> QtCore.QByteArray: ... def geometryShaderCode(self) -> QtCore.QByteArray: ... def tessellationEvaluationShaderCode(self) -> QtCore.QByteArray: ... def tessellationControlShaderCode(self) -> QtCore.QByteArray: ... def vertexShaderCode(self) -> QtCore.QByteArray: ... - def computeShaderGraphChanged(self, computeShaderGraph: QtCore.QUrl) -> None: ... - def fragmentShaderGraphChanged(self, fragmentShaderGraph: QtCore.QUrl) -> None: ... - def geometryShaderGraphChanged(self, geometryShaderGraph: QtCore.QUrl) -> None: ... - def tessellationEvaluationShaderGraphChanged(self, tessellationEvaluationShaderGraph: QtCore.QUrl) -> None: ... - def tessellationControlShaderGraphChanged(self, tessellationControlShaderGraph: QtCore.QUrl) -> None: ... - def vertexShaderGraphChanged(self, vertexShaderGraph: QtCore.QUrl) -> None: ... - def enabledLayersChanged(self, layers: typing.Iterable[str]) -> None: ... - def shaderProgramChanged(self, shaderProgram: 'QShaderProgram') -> None: ... + computeShaderGraphChanged: typing.ClassVar[QtCore.pyqtSignal] + fragmentShaderGraphChanged: typing.ClassVar[QtCore.pyqtSignal] + geometryShaderGraphChanged: typing.ClassVar[QtCore.pyqtSignal] + tessellationEvaluationShaderGraphChanged: typing.ClassVar[QtCore.pyqtSignal] + tessellationControlShaderGraphChanged: typing.ClassVar[QtCore.pyqtSignal] + vertexShaderGraphChanged: typing.ClassVar[QtCore.pyqtSignal] + enabledLayersChanged: typing.ClassVar[QtCore.pyqtSignal] + shaderProgramChanged: typing.ClassVar[QtCore.pyqtSignal] def setComputeShaderGraph(self, computeShaderGraph: QtCore.QUrl) -> None: ... def setFragmentShaderGraph(self, fragmentShaderGraph: QtCore.QUrl) -> None: ... def setGeometryShaderGraph(self, geometryShaderGraph: QtCore.QUrl) -> None: ... @@ -2448,10 +2464,7 @@ class QSortPolicy('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - @typing.overload - def sortTypesChanged(self, sortTypes: typing.Iterable[QSortPolicy.SortType]) -> None: ... - @typing.overload - def sortTypesChanged(self, sortTypes: typing.Iterable[int]) -> None: ... + sortTypesChanged: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def setSortTypes(self, sortTypes: typing.Iterable[QSortPolicy.SortType]) -> None: ... @typing.overload @@ -2463,11 +2476,11 @@ class QSpotLight('QAbstractLight'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def cutOffAngleChanged(self, cutOffAngle: float) -> None: ... - def localDirectionChanged(self, localDirection: QtGui.QVector3D) -> None: ... - def quadraticAttenuationChanged(self, quadraticAttenuation: float) -> None: ... - def linearAttenuationChanged(self, linearAttenuation: float) -> None: ... - def constantAttenuationChanged(self, constantAttenuation: float) -> None: ... + cutOffAngleChanged: typing.ClassVar[QtCore.pyqtSignal] + localDirectionChanged: typing.ClassVar[QtCore.pyqtSignal] + quadraticAttenuationChanged: typing.ClassVar[QtCore.pyqtSignal] + linearAttenuationChanged: typing.ClassVar[QtCore.pyqtSignal] + constantAttenuationChanged: typing.ClassVar[QtCore.pyqtSignal] def setCutOffAngle(self, cutOffAngle: float) -> None: ... def setLocalDirection(self, localDirection: QtGui.QVector3D) -> None: ... def setQuadraticAttenuation(self, value: float) -> None: ... @@ -2483,8 +2496,8 @@ class QStencilMask('QRenderState'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def backOutputMaskChanged(self, backOutputMask: int) -> None: ... - def frontOutputMaskChanged(self, frontOutputMask: int) -> None: ... + backOutputMaskChanged: typing.ClassVar[QtCore.pyqtSignal] + frontOutputMaskChanged: typing.ClassVar[QtCore.pyqtSignal] def setBackOutputMask(self, backOutputMask: int) -> None: ... def setFrontOutputMask(self, frontOutputMask: int) -> None: ... def backOutputMask(self) -> int: ... @@ -2527,10 +2540,10 @@ class QStencilOperationArguments(QtCore.QObject): Back = ... # type: QStencilOperationArguments.FaceMode FrontAndBack = ... # type: QStencilOperationArguments.FaceMode - def faceModeChanged(self, faceMode: 'QStencilOperationArguments.FaceMode') -> None: ... - def allTestsPassOperationChanged(self, stencilDepthPass: 'QStencilOperationArguments.Operation') -> None: ... - def depthTestFailureOperationChanged(self, depthFail: 'QStencilOperationArguments.Operation') -> None: ... - def stencilTestFailureOperationChanged(self, stencilFail: 'QStencilOperationArguments.Operation') -> None: ... + faceModeChanged: typing.ClassVar[QtCore.pyqtSignal] + allTestsPassOperationChanged: typing.ClassVar[QtCore.pyqtSignal] + depthTestFailureOperationChanged: typing.ClassVar[QtCore.pyqtSignal] + stencilTestFailureOperationChanged: typing.ClassVar[QtCore.pyqtSignal] def setAllTestsPassOperation(self, operation: 'QStencilOperationArguments.Operation') -> None: ... def setDepthTestFailureOperation(self, operation: 'QStencilOperationArguments.Operation') -> None: ... def setStencilTestFailureOperation(self, operation: 'QStencilOperationArguments.Operation') -> None: ... @@ -2576,10 +2589,10 @@ class QStencilTestArguments(QtCore.QObject): Back = ... # type: QStencilTestArguments.StencilFaceMode FrontAndBack = ... # type: QStencilTestArguments.StencilFaceMode - def faceModeChanged(self, faceMode: 'QStencilTestArguments.StencilFaceMode') -> None: ... - def referenceValueChanged(self, referenceValue: int) -> None: ... - def stencilFunctionChanged(self, stencilFunction: 'QStencilTestArguments.StencilFunction') -> None: ... - def comparisonMaskChanged(self, comparisonMask: int) -> None: ... + faceModeChanged: typing.ClassVar[QtCore.pyqtSignal] + referenceValueChanged: typing.ClassVar[QtCore.pyqtSignal] + stencilFunctionChanged: typing.ClassVar[QtCore.pyqtSignal] + comparisonMaskChanged: typing.ClassVar[QtCore.pyqtSignal] def setStencilFunction(self, stencilFunction: 'QStencilTestArguments.StencilFunction') -> None: ... def setReferenceValue(self, referenceValue: int) -> None: ... def setComparisonMask(self, comparisonMask: int) -> None: ... @@ -2599,7 +2612,7 @@ class QSubtreeEnabler('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def enablementChanged(self, enablement: 'QSubtreeEnabler.Enablement') -> None: ... + enablementChanged: typing.ClassVar[QtCore.pyqtSignal] def requestUpdate(self) -> None: ... def setEnablement(self, enablement: 'QSubtreeEnabler.Enablement') -> None: ... def enablement(self) -> 'QSubtreeEnabler.Enablement': ... @@ -2678,10 +2691,10 @@ class QTextureLoader('QAbstractTexture'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def mirroredChanged(self, mirrored: bool) -> None: ... + mirroredChanged: typing.ClassVar[QtCore.pyqtSignal] def setMirrored(self, mirrored: bool) -> None: ... def isMirrored(self) -> bool: ... - def sourceChanged(self, source: QtCore.QUrl) -> None: ... + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] def setSource(self, source: QtCore.QUrl) -> None: ... def source(self) -> QtCore.QUrl: ... @@ -2689,7 +2702,7 @@ class QSharedGLTexture('QAbstractTexture'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def textureIdChanged(self, textureId: int) -> None: ... + textureIdChanged: typing.ClassVar[QtCore.pyqtSignal] def setTextureId(self, id: int) -> None: ... def textureId(self) -> int: ... @@ -2775,13 +2788,13 @@ class QTextureImage('QAbstractTextureImage'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def mirroredChanged(self, mirrored: bool) -> None: ... + mirroredChanged: typing.ClassVar[QtCore.pyqtSignal] def setMirrored(self, mirrored: bool) -> None: ... def isMirrored(self) -> bool: ... def setStatus(self, status: 'QTextureImage.Status') -> None: ... def sceneChangeEvent(self, change: Qt3DCore.QSceneChange) -> None: ... - def statusChanged(self, status: 'QTextureImage.Status') -> None: ... - def sourceChanged(self, source: QtCore.QUrl) -> None: ... + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] def setSource(self, source: QtCore.QUrl) -> None: ... def status(self) -> 'QTextureImage.Status': ... def source(self) -> QtCore.QUrl: ... @@ -2841,9 +2854,9 @@ class QTextureWrapMode(QtCore.QObject): @typing.overload def __init__(self, x: 'QTextureWrapMode.WrapMode', y: 'QTextureWrapMode.WrapMode', z: 'QTextureWrapMode.WrapMode', parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def zChanged(self, z: 'QTextureWrapMode.WrapMode') -> None: ... - def yChanged(self, y: 'QTextureWrapMode.WrapMode') -> None: ... - def xChanged(self, x: 'QTextureWrapMode.WrapMode') -> None: ... + zChanged: typing.ClassVar[QtCore.pyqtSignal] + yChanged: typing.ClassVar[QtCore.pyqtSignal] + xChanged: typing.ClassVar[QtCore.pyqtSignal] def setZ(self, z: 'QTextureWrapMode.WrapMode') -> None: ... def setY(self, y: 'QTextureWrapMode.WrapMode') -> None: ... def setX(self, x: 'QTextureWrapMode.WrapMode') -> None: ... @@ -2855,10 +2868,10 @@ class QViewport('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def gammaChanged(self, gamma: float) -> None: ... + gammaChanged: typing.ClassVar[QtCore.pyqtSignal] def setGamma(self, gamma: float) -> None: ... def gamma(self) -> float: ... - def normalizedRectChanged(self, normalizedRect: QtCore.QRectF) -> None: ... + normalizedRectChanged: typing.ClassVar[QtCore.pyqtSignal] def setNormalizedRect(self, normalizedRect: QtCore.QRectF) -> None: ... def normalizedRect(self) -> QtCore.QRectF: ... @@ -2873,10 +2886,10 @@ class QWaitFence('QFrameGraphNode'): def __init__(self, parent: typing.Optional[Qt3DCore.QNode] = ...) -> None: ... - def handleChanged(self, handle: typing.Any) -> None: ... - def handleTypeChanged(self, handleType: 'QWaitFence.HandleType') -> None: ... - def timeoutChanged(self, timeoutChanged: int) -> None: ... - def waitOnCPUChanged(self, waitOnCPU: bool) -> None: ... + handleChanged: typing.ClassVar[QtCore.pyqtSignal] + handleTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + timeoutChanged: typing.ClassVar[QtCore.pyqtSignal] + waitOnCPUChanged: typing.ClassVar[QtCore.pyqtSignal] def setTimeout(self, timeout: int) -> None: ... def timeout(self) -> int: ... def setWaitOnCPU(self, waitOnCPU: bool) -> None: ... diff --git a/PyQt5-stubs/QtBluetooth.pyi b/PyQt5-stubs/QtBluetooth.pyi index b9bb57b5..ccc181de 100644 --- a/PyQt5-stubs/QtBluetooth.pyi +++ b/PyQt5-stubs/QtBluetooth.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtBluetooth module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -35,6 +35,9 @@ PYQT_SLOT = typing.Union[typing.Callable[..., None], QtCore.pyqtBoundSignal] class QBluetooth(sip.simplewrapper): class AttAccessConstraint(int): + def __or__ (self, other: 'QBluetooth.AttAccessConstraint') -> 'QBluetooth.AttAccessConstraints': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QBluetooth.AttAccessConstraints': ... # type: ignore[override, misc] + AttAuthorizationRequired = ... # type: QBluetooth.AttAccessConstraint AttAuthenticationRequired = ... # type: QBluetooth.AttAccessConstraint AttEncryptionRequired = ... # type: QBluetooth.AttAccessConstraint @@ -44,6 +47,9 @@ class QBluetooth(sip.simplewrapper): AttEncryptionRequired = ... # type: QBluetooth.AttAccessConstraint class Security(int): + def __or__ (self, other: 'QBluetooth.Security') -> 'QBluetooth.SecurityFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QBluetooth.SecurityFlags': ... # type: ignore[override, misc] + NoSecurity = ... # type: QBluetooth.Security Authorization = ... # type: QBluetooth.Security Authentication = ... # type: QBluetooth.Security @@ -64,12 +70,20 @@ class QBluetooth(sip.simplewrapper): def __init__(self, f: typing.Union['QBluetooth.SecurityFlags', 'QBluetooth.Security']) -> None: ... @typing.overload def __init__(self, a0: 'QBluetooth.SecurityFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QBluetooth.SecurityFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QBluetooth.SecurityFlags', 'QBluetooth.Security', int]) -> 'QBluetooth.SecurityFlags': ... + def __and__(self, other: typing.Union['QBluetooth.SecurityFlags', 'QBluetooth.Security', int]) -> 'QBluetooth.SecurityFlags': ... + def __xor__(self, other: typing.Union['QBluetooth.SecurityFlags', 'QBluetooth.Security', int]) -> 'QBluetooth.SecurityFlags': ... + def __ror__ (self, other: 'QBluetooth.Security') -> 'QBluetooth.SecurityFlags': ... + def __rand__(self, other: 'QBluetooth.Security') -> 'QBluetooth.SecurityFlags': ... + def __rxor__(self, other: 'QBluetooth.Security') -> 'QBluetooth.SecurityFlags': ... class AttAccessConstraints(sip.wrapper): @@ -79,12 +93,20 @@ class QBluetooth(sip.simplewrapper): def __init__(self, f: typing.Union['QBluetooth.AttAccessConstraints', 'QBluetooth.AttAccessConstraint']) -> None: ... @typing.overload def __init__(self, a0: 'QBluetooth.AttAccessConstraints') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QBluetooth.AttAccessConstraints': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QBluetooth.AttAccessConstraints', 'QBluetooth.AttAccessConstraint', int]) -> 'QBluetooth.AttAccessConstraints': ... + def __and__(self, other: typing.Union['QBluetooth.AttAccessConstraints', 'QBluetooth.AttAccessConstraint', int]) -> 'QBluetooth.AttAccessConstraints': ... + def __xor__(self, other: typing.Union['QBluetooth.AttAccessConstraints', 'QBluetooth.AttAccessConstraint', int]) -> 'QBluetooth.AttAccessConstraints': ... + def __ror__ (self, other: 'QBluetooth.AttAccessConstraint') -> 'QBluetooth.AttAccessConstraints': ... + def __rand__(self, other: 'QBluetooth.AttAccessConstraint') -> 'QBluetooth.AttAccessConstraints': ... + def __rxor__(self, other: 'QBluetooth.AttAccessConstraint') -> 'QBluetooth.AttAccessConstraints': ... class QBluetoothAddress(sip.wrapper): @@ -163,10 +185,10 @@ class QBluetoothDeviceDiscoveryAgent(QtCore.QObject): def supportedDiscoveryMethods() -> 'QBluetoothDeviceDiscoveryAgent.DiscoveryMethods': ... def lowEnergyDiscoveryTimeout(self) -> int: ... def setLowEnergyDiscoveryTimeout(self, msTimeout: int) -> None: ... - def deviceUpdated(self, info: 'QBluetoothDeviceInfo', updatedFields: typing.Union['QBluetoothDeviceInfo.Fields', 'QBluetoothDeviceInfo.Field']) -> None: ... - def canceled(self) -> None: ... - def finished(self) -> None: ... - def deviceDiscovered(self, info: 'QBluetoothDeviceInfo') -> None: ... + deviceUpdated: typing.ClassVar[QtCore.pyqtSignal] + canceled: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] + deviceDiscovered: typing.ClassVar[QtCore.pyqtSignal] def stop(self) -> None: ... @typing.overload def start(self) -> None: ... @@ -174,10 +196,7 @@ class QBluetoothDeviceDiscoveryAgent(QtCore.QObject): def start(self, method: typing.Union['QBluetoothDeviceDiscoveryAgent.DiscoveryMethods', 'QBluetoothDeviceDiscoveryAgent.DiscoveryMethod']) -> None: ... def discoveredDevices(self) -> typing.List['QBluetoothDeviceInfo']: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QBluetoothDeviceDiscoveryAgent.Error': ... - @typing.overload - def error(self, error: 'QBluetoothDeviceDiscoveryAgent.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def isActive(self) -> bool: ... def setInquiryType(self, type: 'QBluetoothDeviceDiscoveryAgent.InquiryType') -> None: ... def inquiryType(self) -> 'QBluetoothDeviceDiscoveryAgent.InquiryType': ... @@ -197,6 +216,9 @@ class QBluetoothDeviceInfo(sip.wrapper): All = ... # type: QBluetoothDeviceInfo.Field class CoreConfiguration(int): + def __or__ (self, other: 'QBluetoothDeviceInfo.CoreConfiguration') -> 'QBluetoothDeviceInfo.CoreConfigurations': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QBluetoothDeviceInfo.CoreConfigurations': ... # type: ignore[override, misc] + UnknownCoreConfiguration = ... # type: QBluetoothDeviceInfo.CoreConfiguration LowEnergyCoreConfiguration = ... # type: QBluetoothDeviceInfo.CoreConfiguration BaseRateCoreConfiguration = ... # type: QBluetoothDeviceInfo.CoreConfiguration @@ -217,6 +239,9 @@ class QBluetoothDeviceInfo(sip.wrapper): DataUnavailable = ... # type: QBluetoothDeviceInfo.DataCompleteness class ServiceClass(int): + def __or__ (self, other: 'QBluetoothDeviceInfo.ServiceClass') -> 'QBluetoothDeviceInfo.ServiceClasses': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QBluetoothDeviceInfo.ServiceClasses': ... # type: ignore[override, misc] + NoService = ... # type: QBluetoothDeviceInfo.ServiceClass PositioningService = ... # type: QBluetoothDeviceInfo.ServiceClass NetworkingService = ... # type: QBluetoothDeviceInfo.ServiceClass @@ -452,12 +477,20 @@ class QBluetoothDeviceInfo(sip.wrapper): def __init__(self, f: typing.Union['QBluetoothDeviceInfo.ServiceClasses', 'QBluetoothDeviceInfo.ServiceClass']) -> None: ... @typing.overload def __init__(self, a0: 'QBluetoothDeviceInfo.ServiceClasses') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QBluetoothDeviceInfo.ServiceClasses': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QBluetoothDeviceInfo.ServiceClasses', 'QBluetoothDeviceInfo.ServiceClass', int]) -> 'QBluetoothDeviceInfo.ServiceClasses': ... + def __and__(self, other: typing.Union['QBluetoothDeviceInfo.ServiceClasses', 'QBluetoothDeviceInfo.ServiceClass', int]) -> 'QBluetoothDeviceInfo.ServiceClasses': ... + def __xor__(self, other: typing.Union['QBluetoothDeviceInfo.ServiceClasses', 'QBluetoothDeviceInfo.ServiceClass', int]) -> 'QBluetoothDeviceInfo.ServiceClasses': ... + def __ror__ (self, other: 'QBluetoothDeviceInfo.ServiceClass') -> 'QBluetoothDeviceInfo.ServiceClasses': ... + def __rand__(self, other: 'QBluetoothDeviceInfo.ServiceClass') -> 'QBluetoothDeviceInfo.ServiceClasses': ... + def __rxor__(self, other: 'QBluetoothDeviceInfo.ServiceClass') -> 'QBluetoothDeviceInfo.ServiceClasses': ... class CoreConfigurations(sip.wrapper): @@ -467,12 +500,20 @@ class QBluetoothDeviceInfo(sip.wrapper): def __init__(self, f: typing.Union['QBluetoothDeviceInfo.CoreConfigurations', 'QBluetoothDeviceInfo.CoreConfiguration']) -> None: ... @typing.overload def __init__(self, a0: 'QBluetoothDeviceInfo.CoreConfigurations') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QBluetoothDeviceInfo.CoreConfigurations': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QBluetoothDeviceInfo.CoreConfigurations', 'QBluetoothDeviceInfo.CoreConfiguration', int]) -> 'QBluetoothDeviceInfo.CoreConfigurations': ... + def __and__(self, other: typing.Union['QBluetoothDeviceInfo.CoreConfigurations', 'QBluetoothDeviceInfo.CoreConfiguration', int]) -> 'QBluetoothDeviceInfo.CoreConfigurations': ... + def __xor__(self, other: typing.Union['QBluetoothDeviceInfo.CoreConfigurations', 'QBluetoothDeviceInfo.CoreConfiguration', int]) -> 'QBluetoothDeviceInfo.CoreConfigurations': ... + def __ror__ (self, other: 'QBluetoothDeviceInfo.CoreConfiguration') -> 'QBluetoothDeviceInfo.CoreConfigurations': ... + def __rand__(self, other: 'QBluetoothDeviceInfo.CoreConfiguration') -> 'QBluetoothDeviceInfo.CoreConfigurations': ... + def __rxor__(self, other: 'QBluetoothDeviceInfo.CoreConfiguration') -> 'QBluetoothDeviceInfo.CoreConfigurations': ... class Fields(sip.wrapper): @@ -482,12 +523,20 @@ class QBluetoothDeviceInfo(sip.wrapper): def __init__(self, f: typing.Union['QBluetoothDeviceInfo.Fields', 'QBluetoothDeviceInfo.Field']) -> None: ... @typing.overload def __init__(self, a0: 'QBluetoothDeviceInfo.Fields') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QBluetoothDeviceInfo.Fields': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QBluetoothDeviceInfo.Fields', 'QBluetoothDeviceInfo.Field', int]) -> 'QBluetoothDeviceInfo.Fields': ... + def __and__(self, other: typing.Union['QBluetoothDeviceInfo.Fields', 'QBluetoothDeviceInfo.Field', int]) -> 'QBluetoothDeviceInfo.Fields': ... + def __xor__(self, other: typing.Union['QBluetoothDeviceInfo.Fields', 'QBluetoothDeviceInfo.Field', int]) -> 'QBluetoothDeviceInfo.Fields': ... + def __ror__ (self, other: 'QBluetoothDeviceInfo.Field') -> 'QBluetoothDeviceInfo.Fields': ... + def __rand__(self, other: 'QBluetoothDeviceInfo.Field') -> 'QBluetoothDeviceInfo.Fields': ... + def __rxor__(self, other: 'QBluetoothDeviceInfo.Field') -> 'QBluetoothDeviceInfo.Fields': ... @typing.overload def __init__(self) -> None: ... @@ -575,13 +624,13 @@ class QBluetoothLocalDevice(QtCore.QObject): @typing.overload def __init__(self, address: QBluetoothAddress, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def deviceDisconnected(self, address: QBluetoothAddress) -> None: ... - def deviceConnected(self, address: QBluetoothAddress) -> None: ... - def error(self, error: 'QBluetoothLocalDevice.Error') -> None: ... - def pairingDisplayConfirmation(self, address: QBluetoothAddress, pin: str) -> None: ... - def pairingDisplayPinCode(self, address: QBluetoothAddress, pin: str) -> None: ... - def pairingFinished(self, address: QBluetoothAddress, pairing: 'QBluetoothLocalDevice.Pairing') -> None: ... - def hostModeStateChanged(self, state: 'QBluetoothLocalDevice.HostMode') -> None: ... + deviceDisconnected: typing.ClassVar[QtCore.pyqtSignal] + deviceConnected: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] + pairingDisplayConfirmation: typing.ClassVar[QtCore.pyqtSignal] + pairingDisplayPinCode: typing.ClassVar[QtCore.pyqtSignal] + pairingFinished: typing.ClassVar[QtCore.pyqtSignal] + hostModeStateChanged: typing.ClassVar[QtCore.pyqtSignal] def pairingConfirmation(self, confirmation: bool) -> None: ... def connectedDevices(self) -> typing.List[QBluetoothAddress]: ... @staticmethod @@ -615,11 +664,8 @@ class QBluetoothServer(QtCore.QObject): def __init__(self, serverType: 'QBluetoothServiceInfo.Protocol', parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def newConnection(self) -> None: ... - @typing.overload - def error(self) -> 'QBluetoothServer.Error': ... - @typing.overload - def error(self, a0: 'QBluetoothServer.Error') -> None: ... + newConnection: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] def serverType(self) -> 'QBluetoothServiceInfo.Protocol': ... def securityFlags(self) -> QBluetooth.SecurityFlags: ... def setSecurityFlags(self, security: typing.Union[QBluetooth.SecurityFlags, QBluetooth.Security]) -> None: ... @@ -664,9 +710,9 @@ class QBluetoothServiceDiscoveryAgent(QtCore.QObject): @typing.overload def __init__(self, deviceAdapter: QBluetoothAddress, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def canceled(self) -> None: ... - def finished(self) -> None: ... - def serviceDiscovered(self, info: 'QBluetoothServiceInfo') -> None: ... + canceled: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] + serviceDiscovered: typing.ClassVar[QtCore.pyqtSignal] def clear(self) -> None: ... def stop(self) -> None: ... def start(self, mode: 'QBluetoothServiceDiscoveryAgent.DiscoveryMode' = ...) -> None: ... @@ -679,10 +725,7 @@ class QBluetoothServiceDiscoveryAgent(QtCore.QObject): def setUuidFilter(self, uuid: 'QBluetoothUuid') -> None: ... def discoveredServices(self) -> typing.List['QBluetoothServiceInfo']: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QBluetoothServiceDiscoveryAgent.Error': ... - @typing.overload - def error(self, error: 'QBluetoothServiceDiscoveryAgent.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def isActive(self) -> bool: ... @@ -825,14 +868,11 @@ class QBluetoothSocket(QtCore.QIODevice): def setSocketState(self, state: 'QBluetoothSocket.SocketState') -> None: ... def writeData(self, data: bytes) -> int: ... def readData(self, maxlen: int) -> bytes: ... - def stateChanged(self, state: 'QBluetoothSocket.SocketState') -> None: ... - def disconnected(self) -> None: ... - def connected(self) -> None: ... + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + disconnected: typing.ClassVar[QtCore.pyqtSignal] + connected: typing.ClassVar[QtCore.pyqtSignal] def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QBluetoothSocket.SocketError': ... - @typing.overload - def error(self, error: 'QBluetoothSocket.SocketError') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def state(self) -> 'QBluetoothSocket.SocketState': ... def socketType(self) -> QBluetoothServiceInfo.Protocol: ... def socketDescriptor(self) -> int: ... @@ -862,7 +902,7 @@ class QBluetoothTransferManager(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def finished(self, reply: 'QBluetoothTransferReply') -> None: ... + finished: typing.ClassVar[QtCore.pyqtSignal] def put(self, request: 'QBluetoothTransferRequest', data: QtCore.QIODevice) -> 'QBluetoothTransferReply': ... @@ -891,15 +931,12 @@ class QBluetoothTransferReply(QtCore.QObject): def setRequest(self, request: 'QBluetoothTransferRequest') -> None: ... def setManager(self, manager: QBluetoothTransferManager) -> None: ... - def transferProgress(self, bytesTransferred: int, bytesTotal: int) -> None: ... - def finished(self, a0: 'QBluetoothTransferReply') -> None: ... + transferProgress: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def abort(self) -> None: ... def request(self) -> 'QBluetoothTransferRequest': ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QBluetoothTransferReply.TransferError': ... - @typing.overload - def error(self, lastError: 'QBluetoothTransferReply.TransferError') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def manager(self) -> QBluetoothTransferManager: ... def isRunning(self) -> bool: ... def isFinished(self) -> bool: ... @@ -1590,6 +1627,9 @@ class QLowEnergyAdvertisingParameters(sip.wrapper): class QLowEnergyCharacteristic(sip.wrapper): class PropertyType(int): + def __or__ (self, other: 'QLowEnergyCharacteristic.PropertyType') -> 'QLowEnergyCharacteristic.PropertyTypes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QLowEnergyCharacteristic.PropertyTypes': ... # type: ignore[override, misc] + Unknown = ... # type: QLowEnergyCharacteristic.PropertyType Broadcasting = ... # type: QLowEnergyCharacteristic.PropertyType Read = ... # type: QLowEnergyCharacteristic.PropertyType @@ -1618,12 +1658,20 @@ class QLowEnergyCharacteristic(sip.wrapper): def __init__(self, f: typing.Union['QLowEnergyCharacteristic.PropertyTypes', 'QLowEnergyCharacteristic.PropertyType']) -> None: ... @typing.overload def __init__(self, a0: 'QLowEnergyCharacteristic.PropertyTypes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QLowEnergyCharacteristic.PropertyTypes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QLowEnergyCharacteristic.PropertyTypes', 'QLowEnergyCharacteristic.PropertyType', int]) -> 'QLowEnergyCharacteristic.PropertyTypes': ... + def __and__(self, other: typing.Union['QLowEnergyCharacteristic.PropertyTypes', 'QLowEnergyCharacteristic.PropertyType', int]) -> 'QLowEnergyCharacteristic.PropertyTypes': ... + def __xor__(self, other: typing.Union['QLowEnergyCharacteristic.PropertyTypes', 'QLowEnergyCharacteristic.PropertyType', int]) -> 'QLowEnergyCharacteristic.PropertyTypes': ... + def __ror__ (self, other: 'QLowEnergyCharacteristic.PropertyType') -> 'QLowEnergyCharacteristic.PropertyTypes': ... + def __rand__(self, other: 'QLowEnergyCharacteristic.PropertyType') -> 'QLowEnergyCharacteristic.PropertyTypes': ... + def __rxor__(self, other: 'QLowEnergyCharacteristic.PropertyType') -> 'QLowEnergyCharacteristic.PropertyTypes': ... @typing.overload def __init__(self) -> None: ... @@ -1746,7 +1794,7 @@ class QLowEnergyController(QtCore.QObject): def __init__(self, remoteDevice: QBluetoothAddress, localDevice: QBluetoothAddress, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def remoteDeviceUuid(self) -> QBluetoothUuid: ... - def connectionUpdated(self, parameters: QLowEnergyConnectionParameters) -> None: ... + connectionUpdated: typing.ClassVar[QtCore.pyqtSignal] def role(self) -> 'QLowEnergyController.Role': ... def requestConnectionUpdate(self, parameters: QLowEnergyConnectionParameters) -> None: ... def addService(self, service: 'QLowEnergyServiceData', parent: typing.Optional[QtCore.QObject] = ...) -> 'QLowEnergyService': ... @@ -1760,17 +1808,14 @@ class QLowEnergyController(QtCore.QObject): @typing.overload @staticmethod def createCentral(remoteDevice: QBluetoothAddress, localDevice: QBluetoothAddress, parent: typing.Optional[QtCore.QObject] = ...) -> 'QLowEnergyController': ... - def discoveryFinished(self) -> None: ... - def serviceDiscovered(self, newService: QBluetoothUuid) -> None: ... - def stateChanged(self, state: 'QLowEnergyController.ControllerState') -> None: ... - def disconnected(self) -> None: ... - def connected(self) -> None: ... + discoveryFinished: typing.ClassVar[QtCore.pyqtSignal] + serviceDiscovered: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + disconnected: typing.ClassVar[QtCore.pyqtSignal] + connected: typing.ClassVar[QtCore.pyqtSignal] def remoteName(self) -> str: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QLowEnergyController.Error': ... - @typing.overload - def error(self, newError: 'QLowEnergyController.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def createServiceObject(self, service: QBluetoothUuid, parent: typing.Optional[QtCore.QObject] = ...) -> 'QLowEnergyService': ... def services(self) -> typing.List[QBluetoothUuid]: ... def discoverServices(self) -> None: ... @@ -1863,6 +1908,9 @@ class QLowEnergyService(QtCore.QObject): UnknownError = ... # type: QLowEnergyService.ServiceError class ServiceType(int): + def __or__ (self, other: 'QLowEnergyService.ServiceType') -> 'QLowEnergyService.ServiceTypes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QLowEnergyService.ServiceTypes': ... # type: ignore[override, misc] + PrimaryService = ... # type: QLowEnergyService.ServiceType IncludedService = ... # type: QLowEnergyService.ServiceType @@ -1877,31 +1925,36 @@ class QLowEnergyService(QtCore.QObject): def __init__(self, f: typing.Union['QLowEnergyService.ServiceTypes', 'QLowEnergyService.ServiceType']) -> None: ... @typing.overload def __init__(self, a0: 'QLowEnergyService.ServiceTypes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QLowEnergyService.ServiceTypes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... - - def descriptorRead(self, info: QLowEnergyDescriptor, value: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def characteristicRead(self, info: QLowEnergyCharacteristic, value: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... + def __or__ (self, other: typing.Union['QLowEnergyService.ServiceTypes', 'QLowEnergyService.ServiceType', int]) -> 'QLowEnergyService.ServiceTypes': ... + def __and__(self, other: typing.Union['QLowEnergyService.ServiceTypes', 'QLowEnergyService.ServiceType', int]) -> 'QLowEnergyService.ServiceTypes': ... + def __xor__(self, other: typing.Union['QLowEnergyService.ServiceTypes', 'QLowEnergyService.ServiceType', int]) -> 'QLowEnergyService.ServiceTypes': ... + def __ror__ (self, other: 'QLowEnergyService.ServiceType') -> 'QLowEnergyService.ServiceTypes': ... + def __rand__(self, other: 'QLowEnergyService.ServiceType') -> 'QLowEnergyService.ServiceTypes': ... + def __rxor__(self, other: 'QLowEnergyService.ServiceType') -> 'QLowEnergyService.ServiceTypes': ... + + descriptorRead: typing.ClassVar[QtCore.pyqtSignal] + characteristicRead: typing.ClassVar[QtCore.pyqtSignal] def readDescriptor(self, descriptor: QLowEnergyDescriptor) -> None: ... def readCharacteristic(self, characteristic: QLowEnergyCharacteristic) -> None: ... - def descriptorWritten(self, info: QLowEnergyDescriptor, value: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def characteristicWritten(self, info: QLowEnergyCharacteristic, value: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def characteristicChanged(self, info: QLowEnergyCharacteristic, value: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def stateChanged(self, newState: 'QLowEnergyService.ServiceState') -> None: ... + descriptorWritten: typing.ClassVar[QtCore.pyqtSignal] + characteristicWritten: typing.ClassVar[QtCore.pyqtSignal] + characteristicChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def writeDescriptor(self, descriptor: QLowEnergyDescriptor, newValue: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... def writeCharacteristic(self, characteristic: QLowEnergyCharacteristic, newValue: typing.Union[QtCore.QByteArray, bytes, bytearray], mode: 'QLowEnergyService.WriteMode' = ...) -> None: ... @typing.overload def contains(self, characteristic: QLowEnergyCharacteristic) -> bool: ... @typing.overload def contains(self, descriptor: QLowEnergyDescriptor) -> bool: ... - @typing.overload - def error(self) -> 'QLowEnergyService.ServiceError': ... - @typing.overload - def error(self, error: 'QLowEnergyService.ServiceError') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def discoverDetails(self) -> None: ... def serviceName(self) -> str: ... def serviceUuid(self) -> QBluetoothUuid: ... diff --git a/PyQt5-stubs/QtChart.pyi b/PyQt5-stubs/QtChart.pyi index 5520a571..19ba5d36 100644 --- a/PyQt5-stubs/QtChart.pyi +++ b/PyQt5-stubs/QtChart.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtChart module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -65,21 +65,29 @@ class QAbstractAxis(QtCore.QObject): def __init__(self, f: typing.Union['QAbstractAxis.AxisTypes', 'QAbstractAxis.AxisType']) -> None: ... @typing.overload def __init__(self, a0: 'QAbstractAxis.AxisTypes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QAbstractAxis.AxisTypes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... - - def labelsEditableChanged(self, editable: bool) -> None: ... + def __or__ (self, other: typing.Union['QAbstractAxis.AxisTypes', 'QAbstractAxis.AxisType', int]) -> 'QAbstractAxis.AxisTypes': ... + def __and__(self, other: typing.Union['QAbstractAxis.AxisTypes', 'QAbstractAxis.AxisType', int]) -> 'QAbstractAxis.AxisTypes': ... + def __xor__(self, other: typing.Union['QAbstractAxis.AxisTypes', 'QAbstractAxis.AxisType', int]) -> 'QAbstractAxis.AxisTypes': ... + def __ror__ (self, other: 'QAbstractAxis.AxisType') -> 'QAbstractAxis.AxisTypes': ... + def __rand__(self, other: 'QAbstractAxis.AxisType') -> 'QAbstractAxis.AxisTypes': ... + def __rxor__(self, other: 'QAbstractAxis.AxisType') -> 'QAbstractAxis.AxisTypes': ... + + labelsEditableChanged: typing.ClassVar[QtCore.pyqtSignal] def labelsEditable(self) -> bool: ... def setLabelsEditable(self, editable: bool = ...) -> None: ... - def reverseChanged(self, reverse: bool) -> None: ... - def minorGridLineColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def gridLineColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def minorGridLinePenChanged(self, pen: typing.Union[QtGui.QPen, QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def minorGridVisibleChanged(self, visible: bool) -> None: ... + reverseChanged: typing.ClassVar[QtCore.pyqtSignal] + minorGridLineColorChanged: typing.ClassVar[QtCore.pyqtSignal] + gridLineColorChanged: typing.ClassVar[QtCore.pyqtSignal] + minorGridLinePenChanged: typing.ClassVar[QtCore.pyqtSignal] + minorGridVisibleChanged: typing.ClassVar[QtCore.pyqtSignal] def isReverse(self) -> bool: ... def setReverse(self, reverse: bool = ...) -> None: ... def minorGridLineColor(self) -> QtGui.QColor: ... @@ -90,17 +98,17 @@ class QAbstractAxis(QtCore.QObject): def setMinorGridLinePen(self, pen: typing.Union[QtGui.QPen, QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... def setMinorGridLineVisible(self, visible: bool = ...) -> None: ... def isMinorGridLineVisible(self) -> bool: ... - def shadesBrushChanged(self, brush: typing.Union[QtGui.QBrush, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def shadesPenChanged(self, pen: typing.Union[QtGui.QPen, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def titleFontChanged(self, font: QtGui.QFont) -> None: ... - def titleVisibleChanged(self, visible: bool) -> None: ... - def titleBrushChanged(self, brush: typing.Union[QtGui.QBrush, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def titleTextChanged(self, title: str) -> None: ... - def gridLinePenChanged(self, pen: typing.Union[QtGui.QPen, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def labelsAngleChanged(self, angle: int) -> None: ... - def labelsFontChanged(self, pen: QtGui.QFont) -> None: ... - def labelsBrushChanged(self, brush: typing.Union[QtGui.QBrush, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def linePenChanged(self, pen: typing.Union[QtGui.QPen, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... + shadesBrushChanged: typing.ClassVar[QtCore.pyqtSignal] + shadesPenChanged: typing.ClassVar[QtCore.pyqtSignal] + titleFontChanged: typing.ClassVar[QtCore.pyqtSignal] + titleVisibleChanged: typing.ClassVar[QtCore.pyqtSignal] + titleBrushChanged: typing.ClassVar[QtCore.pyqtSignal] + titleTextChanged: typing.ClassVar[QtCore.pyqtSignal] + gridLinePenChanged: typing.ClassVar[QtCore.pyqtSignal] + labelsAngleChanged: typing.ClassVar[QtCore.pyqtSignal] + labelsFontChanged: typing.ClassVar[QtCore.pyqtSignal] + labelsBrushChanged: typing.ClassVar[QtCore.pyqtSignal] + linePenChanged: typing.ClassVar[QtCore.pyqtSignal] def alignment(self) -> QtCore.Qt.Alignment: ... def titleText(self) -> str: ... def setTitleText(self, title: str) -> None: ... @@ -110,15 +118,15 @@ class QAbstractAxis(QtCore.QObject): def setTitleBrush(self, brush: typing.Union[QtGui.QBrush, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def setTitleVisible(self, visible: bool = ...) -> None: ... def isTitleVisible(self) -> bool: ... - def shadesBorderColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def shadesColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def shadesVisibleChanged(self, visible: bool) -> None: ... - def labelsColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def colorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def gridVisibleChanged(self, visible: bool) -> None: ... - def labelsVisibleChanged(self, visible: bool) -> None: ... - def lineVisibleChanged(self, visible: bool) -> None: ... - def visibleChanged(self, visible: bool) -> None: ... + shadesBorderColorChanged: typing.ClassVar[QtCore.pyqtSignal] + shadesColorChanged: typing.ClassVar[QtCore.pyqtSignal] + shadesVisibleChanged: typing.ClassVar[QtCore.pyqtSignal] + labelsColorChanged: typing.ClassVar[QtCore.pyqtSignal] + colorChanged: typing.ClassVar[QtCore.pyqtSignal] + gridVisibleChanged: typing.ClassVar[QtCore.pyqtSignal] + labelsVisibleChanged: typing.ClassVar[QtCore.pyqtSignal] + lineVisibleChanged: typing.ClassVar[QtCore.pyqtSignal] + visibleChanged: typing.ClassVar[QtCore.pyqtSignal] def orientation(self) -> QtCore.Qt.Orientation: ... def hide(self) -> None: ... def show(self) -> None: ... @@ -190,17 +198,17 @@ class QAbstractSeries(QtCore.QObject): SeriesTypeBoxPlot = ... # type: QAbstractSeries.SeriesType SeriesTypeCandlestick = ... # type: QAbstractSeries.SeriesType - def useOpenGLChanged(self) -> None: ... + useOpenGLChanged: typing.ClassVar[QtCore.pyqtSignal] def useOpenGL(self) -> bool: ... def setUseOpenGL(self, enable: bool = ...) -> None: ... - def opacityChanged(self) -> None: ... + opacityChanged: typing.ClassVar[QtCore.pyqtSignal] def attachedAxes(self) -> typing.List['QAbstractAxis']: ... def detachAxis(self, axis: 'QAbstractAxis') -> bool: ... def attachAxis(self, axis: 'QAbstractAxis') -> bool: ... def setOpacity(self, opacity: float) -> None: ... def opacity(self) -> float: ... - def visibleChanged(self) -> None: ... - def nameChanged(self) -> None: ... + visibleChanged: typing.ClassVar[QtCore.pyqtSignal] + nameChanged: typing.ClassVar[QtCore.pyqtSignal] def hide(self) -> None: ... def show(self) -> None: ... def chart(self) -> 'QChart': ... @@ -223,27 +231,27 @@ class QAbstractBarSeries('QAbstractSeries'): LabelsInsideBase = ... # type: QAbstractBarSeries.LabelsPosition LabelsOutsideEnd = ... # type: QAbstractBarSeries.LabelsPosition - def labelsPrecisionChanged(self, precision: int) -> None: ... + labelsPrecisionChanged: typing.ClassVar[QtCore.pyqtSignal] def labelsPrecision(self) -> int: ... def setLabelsPrecision(self, precision: int) -> None: ... - def labelsAngleChanged(self, angle: float) -> None: ... + labelsAngleChanged: typing.ClassVar[QtCore.pyqtSignal] def labelsAngle(self) -> float: ... def setLabelsAngle(self, angle: float) -> None: ... - def doubleClicked(self, index: int, barset: 'QBarSet') -> None: ... - def released(self, index: int, barset: 'QBarSet') -> None: ... - def pressed(self, index: int, barset: 'QBarSet') -> None: ... - def labelsPositionChanged(self, position: 'QAbstractBarSeries.LabelsPosition') -> None: ... - def labelsFormatChanged(self, format: str) -> None: ... + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + labelsPositionChanged: typing.ClassVar[QtCore.pyqtSignal] + labelsFormatChanged: typing.ClassVar[QtCore.pyqtSignal] def labelsPosition(self) -> 'QAbstractBarSeries.LabelsPosition': ... def setLabelsPosition(self, position: 'QAbstractBarSeries.LabelsPosition') -> None: ... def labelsFormat(self) -> str: ... def setLabelsFormat(self, format: str) -> None: ... - def barsetsRemoved(self, sets: typing.Iterable['QBarSet']) -> None: ... - def barsetsAdded(self, sets: typing.Iterable['QBarSet']) -> None: ... - def labelsVisibleChanged(self) -> None: ... - def countChanged(self) -> None: ... - def hovered(self, status: bool, index: int, barset: 'QBarSet') -> None: ... - def clicked(self, index: int, barset: 'QBarSet') -> None: ... + barsetsRemoved: typing.ClassVar[QtCore.pyqtSignal] + barsetsAdded: typing.ClassVar[QtCore.pyqtSignal] + labelsVisibleChanged: typing.ClassVar[QtCore.pyqtSignal] + countChanged: typing.ClassVar[QtCore.pyqtSignal] + hovered: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] def take(self, set: 'QBarSet') -> bool: ... def isLabelsVisible(self) -> bool: ... def setLabelsVisible(self, visible: bool = ...) -> None: ... @@ -277,17 +285,17 @@ class QLegendMarker(QtCore.QObject): LegendMarkerTypeBoxPlot = ... # type: QLegendMarker.LegendMarkerType LegendMarkerTypeCandlestick = ... # type: QLegendMarker.LegendMarkerType - def shapeChanged(self) -> None: ... + shapeChanged: typing.ClassVar[QtCore.pyqtSignal] def setShape(self, shape: 'QLegend.MarkerShape') -> None: ... def shape(self) -> 'QLegend.MarkerShape': ... - def visibleChanged(self) -> None: ... - def brushChanged(self) -> None: ... - def penChanged(self) -> None: ... - def fontChanged(self) -> None: ... - def labelBrushChanged(self) -> None: ... - def labelChanged(self) -> None: ... - def hovered(self, status: bool) -> None: ... - def clicked(self) -> None: ... + visibleChanged: typing.ClassVar[QtCore.pyqtSignal] + brushChanged: typing.ClassVar[QtCore.pyqtSignal] + penChanged: typing.ClassVar[QtCore.pyqtSignal] + fontChanged: typing.ClassVar[QtCore.pyqtSignal] + labelBrushChanged: typing.ClassVar[QtCore.pyqtSignal] + labelChanged: typing.ClassVar[QtCore.pyqtSignal] + hovered: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] def series(self) -> 'QAbstractSeries': ... def setVisible(self, visible: bool) -> None: ... def isVisible(self) -> bool: ... @@ -317,16 +325,16 @@ class QAreaSeries('QAbstractSeries'): @typing.overload def __init__(self, upperSeries: 'QLineSeries', lowerSeries: typing.Optional['QLineSeries'] = ...) -> None: ... - def pointLabelsClippingChanged(self, clipping: bool) -> None: ... + pointLabelsClippingChanged: typing.ClassVar[QtCore.pyqtSignal] def pointLabelsClipping(self) -> bool: ... def setPointLabelsClipping(self, enable: bool = ...) -> None: ... - def doubleClicked(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... - def released(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... - def pressed(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... - def pointLabelsColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def pointLabelsFontChanged(self, font: QtGui.QFont) -> None: ... - def pointLabelsVisibilityChanged(self, visible: bool) -> None: ... - def pointLabelsFormatChanged(self, format: str) -> None: ... + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + pointLabelsColorChanged: typing.ClassVar[QtCore.pyqtSignal] + pointLabelsFontChanged: typing.ClassVar[QtCore.pyqtSignal] + pointLabelsVisibilityChanged: typing.ClassVar[QtCore.pyqtSignal] + pointLabelsFormatChanged: typing.ClassVar[QtCore.pyqtSignal] def pointLabelsColor(self) -> QtGui.QColor: ... def setPointLabelsColor(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def pointLabelsFont(self) -> QtGui.QFont: ... @@ -335,11 +343,11 @@ class QAreaSeries('QAbstractSeries'): def setPointLabelsVisible(self, visible: bool = ...) -> None: ... def pointLabelsFormat(self) -> str: ... def setPointLabelsFormat(self, format: str) -> None: ... - def hovered(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint], state: bool) -> None: ... - def selected(self) -> None: ... - def clicked(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... - def colorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def borderColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... + hovered: typing.ClassVar[QtCore.pyqtSignal] + selected: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] + colorChanged: typing.ClassVar[QtCore.pyqtSignal] + borderColorChanged: typing.ClassVar[QtCore.pyqtSignal] def borderColor(self) -> QtGui.QColor: ... def setBorderColor(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def color(self) -> QtGui.QColor: ... @@ -360,11 +368,11 @@ class QBarCategoryAxis('QAbstractAxis'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def countChanged(self) -> None: ... - def rangeChanged(self, min: str, max: str) -> None: ... - def maxChanged(self, max: str) -> None: ... - def minChanged(self, min: str) -> None: ... - def categoriesChanged(self) -> None: ... + countChanged: typing.ClassVar[QtCore.pyqtSignal] + rangeChanged: typing.ClassVar[QtCore.pyqtSignal] + maxChanged: typing.ClassVar[QtCore.pyqtSignal] + minChanged: typing.ClassVar[QtCore.pyqtSignal] + categoriesChanged: typing.ClassVar[QtCore.pyqtSignal] def setRange(self, minCategory: str, maxCategory: str) -> None: ... def max(self) -> str: ... def setMax(self, maxCategory: str) -> None: ... @@ -403,22 +411,22 @@ class QBarSet(QtCore.QObject): def __init__(self, name: str, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def doubleClicked(self, index: int) -> None: ... - def released(self, index: int) -> None: ... - def pressed(self, index: int) -> None: ... - def labelColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def borderColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def colorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def hovered(self, status: bool, index: int) -> None: ... - def clicked(self, index: int) -> None: ... - def valueChanged(self, index: int) -> None: ... - def valuesRemoved(self, index: int, count: int) -> None: ... - def valuesAdded(self, index: int, count: int) -> None: ... - def labelFontChanged(self) -> None: ... - def labelBrushChanged(self) -> None: ... - def labelChanged(self) -> None: ... - def brushChanged(self) -> None: ... - def penChanged(self) -> None: ... + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + labelColorChanged: typing.ClassVar[QtCore.pyqtSignal] + borderColorChanged: typing.ClassVar[QtCore.pyqtSignal] + colorChanged: typing.ClassVar[QtCore.pyqtSignal] + hovered: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] + valueChanged: typing.ClassVar[QtCore.pyqtSignal] + valuesRemoved: typing.ClassVar[QtCore.pyqtSignal] + valuesAdded: typing.ClassVar[QtCore.pyqtSignal] + labelFontChanged: typing.ClassVar[QtCore.pyqtSignal] + labelBrushChanged: typing.ClassVar[QtCore.pyqtSignal] + labelChanged: typing.ClassVar[QtCore.pyqtSignal] + brushChanged: typing.ClassVar[QtCore.pyqtSignal] + penChanged: typing.ClassVar[QtCore.pyqtSignal] def setLabelColor(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def labelColor(self) -> QtGui.QColor: ... def setBorderColor(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... @@ -459,18 +467,18 @@ class QBoxPlotSeries('QAbstractSeries'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def doubleClicked(self, boxset: 'QBoxSet') -> None: ... - def released(self, boxset: 'QBoxSet') -> None: ... - def pressed(self, boxset: 'QBoxSet') -> None: ... - def boxsetsRemoved(self, sets: typing.Iterable['QBoxSet']) -> None: ... - def boxsetsAdded(self, sets: typing.Iterable['QBoxSet']) -> None: ... - def boxWidthChanged(self) -> None: ... - def boxOutlineVisibilityChanged(self) -> None: ... - def brushChanged(self) -> None: ... - def penChanged(self) -> None: ... - def countChanged(self) -> None: ... - def hovered(self, status: bool, boxset: 'QBoxSet') -> None: ... - def clicked(self, boxset: 'QBoxSet') -> None: ... + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + boxsetsRemoved: typing.ClassVar[QtCore.pyqtSignal] + boxsetsAdded: typing.ClassVar[QtCore.pyqtSignal] + boxWidthChanged: typing.ClassVar[QtCore.pyqtSignal] + boxOutlineVisibilityChanged: typing.ClassVar[QtCore.pyqtSignal] + brushChanged: typing.ClassVar[QtCore.pyqtSignal] + penChanged: typing.ClassVar[QtCore.pyqtSignal] + countChanged: typing.ClassVar[QtCore.pyqtSignal] + hovered: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] def pen(self) -> QtGui.QPen: ... def setPen(self, pen: typing.Union[QtGui.QPen, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def brush(self) -> QtGui.QBrush: ... @@ -512,16 +520,16 @@ class QBoxSet(QtCore.QObject): @typing.overload def __init__(self, le: float, lq: float, m: float, uq: float, ue: float, label: str = ..., parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def doubleClicked(self) -> None: ... - def released(self) -> None: ... - def pressed(self) -> None: ... - def cleared(self) -> None: ... - def valueChanged(self, index: int) -> None: ... - def valuesChanged(self) -> None: ... - def brushChanged(self) -> None: ... - def penChanged(self) -> None: ... - def hovered(self, status: bool) -> None: ... - def clicked(self) -> None: ... + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + cleared: typing.ClassVar[QtCore.pyqtSignal] + valueChanged: typing.ClassVar[QtCore.pyqtSignal] + valuesChanged: typing.ClassVar[QtCore.pyqtSignal] + brushChanged: typing.ClassVar[QtCore.pyqtSignal] + penChanged: typing.ClassVar[QtCore.pyqtSignal] + hovered: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] def brush(self) -> QtGui.QBrush: ... def setBrush(self, brush: typing.Union[QtGui.QBrush, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def pen(self) -> QtGui.QPen: ... @@ -564,8 +572,8 @@ class QCandlestickModelMapper(QtCore.QObject): def setOpen(self, open: int) -> None: ... def timestamp(self) -> int: ... def setTimestamp(self, timestamp: int) -> None: ... - def seriesReplaced(self) -> None: ... - def modelReplaced(self) -> None: ... + seriesReplaced: typing.ClassVar[QtCore.pyqtSignal] + modelReplaced: typing.ClassVar[QtCore.pyqtSignal] def orientation(self) -> QtCore.Qt.Orientation: ... def series(self) -> 'QCandlestickSeries': ... def setSeries(self, series: 'QCandlestickSeries') -> None: ... @@ -576,24 +584,24 @@ class QCandlestickSeries('QAbstractSeries'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def penChanged(self) -> None: ... - def brushChanged(self) -> None: ... - def decreasingColorChanged(self) -> None: ... - def increasingColorChanged(self) -> None: ... - def capsVisibilityChanged(self) -> None: ... - def capsWidthChanged(self) -> None: ... - def bodyOutlineVisibilityChanged(self) -> None: ... - def bodyWidthChanged(self) -> None: ... - def minimumColumnWidthChanged(self) -> None: ... - def maximumColumnWidthChanged(self) -> None: ... - def countChanged(self) -> None: ... - def candlestickSetsRemoved(self, sets: typing.Iterable['QCandlestickSet']) -> None: ... - def candlestickSetsAdded(self, sets: typing.Iterable['QCandlestickSet']) -> None: ... - def doubleClicked(self, set: 'QCandlestickSet') -> None: ... - def released(self, set: 'QCandlestickSet') -> None: ... - def pressed(self, set: 'QCandlestickSet') -> None: ... - def hovered(self, status: bool, set: 'QCandlestickSet') -> None: ... - def clicked(self, set: 'QCandlestickSet') -> None: ... + penChanged: typing.ClassVar[QtCore.pyqtSignal] + brushChanged: typing.ClassVar[QtCore.pyqtSignal] + decreasingColorChanged: typing.ClassVar[QtCore.pyqtSignal] + increasingColorChanged: typing.ClassVar[QtCore.pyqtSignal] + capsVisibilityChanged: typing.ClassVar[QtCore.pyqtSignal] + capsWidthChanged: typing.ClassVar[QtCore.pyqtSignal] + bodyOutlineVisibilityChanged: typing.ClassVar[QtCore.pyqtSignal] + bodyWidthChanged: typing.ClassVar[QtCore.pyqtSignal] + minimumColumnWidthChanged: typing.ClassVar[QtCore.pyqtSignal] + maximumColumnWidthChanged: typing.ClassVar[QtCore.pyqtSignal] + countChanged: typing.ClassVar[QtCore.pyqtSignal] + candlestickSetsRemoved: typing.ClassVar[QtCore.pyqtSignal] + candlestickSetsAdded: typing.ClassVar[QtCore.pyqtSignal] + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + hovered: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] def pen(self) -> QtGui.QPen: ... def setPen(self, pen: typing.Union[QtGui.QPen, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def brush(self) -> QtGui.QBrush: ... @@ -637,18 +645,18 @@ class QCandlestickSet(QtCore.QObject): @typing.overload def __init__(self, open: float, high: float, low: float, close: float, timestamp: float = ..., parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def penChanged(self) -> None: ... - def brushChanged(self) -> None: ... - def closeChanged(self) -> None: ... - def lowChanged(self) -> None: ... - def highChanged(self) -> None: ... - def openChanged(self) -> None: ... - def timestampChanged(self) -> None: ... - def doubleClicked(self) -> None: ... - def released(self) -> None: ... - def pressed(self) -> None: ... - def hovered(self, status: bool) -> None: ... - def clicked(self) -> None: ... + penChanged: typing.ClassVar[QtCore.pyqtSignal] + brushChanged: typing.ClassVar[QtCore.pyqtSignal] + closeChanged: typing.ClassVar[QtCore.pyqtSignal] + lowChanged: typing.ClassVar[QtCore.pyqtSignal] + highChanged: typing.ClassVar[QtCore.pyqtSignal] + openChanged: typing.ClassVar[QtCore.pyqtSignal] + timestampChanged: typing.ClassVar[QtCore.pyqtSignal] + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + hovered: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] def pen(self) -> QtGui.QPen: ... def setPen(self, pen: typing.Union[QtGui.QPen, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def brush(self) -> QtGui.QBrush: ... @@ -675,23 +683,23 @@ class QValueAxis('QAbstractAxis'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def tickTypeChanged(self, type: 'QValueAxis.TickType') -> None: ... - def tickAnchorChanged(self, anchor: float) -> None: ... - def tickIntervalChanged(self, interval: float) -> None: ... + tickTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + tickAnchorChanged: typing.ClassVar[QtCore.pyqtSignal] + tickIntervalChanged: typing.ClassVar[QtCore.pyqtSignal] def tickType(self) -> 'QValueAxis.TickType': ... def setTickType(self, type: 'QValueAxis.TickType') -> None: ... def tickInterval(self) -> float: ... def setTickInterval(self, insterval: float) -> None: ... def tickAnchor(self) -> float: ... def setTickAnchor(self, anchor: float) -> None: ... - def minorTickCountChanged(self, tickCount: int) -> None: ... + minorTickCountChanged: typing.ClassVar[QtCore.pyqtSignal] def minorTickCount(self) -> int: ... def setMinorTickCount(self, count: int) -> None: ... - def labelFormatChanged(self, format: str) -> None: ... - def tickCountChanged(self, tickCount: int) -> None: ... - def rangeChanged(self, min: float, max: float) -> None: ... - def maxChanged(self, max: float) -> None: ... - def minChanged(self, min: float) -> None: ... + labelFormatChanged: typing.ClassVar[QtCore.pyqtSignal] + tickCountChanged: typing.ClassVar[QtCore.pyqtSignal] + rangeChanged: typing.ClassVar[QtCore.pyqtSignal] + maxChanged: typing.ClassVar[QtCore.pyqtSignal] + minChanged: typing.ClassVar[QtCore.pyqtSignal] def applyNiceNumbers(self) -> None: ... def labelFormat(self) -> str: ... def setLabelFormat(self, format: str) -> None: ... @@ -715,10 +723,10 @@ class QCategoryAxis('QValueAxis'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def labelsPositionChanged(self, position: 'QCategoryAxis.AxisLabelsPosition') -> None: ... + labelsPositionChanged: typing.ClassVar[QtCore.pyqtSignal] def setLabelsPosition(self, position: 'QCategoryAxis.AxisLabelsPosition') -> None: ... def labelsPosition(self) -> 'QCategoryAxis.AxisLabelsPosition': ... - def categoriesChanged(self) -> None: ... + categoriesChanged: typing.ClassVar[QtCore.pyqtSignal] def __len__(self) -> int: ... def count(self) -> int: ... def categoriesLabels(self) -> typing.List[str]: ... @@ -742,6 +750,9 @@ class QChart(QtWidgets.QGraphicsWidget): ChartTypePolar = ... # type: QChart.ChartType class AnimationOption(int): + def __or__ (self, other: typing.Union[int, 'QChart.AnimationOption']) -> 'QChart.AnimationOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QChart.AnimationOptions': ... # type: ignore[override, misc] + NoAnimation = ... # type: QChart.AnimationOption GridAxisAnimations = ... # type: QChart.AnimationOption SeriesAnimations = ... # type: QChart.AnimationOption @@ -779,12 +790,20 @@ class QChart(QtWidgets.QGraphicsWidget): def __init__(self, f: typing.Union['QChart.AnimationOptions', 'QChart.AnimationOption']) -> None: ... @typing.overload def __init__(self, a0: 'QChart.AnimationOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QChart.AnimationOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QChart.AnimationOptions', 'QChart.AnimationOption', int]) -> 'QChart.AnimationOptions': ... + def __and__(self, other: typing.Union['QChart.AnimationOptions', 'QChart.AnimationOption', int]) -> 'QChart.AnimationOptions': ... + def __xor__(self, other: typing.Union['QChart.AnimationOptions', 'QChart.AnimationOption', int]) -> 'QChart.AnimationOptions': ... + def __ror__ (self, other: 'QChart.AnimationOption') -> 'QChart.AnimationOptions': ... + def __rand__(self, other: 'QChart.AnimationOption') -> 'QChart.AnimationOptions': ... + def __rxor__(self, other: 'QChart.AnimationOption') -> 'QChart.AnimationOptions': ... def __init__(self, parent: typing.Optional[QtWidgets.QGraphicsItem] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> None: ... @@ -792,7 +811,7 @@ class QChart(QtWidgets.QGraphicsWidget): def setAnimationEasingCurve(self, curve: typing.Union[QtCore.QEasingCurve, QtCore.QEasingCurve.Type]) -> None: ... def animationDuration(self) -> int: ... def setAnimationDuration(self, msecs: int) -> None: ... - def plotAreaChanged(self, plotArea: QtCore.QRectF) -> None: ... + plotAreaChanged: typing.ClassVar[QtCore.pyqtSignal] def locale(self) -> QtCore.QLocale: ... def setLocale(self, locale: QtCore.QLocale) -> None: ... def localizeNumbers(self) -> bool: ... @@ -874,12 +893,20 @@ class QChartView(QtWidgets.QGraphicsView): def __init__(self, f: typing.Union['QChartView.RubberBands', 'QChartView.RubberBand']) -> None: ... @typing.overload def __init__(self, a0: 'QChartView.RubberBands') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QChartView.RubberBands': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QChartView.RubberBands', 'QChartView.RubberBand', int]) -> 'QChartView.RubberBands': ... + def __and__(self, other: typing.Union['QChartView.RubberBands', 'QChartView.RubberBand', int]) -> 'QChartView.RubberBands': ... + def __xor__(self, other: typing.Union['QChartView.RubberBands', 'QChartView.RubberBand', int]) -> 'QChartView.RubberBands': ... + def __ror__ (self, other: 'QChartView.RubberBand') -> 'QChartView.RubberBands': ... + def __rand__(self, other: 'QChartView.RubberBand') -> 'QChartView.RubberBands': ... + def __rxor__(self, other: 'QChartView.RubberBand') -> 'QChartView.RubberBands': ... @typing.overload def __init__(self, parent: typing.Optional[QtWidgets.QWidget] = ...) -> None: ... @@ -900,11 +927,11 @@ class QDateTimeAxis('QAbstractAxis'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def tickCountChanged(self, tick: int) -> None: ... - def formatChanged(self, format: str) -> None: ... - def rangeChanged(self, min: typing.Union[QtCore.QDateTime, datetime.datetime], max: typing.Union[QtCore.QDateTime, datetime.datetime]) -> None: ... - def maxChanged(self, max: typing.Union[QtCore.QDateTime, datetime.datetime]) -> None: ... - def minChanged(self, min: typing.Union[QtCore.QDateTime, datetime.datetime]) -> None: ... + tickCountChanged: typing.ClassVar[QtCore.pyqtSignal] + formatChanged: typing.ClassVar[QtCore.pyqtSignal] + rangeChanged: typing.ClassVar[QtCore.pyqtSignal] + maxChanged: typing.ClassVar[QtCore.pyqtSignal] + minChanged: typing.ClassVar[QtCore.pyqtSignal] def tickCount(self) -> int: ... def setTickCount(self, count: int) -> None: ... def format(self) -> str: ... @@ -920,12 +947,12 @@ class QHBarModelMapper(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def columnCountChanged(self) -> None: ... - def firstColumnChanged(self) -> None: ... - def lastBarSetRowChanged(self) -> None: ... - def firstBarSetRowChanged(self) -> None: ... - def modelReplaced(self) -> None: ... - def seriesReplaced(self) -> None: ... + columnCountChanged: typing.ClassVar[QtCore.pyqtSignal] + firstColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + lastBarSetRowChanged: typing.ClassVar[QtCore.pyqtSignal] + firstBarSetRowChanged: typing.ClassVar[QtCore.pyqtSignal] + modelReplaced: typing.ClassVar[QtCore.pyqtSignal] + seriesReplaced: typing.ClassVar[QtCore.pyqtSignal] def setColumnCount(self, columnCount: int) -> None: ... def columnCount(self) -> int: ... def setFirstColumn(self, firstColumn: int) -> None: ... @@ -943,12 +970,12 @@ class QHBoxPlotModelMapper(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def columnCountChanged(self) -> None: ... - def firstColumnChanged(self) -> None: ... - def lastBoxSetRowChanged(self) -> None: ... - def firstBoxSetRowChanged(self) -> None: ... - def modelReplaced(self) -> None: ... - def seriesReplaced(self) -> None: ... + columnCountChanged: typing.ClassVar[QtCore.pyqtSignal] + firstColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + lastBoxSetRowChanged: typing.ClassVar[QtCore.pyqtSignal] + firstBoxSetRowChanged: typing.ClassVar[QtCore.pyqtSignal] + modelReplaced: typing.ClassVar[QtCore.pyqtSignal] + seriesReplaced: typing.ClassVar[QtCore.pyqtSignal] def setColumnCount(self, rowCount: int) -> None: ... def columnCount(self) -> int: ... def setFirstColumn(self, firstColumn: int) -> None: ... @@ -966,13 +993,13 @@ class QHCandlestickModelMapper('QCandlestickModelMapper'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def lastSetRowChanged(self) -> None: ... - def firstSetRowChanged(self) -> None: ... - def closeColumnChanged(self) -> None: ... - def lowColumnChanged(self) -> None: ... - def highColumnChanged(self) -> None: ... - def openColumnChanged(self) -> None: ... - def timestampColumnChanged(self) -> None: ... + lastSetRowChanged: typing.ClassVar[QtCore.pyqtSignal] + firstSetRowChanged: typing.ClassVar[QtCore.pyqtSignal] + closeColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + lowColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + highColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + openColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + timestampColumnChanged: typing.ClassVar[QtCore.pyqtSignal] def lastSetRow(self) -> int: ... def setLastSetRow(self, lastSetRow: int) -> None: ... def firstSetRow(self) -> int: ... @@ -1011,12 +1038,12 @@ class QHPieModelMapper(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def columnCountChanged(self) -> None: ... - def firstColumnChanged(self) -> None: ... - def labelsRowChanged(self) -> None: ... - def valuesRowChanged(self) -> None: ... - def modelReplaced(self) -> None: ... - def seriesReplaced(self) -> None: ... + columnCountChanged: typing.ClassVar[QtCore.pyqtSignal] + firstColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + labelsRowChanged: typing.ClassVar[QtCore.pyqtSignal] + valuesRowChanged: typing.ClassVar[QtCore.pyqtSignal] + modelReplaced: typing.ClassVar[QtCore.pyqtSignal] + seriesReplaced: typing.ClassVar[QtCore.pyqtSignal] def setColumnCount(self, columnCount: int) -> None: ... def columnCount(self) -> int: ... def setFirstColumn(self, firstColumn: int) -> None: ... @@ -1034,12 +1061,12 @@ class QHXYModelMapper(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def columnCountChanged(self) -> None: ... - def firstColumnChanged(self) -> None: ... - def yRowChanged(self) -> None: ... - def xRowChanged(self) -> None: ... - def modelReplaced(self) -> None: ... - def seriesReplaced(self) -> None: ... + columnCountChanged: typing.ClassVar[QtCore.pyqtSignal] + firstColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + yRowChanged: typing.ClassVar[QtCore.pyqtSignal] + xRowChanged: typing.ClassVar[QtCore.pyqtSignal] + modelReplaced: typing.ClassVar[QtCore.pyqtSignal] + seriesReplaced: typing.ClassVar[QtCore.pyqtSignal] def setColumnCount(self, columnCount: int) -> None: ... def columnCount(self) -> int: ... def setFirstColumn(self, firstColumn: int) -> None: ... @@ -1066,22 +1093,22 @@ class QLegend(QtWidgets.QGraphicsWidget): MarkerShapeCircle = ... # type: QLegend.MarkerShape MarkerShapeFromSeries = ... # type: QLegend.MarkerShape - def markerShapeChanged(self, shape: 'QLegend.MarkerShape') -> None: ... + markerShapeChanged: typing.ClassVar[QtCore.pyqtSignal] def setMarkerShape(self, shape: 'QLegend.MarkerShape') -> None: ... def markerShape(self) -> 'QLegend.MarkerShape': ... - def showToolTipsChanged(self, showToolTips: bool) -> None: ... + showToolTipsChanged: typing.ClassVar[QtCore.pyqtSignal] def setShowToolTips(self, show: bool) -> None: ... def showToolTips(self) -> bool: ... - def reverseMarkersChanged(self, reverseMarkers: bool) -> None: ... + reverseMarkersChanged: typing.ClassVar[QtCore.pyqtSignal] def setReverseMarkers(self, reverseMarkers: bool = ...) -> None: ... def reverseMarkers(self) -> bool: ... def showEvent(self, event: QtGui.QShowEvent) -> None: ... def hideEvent(self, event: QtGui.QHideEvent) -> None: ... - def labelColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def fontChanged(self, font: QtGui.QFont) -> None: ... - def borderColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def colorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def backgroundVisibleChanged(self, visible: bool) -> None: ... + labelColorChanged: typing.ClassVar[QtCore.pyqtSignal] + fontChanged: typing.ClassVar[QtCore.pyqtSignal] + borderColorChanged: typing.ClassVar[QtCore.pyqtSignal] + colorChanged: typing.ClassVar[QtCore.pyqtSignal] + backgroundVisibleChanged: typing.ClassVar[QtCore.pyqtSignal] def markers(self, series: typing.Optional['QAbstractSeries'] = ...) -> typing.List['QLegendMarker']: ... def labelColor(self) -> QtGui.QColor: ... def setLabelColor(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... @@ -1108,20 +1135,20 @@ class QLegend(QtWidgets.QGraphicsWidget): class QXYSeries('QAbstractSeries'): - def penChanged(self, pen: typing.Union[QtGui.QPen, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def pointsRemoved(self, index: int, count: int) -> None: ... - def pointLabelsClippingChanged(self, clipping: bool) -> None: ... + penChanged: typing.ClassVar[QtCore.pyqtSignal] + pointsRemoved: typing.ClassVar[QtCore.pyqtSignal] + pointLabelsClippingChanged: typing.ClassVar[QtCore.pyqtSignal] def pointLabelsClipping(self) -> bool: ... def setPointLabelsClipping(self, enable: bool = ...) -> None: ... def pointsVector(self) -> typing.List[QtCore.QPointF]: ... def removePoints(self, index: int, count: int) -> None: ... - def doubleClicked(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... - def released(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... - def pressed(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... - def pointLabelsColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def pointLabelsFontChanged(self, font: QtGui.QFont) -> None: ... - def pointLabelsVisibilityChanged(self, visible: bool) -> None: ... - def pointLabelsFormatChanged(self, format: str) -> None: ... + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + pointLabelsColorChanged: typing.ClassVar[QtCore.pyqtSignal] + pointLabelsFontChanged: typing.ClassVar[QtCore.pyqtSignal] + pointLabelsVisibilityChanged: typing.ClassVar[QtCore.pyqtSignal] + pointLabelsFormatChanged: typing.ClassVar[QtCore.pyqtSignal] def pointLabelsColor(self) -> QtGui.QColor: ... def setPointLabelsColor(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def pointLabelsFont(self) -> QtGui.QFont: ... @@ -1130,13 +1157,13 @@ class QXYSeries('QAbstractSeries'): def setPointLabelsVisible(self, visible: bool = ...) -> None: ... def pointLabelsFormat(self) -> str: ... def setPointLabelsFormat(self, format: str) -> None: ... - def hovered(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint], state: bool) -> None: ... - def pointsReplaced(self) -> None: ... - def pointAdded(self, index: int) -> None: ... - def pointRemoved(self, index: int) -> None: ... - def pointReplaced(self, index: int) -> None: ... - def colorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def clicked(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... + hovered: typing.ClassVar[QtCore.pyqtSignal] + pointsReplaced: typing.ClassVar[QtCore.pyqtSignal] + pointAdded: typing.ClassVar[QtCore.pyqtSignal] + pointRemoved: typing.ClassVar[QtCore.pyqtSignal] + pointReplaced: typing.ClassVar[QtCore.pyqtSignal] + colorChanged: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] def at(self, index: int) -> QtCore.QPointF: ... def pointsVisible(self) -> bool: ... def setPointsVisible(self, visible: bool = ...) -> None: ... @@ -1183,16 +1210,16 @@ class QLogValueAxis('QAbstractAxis'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def minorTickCountChanged(self, minorTickCount: int) -> None: ... - def tickCountChanged(self, tickCount: int) -> None: ... + minorTickCountChanged: typing.ClassVar[QtCore.pyqtSignal] + tickCountChanged: typing.ClassVar[QtCore.pyqtSignal] def minorTickCount(self) -> int: ... def setMinorTickCount(self, minorTickCount: int) -> None: ... def tickCount(self) -> int: ... - def baseChanged(self, base: float) -> None: ... - def labelFormatChanged(self, format: str) -> None: ... - def rangeChanged(self, min: float, max: float) -> None: ... - def maxChanged(self, max: float) -> None: ... - def minChanged(self, min: float) -> None: ... + baseChanged: typing.ClassVar[QtCore.pyqtSignal] + labelFormatChanged: typing.ClassVar[QtCore.pyqtSignal] + rangeChanged: typing.ClassVar[QtCore.pyqtSignal] + maxChanged: typing.ClassVar[QtCore.pyqtSignal] + minChanged: typing.ClassVar[QtCore.pyqtSignal] def base(self) -> float: ... def setBase(self, base: float) -> None: ... def labelFormat(self) -> str: ... @@ -1222,19 +1249,19 @@ class QPieSeries('QAbstractSeries'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def doubleClicked(self, slice: 'QPieSlice') -> None: ... - def released(self, slice: 'QPieSlice') -> None: ... - def pressed(self, slice: 'QPieSlice') -> None: ... + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] def setLabelsPosition(self, position: 'QPieSlice.LabelPosition') -> None: ... def holeSize(self) -> float: ... def setHoleSize(self, holeSize: float) -> None: ... def take(self, slice: 'QPieSlice') -> bool: ... - def sumChanged(self) -> None: ... - def countChanged(self) -> None: ... - def hovered(self, slice: 'QPieSlice', state: bool) -> None: ... - def clicked(self, slice: 'QPieSlice') -> None: ... - def removed(self, slices: typing.Iterable['QPieSlice']) -> None: ... - def added(self, slices: typing.Iterable['QPieSlice']) -> None: ... + sumChanged: typing.ClassVar[QtCore.pyqtSignal] + countChanged: typing.ClassVar[QtCore.pyqtSignal] + hovered: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] + removed: typing.ClassVar[QtCore.pyqtSignal] + added: typing.ClassVar[QtCore.pyqtSignal] def setLabelsVisible(self, visible: bool = ...) -> None: ... def pieEndAngle(self) -> float: ... def setPieEndAngle(self, endAngle: float) -> None: ... @@ -1280,25 +1307,25 @@ class QPieSlice(QtCore.QObject): @typing.overload def __init__(self, label: str, value: float, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def doubleClicked(self) -> None: ... - def released(self) -> None: ... - def pressed(self) -> None: ... - def hovered(self, state: bool) -> None: ... - def clicked(self) -> None: ... - def labelColorChanged(self) -> None: ... - def borderWidthChanged(self) -> None: ... - def borderColorChanged(self) -> None: ... - def colorChanged(self) -> None: ... - def angleSpanChanged(self) -> None: ... - def startAngleChanged(self) -> None: ... - def percentageChanged(self) -> None: ... - def labelFontChanged(self) -> None: ... - def labelBrushChanged(self) -> None: ... - def brushChanged(self) -> None: ... - def penChanged(self) -> None: ... - def labelVisibleChanged(self) -> None: ... - def valueChanged(self) -> None: ... - def labelChanged(self) -> None: ... + doubleClicked: typing.ClassVar[QtCore.pyqtSignal] + released: typing.ClassVar[QtCore.pyqtSignal] + pressed: typing.ClassVar[QtCore.pyqtSignal] + hovered: typing.ClassVar[QtCore.pyqtSignal] + clicked: typing.ClassVar[QtCore.pyqtSignal] + labelColorChanged: typing.ClassVar[QtCore.pyqtSignal] + borderWidthChanged: typing.ClassVar[QtCore.pyqtSignal] + borderColorChanged: typing.ClassVar[QtCore.pyqtSignal] + colorChanged: typing.ClassVar[QtCore.pyqtSignal] + angleSpanChanged: typing.ClassVar[QtCore.pyqtSignal] + startAngleChanged: typing.ClassVar[QtCore.pyqtSignal] + percentageChanged: typing.ClassVar[QtCore.pyqtSignal] + labelFontChanged: typing.ClassVar[QtCore.pyqtSignal] + labelBrushChanged: typing.ClassVar[QtCore.pyqtSignal] + brushChanged: typing.ClassVar[QtCore.pyqtSignal] + penChanged: typing.ClassVar[QtCore.pyqtSignal] + labelVisibleChanged: typing.ClassVar[QtCore.pyqtSignal] + valueChanged: typing.ClassVar[QtCore.pyqtSignal] + labelChanged: typing.ClassVar[QtCore.pyqtSignal] def setLabelPosition(self, position: 'QPieSlice.LabelPosition') -> None: ... def labelPosition(self) -> 'QPieSlice.LabelPosition': ... def series(self) -> 'QPieSeries': ... @@ -1351,12 +1378,20 @@ class QPolarChart('QChart'): def __init__(self, f: typing.Union['QPolarChart.PolarOrientations', 'QPolarChart.PolarOrientation']) -> None: ... @typing.overload def __init__(self, a0: 'QPolarChart.PolarOrientations') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QPolarChart.PolarOrientations': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QPolarChart.PolarOrientations', 'QPolarChart.PolarOrientation', int]) -> 'QPolarChart.PolarOrientations': ... + def __and__(self, other: typing.Union['QPolarChart.PolarOrientations', 'QPolarChart.PolarOrientation', int]) -> 'QPolarChart.PolarOrientations': ... + def __xor__(self, other: typing.Union['QPolarChart.PolarOrientations', 'QPolarChart.PolarOrientation', int]) -> 'QPolarChart.PolarOrientations': ... + def __ror__ (self, other: 'QPolarChart.PolarOrientation') -> 'QPolarChart.PolarOrientations': ... + def __rand__(self, other: 'QPolarChart.PolarOrientation') -> 'QPolarChart.PolarOrientations': ... + def __rxor__(self, other: 'QPolarChart.PolarOrientation') -> 'QPolarChart.PolarOrientations': ... def __init__(self, parent: typing.Optional[QtWidgets.QGraphicsItem] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> None: ... @@ -1376,10 +1411,10 @@ class QScatterSeries('QXYSeries'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def markerSizeChanged(self, size: float) -> None: ... - def markerShapeChanged(self, shape: 'QScatterSeries.MarkerShape') -> None: ... - def borderColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... - def colorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... + markerSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + markerShapeChanged: typing.ClassVar[QtCore.pyqtSignal] + borderColorChanged: typing.ClassVar[QtCore.pyqtSignal] + colorChanged: typing.ClassVar[QtCore.pyqtSignal] def borderColor(self) -> QtGui.QColor: ... def setBorderColor(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient]) -> None: ... def color(self) -> QtGui.QColor: ... @@ -1409,12 +1444,12 @@ class QVBarModelMapper(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def rowCountChanged(self) -> None: ... - def firstRowChanged(self) -> None: ... - def lastBarSetColumnChanged(self) -> None: ... - def firstBarSetColumnChanged(self) -> None: ... - def modelReplaced(self) -> None: ... - def seriesReplaced(self) -> None: ... + rowCountChanged: typing.ClassVar[QtCore.pyqtSignal] + firstRowChanged: typing.ClassVar[QtCore.pyqtSignal] + lastBarSetColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + firstBarSetColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + modelReplaced: typing.ClassVar[QtCore.pyqtSignal] + seriesReplaced: typing.ClassVar[QtCore.pyqtSignal] def setRowCount(self, rowCount: int) -> None: ... def rowCount(self) -> int: ... def setFirstRow(self, firstRow: int) -> None: ... @@ -1432,12 +1467,12 @@ class QVBoxPlotModelMapper(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def rowCountChanged(self) -> None: ... - def firstRowChanged(self) -> None: ... - def lastBoxSetColumnChanged(self) -> None: ... - def firstBoxSetColumnChanged(self) -> None: ... - def modelReplaced(self) -> None: ... - def seriesReplaced(self) -> None: ... + rowCountChanged: typing.ClassVar[QtCore.pyqtSignal] + firstRowChanged: typing.ClassVar[QtCore.pyqtSignal] + lastBoxSetColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + firstBoxSetColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + modelReplaced: typing.ClassVar[QtCore.pyqtSignal] + seriesReplaced: typing.ClassVar[QtCore.pyqtSignal] def setRowCount(self, rowCount: int) -> None: ... def rowCount(self) -> int: ... def setFirstRow(self, firstRow: int) -> None: ... @@ -1455,13 +1490,13 @@ class QVCandlestickModelMapper('QCandlestickModelMapper'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def lastSetColumnChanged(self) -> None: ... - def firstSetColumnChanged(self) -> None: ... - def closeRowChanged(self) -> None: ... - def lowRowChanged(self) -> None: ... - def highRowChanged(self) -> None: ... - def openRowChanged(self) -> None: ... - def timestampRowChanged(self) -> None: ... + lastSetColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + firstSetColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + closeRowChanged: typing.ClassVar[QtCore.pyqtSignal] + lowRowChanged: typing.ClassVar[QtCore.pyqtSignal] + highRowChanged: typing.ClassVar[QtCore.pyqtSignal] + openRowChanged: typing.ClassVar[QtCore.pyqtSignal] + timestampRowChanged: typing.ClassVar[QtCore.pyqtSignal] def lastSetColumn(self) -> int: ... def setLastSetColumn(self, lastSetColumn: int) -> None: ... def firstSetColumn(self) -> int: ... @@ -1482,12 +1517,12 @@ class QVPieModelMapper(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def rowCountChanged(self) -> None: ... - def firstRowChanged(self) -> None: ... - def labelsColumnChanged(self) -> None: ... - def valuesColumnChanged(self) -> None: ... - def modelReplaced(self) -> None: ... - def seriesReplaced(self) -> None: ... + rowCountChanged: typing.ClassVar[QtCore.pyqtSignal] + firstRowChanged: typing.ClassVar[QtCore.pyqtSignal] + labelsColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + valuesColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + modelReplaced: typing.ClassVar[QtCore.pyqtSignal] + seriesReplaced: typing.ClassVar[QtCore.pyqtSignal] def setRowCount(self, rowCount: int) -> None: ... def rowCount(self) -> int: ... def setFirstRow(self, firstRow: int) -> None: ... @@ -1505,12 +1540,12 @@ class QVXYModelMapper(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def rowCountChanged(self) -> None: ... - def firstRowChanged(self) -> None: ... - def yColumnChanged(self) -> None: ... - def xColumnChanged(self) -> None: ... - def modelReplaced(self) -> None: ... - def seriesReplaced(self) -> None: ... + rowCountChanged: typing.ClassVar[QtCore.pyqtSignal] + firstRowChanged: typing.ClassVar[QtCore.pyqtSignal] + yColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + xColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + modelReplaced: typing.ClassVar[QtCore.pyqtSignal] + seriesReplaced: typing.ClassVar[QtCore.pyqtSignal] def setRowCount(self, rowCount: int) -> None: ... def rowCount(self) -> int: ... def setFirstRow(self, firstRow: int) -> None: ... diff --git a/PyQt5-stubs/QtCore.pyi b/PyQt5-stubs/QtCore.pyi index e430ea9a..1413e038 100644 --- a/PyQt5-stubs/QtCore.pyi +++ b/PyQt5-stubs/QtCore.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtCore module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -20,6 +20,7 @@ # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +import sys import typing from PyQt5 import sip @@ -178,6 +179,9 @@ class Qt(sip.simplewrapper): TabFocusAllControls = ... # type: Qt.TabFocusBehavior class MouseEventFlag(int): + def __or__ (self, other: 'Qt.MouseEventFlag') -> 'Qt.MouseEventFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.MouseEventFlags': ... # type: ignore[override, misc] + MouseEventCreatedDoubleClick = ... # type: Qt.MouseEventFlag MouseEventCreatedDoubleClick = ... # type: Qt.MouseEventFlag @@ -224,6 +228,9 @@ class Qt(sip.simplewrapper): SwipeNativeGesture = ... # type: Qt.NativeGestureType class Edge(int): + def __or__ (self, other: 'Qt.Edge') -> 'Qt.Edges': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.Edges': ... # type: ignore[override, misc] + TopEdge = ... # type: Qt.Edge LeftEdge = ... # type: Qt.Edge RightEdge = ... # type: Qt.Edge @@ -271,6 +278,9 @@ class Qt(sip.simplewrapper): FindChildrenRecursively = ... # type: Qt.FindChildOption class ScreenOrientation(int): + def __or__ (self, other: 'Qt.ScreenOrientation') -> 'Qt.ScreenOrientations': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.ScreenOrientations': ... # type: ignore[override, misc] + PrimaryOrientation = ... # type: Qt.ScreenOrientation PortraitOrientation = ... # type: Qt.ScreenOrientation LandscapeOrientation = ... # type: Qt.ScreenOrientation @@ -304,6 +314,9 @@ class Qt(sip.simplewrapper): NavigationModeCursorForceVisible = ... # type: Qt.NavigationMode class GestureFlag(int): + def __or__ (self, other: 'Qt.GestureFlag') -> 'Qt.GestureFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.GestureFlags': ... # type: ignore[override, misc] + DontStartGestureOnChildren = ... # type: Qt.GestureFlag ReceivePartialGestures = ... # type: Qt.GestureFlag IgnoredGesturesPropagateToParent = ... # type: Qt.GestureFlag @@ -339,6 +352,9 @@ class Qt(sip.simplewrapper): GestureCanceled = ... # type: Qt.GestureState class TouchPointState(int): + def __or__ (self, other: 'Qt.TouchPointState') -> 'Qt.TouchPointStates': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.TouchPointStates': ... # type: ignore[override, misc] + TouchPointPressed = ... # type: Qt.TouchPointState TouchPointMoved = ... # type: Qt.TouchPointState TouchPointStationary = ... # type: Qt.TouchPointState @@ -372,6 +388,9 @@ class Qt(sip.simplewrapper): AnchorBottom = ... # type: Qt.AnchorPoint class InputMethodHint(int): + def __or__ (self, other: 'Qt.InputMethodHint') -> 'Qt.InputMethodHints': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.InputMethodHints': ... # type: ignore[override, misc] + ImhNone = ... # type: Qt.InputMethodHint ImhHiddenText = ... # type: Qt.InputMethodHint ImhNoAutoUppercase = ... # type: Qt.InputMethodHint @@ -496,6 +515,9 @@ class Qt(sip.simplewrapper): MaskOutColor = ... # type: Qt.MaskMode class TextInteractionFlag(int): + def __or__ (self, other: 'Qt.TextInteractionFlag') -> 'Qt.TextInteractionFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.TextInteractionFlags': ... # type: ignore[override, misc] + NoTextInteraction = ... # type: Qt.TextInteractionFlag TextSelectableByMouse = ... # type: Qt.TextInteractionFlag TextSelectableByKeyboard = ... # type: Qt.TextInteractionFlag @@ -604,6 +626,9 @@ class Qt(sip.simplewrapper): ApplicationModal = ... # type: Qt.WindowModality class MatchFlag(int): + def __or__ (self, other: 'Qt.MatchFlag') -> 'Qt.MatchFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.MatchFlags': ... # type: ignore[override, misc] + MatchExactly = ... # type: Qt.MatchFlag MatchFixedString = ... # type: Qt.MatchFlag MatchContains = ... # type: Qt.MatchFlag @@ -629,6 +654,9 @@ class Qt(sip.simplewrapper): MatchRegularExpression = ... # type: Qt.MatchFlag class ItemFlag(int): + def __or__ (self, other: 'Qt.ItemFlag') -> 'Qt.ItemFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.ItemFlags': ... # type: ignore[override, misc] + NoItemFlags = ... # type: Qt.ItemFlag ItemIsSelectable = ... # type: Qt.ItemFlag ItemIsEditable = ... # type: Qt.ItemFlag @@ -702,6 +730,9 @@ class Qt(sip.simplewrapper): Checked = ... # type: Qt.CheckState class DropAction(int): + def __or__ (self, other: 'Qt.DropAction') -> 'Qt.DropActions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.DropActions': ... # type: ignore[override, misc] + CopyAction = ... # type: Qt.DropAction MoveAction = ... # type: Qt.DropAction LinkAction = ... # type: Qt.DropAction @@ -739,6 +770,10 @@ class Qt(sip.simplewrapper): ToolButtonFollowStyle = ... # type: Qt.ToolButtonStyle class InputMethodQuery(int): + def __or__ (self, other: 'Qt.InputMethodQuery') -> 'Qt.InputMethodQueries': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.InputMethodQueries': ... # type: ignore[override, misc] + + ImMicroFocus = ... # type: Qt.InputMethodQuery ImFont = ... # type: Qt.InputMethodQuery ImCursorPosition = ... # type: Qt.InputMethodQuery @@ -943,6 +978,9 @@ class Qt(sip.simplewrapper): RFC2822Date = ... # type: Qt.DateFormat class ToolBarArea(int): + def __or__ (self, other: 'Qt.ToolBarArea') -> 'Qt.ToolBarAreas': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.ToolBarAreas': ... # type: ignore[override, misc] + LeftToolBarArea = ... # type: Qt.ToolBarArea RightToolBarArea = ... # type: Qt.ToolBarArea TopToolBarArea = ... # type: Qt.ToolBarArea @@ -969,6 +1007,9 @@ class Qt(sip.simplewrapper): VeryCoarseTimer = ... # type: Qt.TimerType class DockWidgetArea(int): + def __or__ (self, other: 'Qt.DockWidgetArea') -> 'Qt.DockWidgetAreas': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.DockWidgetAreas': ... # type: ignore[override, misc] + LeftDockWidgetArea = ... # type: Qt.DockWidgetArea RightDockWidgetArea = ... # type: Qt.DockWidgetArea TopDockWidgetArea = ... # type: Qt.DockWidgetArea @@ -2121,6 +2162,9 @@ class Qt(sip.simplewrapper): OpaqueMode = ... # type: Qt.BGMode class ImageConversionFlag(int): + def __or__ (self, other: 'Qt.ImageConversionFlag') -> 'Qt.ImageConversionFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.ImageConversionFlags': ... # type: ignore[override, misc] + AutoColor = ... # type: Qt.ImageConversionFlag ColorOnly = ... # type: Qt.ImageConversionFlag MonoOnly = ... # type: Qt.ImageConversionFlag @@ -2363,6 +2407,9 @@ class Qt(sip.simplewrapper): WA_StyleSheetTarget = ... # type: Qt.WidgetAttribute class WindowState(int): + def __or__ (self, other: 'Qt.WindowState') -> 'Qt.WindowStates': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.WindowStates': ... # type: ignore[override, misc] + WindowNoState = ... # type: Qt.WindowState WindowMinimized = ... # type: Qt.WindowState WindowMaximized = ... # type: Qt.WindowState @@ -2376,6 +2423,9 @@ class Qt(sip.simplewrapper): WindowActive = ... # type: Qt.WindowState class WindowType(int): + def __or__ (self, other: 'Qt.WindowType') -> 'Qt.WindowFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.WindowFlags': ... # type: ignore[override, misc] + Widget = ... # type: Qt.WindowType Window = ... # type: Qt.WindowType Dialog = ... # type: Qt.WindowType @@ -2489,6 +2539,10 @@ class Qt(sip.simplewrapper): TextJustificationForced = ... # type: Qt.TextFlag class AlignmentFlag(int): + def __or__ (self, other: 'Qt.AlignmentFlag') -> 'Qt.Alignment': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.Alignment': ... # type: ignore[override, misc] + + AlignLeft = ... # type: Qt.AlignmentFlag AlignLeading = ... # type: Qt.AlignmentFlag AlignRight = ... # type: Qt.AlignmentFlag @@ -2540,6 +2594,9 @@ class Qt(sip.simplewrapper): WheelFocus = ... # type: Qt.FocusPolicy class Orientation(int): + def __or__ (self, other: 'Qt.Orientation') -> 'Qt.Orientations': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.Orientations': ... # type: ignore[override, misc] + Horizontal = ... # type: Qt.Orientation Vertical = ... # type: Qt.Orientation @@ -2547,6 +2604,9 @@ class Qt(sip.simplewrapper): Vertical = ... # type: Qt.Orientation class MouseButton(int): + def __or__ (self, other: 'Qt.MouseButton') -> 'Qt.MouseButtons': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.MouseButtons': ... # type: ignore[override, misc] + NoButton = ... # type: Qt.MouseButton AllButtons = ... # type: Qt.MouseButton LeftButton = ... # type: Qt.MouseButton @@ -2635,6 +2695,9 @@ class Qt(sip.simplewrapper): UNICODE_ACCEL = ... # type: Qt.Modifier class KeyboardModifier(int): + def __or__ (self, other: 'Qt.KeyboardModifier') -> 'Qt.KeyboardModifiers': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'Qt.KeyboardModifiers': ... # type: ignore[override, misc] + NoModifier = ... # type: Qt.KeyboardModifier ShiftModifier = ... # type: Qt.KeyboardModifier ControlModifier = ... # type: Qt.KeyboardModifier @@ -2704,12 +2767,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.KeyboardModifiers', 'Qt.KeyboardModifier']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.KeyboardModifiers') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.KeyboardModifiers': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.KeyboardModifiers', 'Qt.KeyboardModifier', int]) -> 'Qt.KeyboardModifiers': ... + def __and__(self, other: typing.Union['Qt.KeyboardModifiers', 'Qt.KeyboardModifier', int]) -> 'Qt.KeyboardModifiers': ... + def __xor__(self, other: typing.Union['Qt.KeyboardModifiers', 'Qt.KeyboardModifier', int]) -> 'Qt.KeyboardModifiers': ... + def __ror__ (self, other: 'Qt.KeyboardModifier') -> 'Qt.KeyboardModifiers': ... + def __rand__(self, other: 'Qt.KeyboardModifier') -> 'Qt.KeyboardModifiers': ... + def __rxor__(self, other: 'Qt.KeyboardModifier') -> 'Qt.KeyboardModifiers': ... class MouseButtons(sip.simplewrapper): @@ -2719,12 +2790,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.MouseButtons', 'Qt.MouseButton']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.MouseButtons') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.MouseButtons': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.MouseButtons', 'Qt.MouseButton', int]) -> 'Qt.MouseButtons': ... + def __and__(self, other: typing.Union['Qt.MouseButtons', 'Qt.MouseButton', int]) -> 'Qt.MouseButtons': ... + def __xor__(self, other: typing.Union['Qt.MouseButtons', 'Qt.MouseButton', int]) -> 'Qt.MouseButtons': ... + def __ror__ (self, other: 'Qt.MouseButton') -> 'Qt.MouseButtons': ... + def __rand__(self, other: 'Qt.MouseButton') -> 'Qt.MouseButtons': ... + def __rxor__(self, other: 'Qt.MouseButton') -> 'Qt.MouseButtons': ... class Orientations(sip.simplewrapper): @@ -2734,19 +2813,27 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.Orientations', 'Qt.Orientation']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.Orientations') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.Orientations': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.Orientations', 'Qt.Orientation', int]) -> 'Qt.Orientations': ... + def __and__(self, other: typing.Union['Qt.Orientations', 'Qt.Orientation', int]) -> 'Qt.Orientations': ... + def __xor__(self, other: typing.Union['Qt.Orientations', 'Qt.Orientation', int]) -> 'Qt.Orientations': ... + def __ror__ (self, other: 'Qt.Orientation') -> 'Qt.Orientations': ... + def __rand__(self, other: 'Qt.Orientation') -> 'Qt.Orientations': ... + def __rxor__(self, other: 'Qt.Orientation') -> 'Qt.Orientations': ... class Alignment(sip.simplewrapper): @typing.overload def __init__(self) -> None: ... @typing.overload - def __init__(self, f: typing.Union['Qt.Alignment', 'Qt.AlignmentFlag']) -> None: ... + def __init__(self, f: typing.Union['Qt.Alignment', 'Qt.AlignmentFlag', int]) -> None: ... @typing.overload def __init__(self, a0: 'Qt.Alignment') -> None: ... @@ -2755,13 +2842,19 @@ class Qt(sip.simplewrapper): def __invert__(self) -> 'Qt.Alignment': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.Alignment', 'Qt.AlignmentFlag', int]) -> 'Qt.Alignment': ... + def __and__(self, other: typing.Union['Qt.Alignment', 'Qt.AlignmentFlag', int]) -> 'Qt.Alignment': ... + def __xor__(self, other: typing.Union['Qt.Alignment', 'Qt.AlignmentFlag', int]) -> 'Qt.Alignment': ... + def __ror__ (self, other: 'Qt.AlignmentFlag') -> 'Qt.Alignment': ... + def __rand__(self, other: 'Qt.AlignmentFlag') -> 'Qt.Alignment': ... + def __rxor__(self, other: 'Qt.AlignmentFlag') -> 'Qt.Alignment': ... class WindowFlags(sip.simplewrapper): @typing.overload def __init__(self) -> None: ... @typing.overload - def __init__(self, f: typing.Union['Qt.WindowFlags', 'Qt.WindowType']) -> None: ... + def __init__(self, f: typing.Union['Qt.WindowFlags', 'Qt.WindowType', int]) -> None: ... @typing.overload def __init__(self, a0: 'Qt.WindowFlags') -> None: ... @@ -2770,6 +2863,12 @@ class Qt(sip.simplewrapper): def __invert__(self) -> 'Qt.WindowFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.WindowFlags', 'Qt.WindowType', int]) -> 'Qt.WindowFlags': ... + def __and__(self, other: typing.Union['Qt.WindowFlags', 'Qt.WindowType', int]) -> 'Qt.WindowFlags': ... + def __xor__(self, other: typing.Union['Qt.WindowFlags', 'Qt.WindowType', int]) -> 'Qt.WindowFlags': ... + def __ror__ (self, other: 'Qt.WindowType') -> 'Qt.WindowFlags': ... + def __rand__(self, other: 'Qt.WindowType') -> 'Qt.WindowFlags': ... + def __rxor__(self, other: 'Qt.WindowType') -> 'Qt.WindowFlags': ... class WindowStates(sip.simplewrapper): @@ -2779,12 +2878,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.WindowStates', 'Qt.WindowState']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.WindowStates') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.WindowStates': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.WindowStates', 'Qt.WindowState', int]) -> 'Qt.WindowStates': ... + def __and__(self, other: typing.Union['Qt.WindowStates', 'Qt.WindowState', int]) -> 'Qt.WindowStates': ... + def __xor__(self, other: typing.Union['Qt.WindowStates', 'Qt.WindowState', int]) -> 'Qt.WindowStates': ... + def __ror__ (self, other: 'Qt.WindowState') -> 'Qt.WindowStates': ... + def __rand__(self, other: 'Qt.WindowState') -> 'Qt.WindowStates': ... + def __rxor__(self, other: 'Qt.WindowState') -> 'Qt.WindowStates': ... class ImageConversionFlags(sip.simplewrapper): @@ -2794,12 +2901,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.ImageConversionFlags', 'Qt.ImageConversionFlag']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.ImageConversionFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.ImageConversionFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.ImageConversionFlags', 'Qt.ImageConversionFlag', int]) -> 'Qt.ImageConversionFlags': ... + def __and__(self, other: typing.Union['Qt.ImageConversionFlags', 'Qt.ImageConversionFlag', int]) -> 'Qt.ImageConversionFlags': ... + def __xor__(self, other: typing.Union['Qt.ImageConversionFlags', 'Qt.ImageConversionFlag', int]) -> 'Qt.ImageConversionFlags': ... + def __ror__ (self, other: 'Qt.ImageConversionFlag') -> 'Qt.ImageConversionFlags': ... + def __rand__(self, other: 'Qt.ImageConversionFlag') -> 'Qt.ImageConversionFlags': ... + def __rxor__(self, other: 'Qt.ImageConversionFlag') -> 'Qt.ImageConversionFlags': ... class DockWidgetAreas(sip.simplewrapper): @@ -2809,12 +2924,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.DockWidgetAreas', 'Qt.DockWidgetArea']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.DockWidgetAreas') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.DockWidgetAreas': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.DockWidgetAreas', 'Qt.DockWidgetArea', int]) -> 'Qt.DockWidgetAreas': ... + def __and__(self, other: typing.Union['Qt.DockWidgetAreas', 'Qt.DockWidgetArea', int]) -> 'Qt.DockWidgetAreas': ... + def __xor__(self, other: typing.Union['Qt.DockWidgetAreas', 'Qt.DockWidgetArea', int]) -> 'Qt.DockWidgetAreas': ... + def __ror__ (self, other: 'Qt.DockWidgetArea') -> 'Qt.DockWidgetAreas': ... + def __rand__(self, other: 'Qt.DockWidgetArea') -> 'Qt.DockWidgetAreas': ... + def __rxor__(self, other: 'Qt.DockWidgetArea') -> 'Qt.DockWidgetAreas': ... class ToolBarAreas(sip.simplewrapper): @@ -2824,12 +2947,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.ToolBarAreas', 'Qt.ToolBarArea']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.ToolBarAreas') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.ToolBarAreas': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.ToolBarAreas', 'Qt.ToolBarArea', int]) -> 'Qt.ToolBarAreas': ... + def __and__(self, other: typing.Union['Qt.ToolBarAreas', 'Qt.ToolBarArea', int]) -> 'Qt.ToolBarAreas': ... + def __xor__(self, other: typing.Union['Qt.ToolBarAreas', 'Qt.ToolBarArea', int]) -> 'Qt.ToolBarAreas': ... + def __ror__ (self, other: 'Qt.ToolBarArea') -> 'Qt.ToolBarAreas': ... + def __rand__(self, other: 'Qt.ToolBarArea') -> 'Qt.ToolBarAreas': ... + def __rxor__(self, other: 'Qt.ToolBarArea') -> 'Qt.ToolBarAreas': ... class InputMethodQueries(sip.simplewrapper): @@ -2839,12 +2970,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.InputMethodQueries', 'Qt.InputMethodQuery']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.InputMethodQueries') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.InputMethodQueries': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.InputMethodQueries', 'Qt.InputMethodQuery', int]) -> 'Qt.InputMethodQueries': ... + def __and__(self, other: typing.Union['Qt.InputMethodQueries', 'Qt.InputMethodQuery', int]) -> 'Qt.InputMethodQueries': ... + def __xor__(self, other: typing.Union['Qt.InputMethodQueries', 'Qt.InputMethodQuery', int]) -> 'Qt.InputMethodQueries': ... + def __ror__ (self, other: 'Qt.InputMethodQuery') -> 'Qt.InputMethodQueries': ... + def __rand__(self, other: 'Qt.InputMethodQuery') -> 'Qt.InputMethodQueries': ... + def __rxor__(self, other: 'Qt.InputMethodQuery') -> 'Qt.InputMethodQueries': ... class DropActions(sip.simplewrapper): @@ -2854,12 +2993,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.DropActions', 'Qt.DropAction']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.DropActions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.DropActions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.DropActions', 'Qt.DropAction', int]) -> 'Qt.DropActions': ... + def __and__(self, other: typing.Union['Qt.DropActions', 'Qt.DropAction', int]) -> 'Qt.DropActions': ... + def __xor__(self, other: typing.Union['Qt.DropActions', 'Qt.DropAction', int]) -> 'Qt.DropActions': ... + def __ror__ (self, other: 'Qt.DropAction') -> 'Qt.DropActions': ... + def __rand__(self, other: 'Qt.DropAction') -> 'Qt.DropActions': ... + def __rxor__(self, other: 'Qt.DropAction') -> 'Qt.DropActions': ... class ItemFlags(sip.simplewrapper): @@ -2869,12 +3016,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.ItemFlags', 'Qt.ItemFlag']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.ItemFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.ItemFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.ItemFlags', 'Qt.ItemFlag', int]) -> 'Qt.ItemFlags': ... + def __and__(self, other: typing.Union['Qt.ItemFlags', 'Qt.ItemFlag', int]) -> 'Qt.ItemFlags': ... + def __xor__(self, other: typing.Union['Qt.ItemFlags', 'Qt.ItemFlag', int]) -> 'Qt.ItemFlags': ... + def __ror__ (self, other: 'Qt.ItemFlag') -> 'Qt.ItemFlags': ... + def __rand__(self, other: 'Qt.ItemFlag') -> 'Qt.ItemFlags': ... + def __rxor__(self, other: 'Qt.ItemFlag') -> 'Qt.ItemFlags': ... class MatchFlags(sip.simplewrapper): @@ -2884,12 +3039,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.MatchFlags', 'Qt.MatchFlag']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.MatchFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.MatchFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.MatchFlags', 'Qt.MatchFlag', int]) -> 'Qt.MatchFlags': ... + def __and__(self, other: typing.Union['Qt.MatchFlags', 'Qt.MatchFlag', int]) -> 'Qt.MatchFlags': ... + def __xor__(self, other: typing.Union['Qt.MatchFlags', 'Qt.MatchFlag', int]) -> 'Qt.MatchFlags': ... + def __ror__ (self, other: 'Qt.MatchFlag') -> 'Qt.MatchFlags': ... + def __rand__(self, other: 'Qt.MatchFlag') -> 'Qt.MatchFlags': ... + def __rxor__(self, other: 'Qt.MatchFlag') -> 'Qt.MatchFlags': ... class TextInteractionFlags(sip.simplewrapper): @@ -2899,12 +3062,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.TextInteractionFlags', 'Qt.TextInteractionFlag']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.TextInteractionFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.TextInteractionFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.TextInteractionFlags', 'Qt.TextInteractionFlag', int]) -> 'Qt.TextInteractionFlags': ... + def __and__(self, other: typing.Union['Qt.TextInteractionFlags', 'Qt.TextInteractionFlag', int]) -> 'Qt.TextInteractionFlags': ... + def __xor__(self, other: typing.Union['Qt.TextInteractionFlags', 'Qt.TextInteractionFlag', int]) -> 'Qt.TextInteractionFlags': ... + def __ror__ (self, other: 'Qt.TextInteractionFlag') -> 'Qt.TextInteractionFlags': ... + def __rand__(self, other: 'Qt.TextInteractionFlag') -> 'Qt.TextInteractionFlags': ... + def __rxor__(self, other: 'Qt.TextInteractionFlag') -> 'Qt.TextInteractionFlags': ... class InputMethodHints(sip.simplewrapper): @@ -2914,12 +3085,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.InputMethodHints', 'Qt.InputMethodHint']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.InputMethodHints') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.InputMethodHints': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.InputMethodHints', 'Qt.InputMethodHint', int]) -> 'Qt.InputMethodHints': ... + def __and__(self, other: typing.Union['Qt.InputMethodHints', 'Qt.InputMethodHint', int]) -> 'Qt.InputMethodHints': ... + def __xor__(self, other: typing.Union['Qt.InputMethodHints', 'Qt.InputMethodHint', int]) -> 'Qt.InputMethodHints': ... + def __ror__ (self, other: 'Qt.InputMethodHint') -> 'Qt.InputMethodHints': ... + def __rand__(self, other: 'Qt.InputMethodHint') -> 'Qt.InputMethodHints': ... + def __rxor__(self, other: 'Qt.InputMethodHint') -> 'Qt.InputMethodHints': ... class TouchPointStates(sip.simplewrapper): @@ -2929,12 +3108,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.TouchPointStates', 'Qt.TouchPointState']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.TouchPointStates') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.TouchPointStates': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.TouchPointStates', 'Qt.TouchPointState', int]) -> 'Qt.TouchPointStates': ... + def __and__(self, other: typing.Union['Qt.TouchPointStates', 'Qt.TouchPointState', int]) -> 'Qt.TouchPointStates': ... + def __xor__(self, other: typing.Union['Qt.TouchPointStates', 'Qt.TouchPointState', int]) -> 'Qt.TouchPointStates': ... + def __ror__ (self, other: 'Qt.TouchPointState') -> 'Qt.TouchPointStates': ... + def __rand__(self, other: 'Qt.TouchPointState') -> 'Qt.TouchPointStates': ... + def __rxor__(self, other: 'Qt.TouchPointState') -> 'Qt.TouchPointStates': ... class GestureFlags(sip.simplewrapper): @@ -2944,12 +3131,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.GestureFlags', 'Qt.GestureFlag']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.GestureFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.GestureFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.GestureFlags', 'Qt.GestureFlag', int]) -> 'Qt.GestureFlags': ... + def __and__(self, other: typing.Union['Qt.GestureFlags', 'Qt.GestureFlag', int]) -> 'Qt.GestureFlags': ... + def __xor__(self, other: typing.Union['Qt.GestureFlags', 'Qt.GestureFlag', int]) -> 'Qt.GestureFlags': ... + def __ror__ (self, other: 'Qt.GestureFlag') -> 'Qt.GestureFlags': ... + def __rand__(self, other: 'Qt.GestureFlag') -> 'Qt.GestureFlags': ... + def __rxor__(self, other: 'Qt.GestureFlag') -> 'Qt.GestureFlags': ... class ScreenOrientations(sip.simplewrapper): @@ -2959,12 +3154,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.ScreenOrientations', 'Qt.ScreenOrientation']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.ScreenOrientations') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.ScreenOrientations': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.ScreenOrientations', 'Qt.ScreenOrientation', int]) -> 'Qt.ScreenOrientations': ... + def __and__(self, other: typing.Union['Qt.ScreenOrientations', 'Qt.ScreenOrientation', int]) -> 'Qt.ScreenOrientations': ... + def __xor__(self, other: typing.Union['Qt.ScreenOrientations', 'Qt.ScreenOrientation', int]) -> 'Qt.ScreenOrientations': ... + def __ror__ (self, other: 'Qt.ScreenOrientation') -> 'Qt.ScreenOrientations': ... + def __rand__(self, other: 'Qt.ScreenOrientation') -> 'Qt.ScreenOrientations': ... + def __rxor__(self, other: 'Qt.ScreenOrientation') -> 'Qt.ScreenOrientations': ... class FindChildOptions(sip.simplewrapper): @@ -2974,12 +3177,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.FindChildOptions', 'Qt.FindChildOption']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.FindChildOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.FindChildOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.FindChildOptions', 'Qt.FindChildOption', int]) -> 'Qt.FindChildOptions': ... + def __and__(self, other: typing.Union['Qt.FindChildOptions', 'Qt.FindChildOption', int]) -> 'Qt.FindChildOptions': ... + def __xor__(self, other: typing.Union['Qt.FindChildOptions', 'Qt.FindChildOption', int]) -> 'Qt.FindChildOptions': ... + def __ror__ (self, other: 'Qt.FindChildOption') -> 'Qt.FindChildOptions': ... + def __rand__(self, other: 'Qt.FindChildOption') -> 'Qt.FindChildOptions': ... + def __rxor__(self, other: 'Qt.FindChildOption') -> 'Qt.FindChildOptions': ... class ApplicationStates(sip.simplewrapper): @@ -2989,12 +3200,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.ApplicationStates', 'Qt.ApplicationState']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.ApplicationStates') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.ApplicationStates': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.ApplicationStates', 'Qt.ApplicationState', int]) -> 'Qt.ApplicationStates': ... + def __and__(self, other: typing.Union['Qt.ApplicationStates', 'Qt.ApplicationState', int]) -> 'Qt.ApplicationStates': ... + def __xor__(self, other: typing.Union['Qt.ApplicationStates', 'Qt.ApplicationState', int]) -> 'Qt.ApplicationStates': ... + def __ror__ (self, other: 'Qt.ApplicationState') -> 'Qt.ApplicationStates': ... + def __rand__(self, other: 'Qt.ApplicationState') -> 'Qt.ApplicationStates': ... + def __rxor__(self, other: 'Qt.ApplicationState') -> 'Qt.ApplicationStates': ... class Edges(sip.simplewrapper): @@ -3004,12 +3223,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.Edges', 'Qt.Edge']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.Edges') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.Edges': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.Edges', 'Qt.Edge', int]) -> 'Qt.Edges': ... + def __and__(self, other: typing.Union['Qt.Edges', 'Qt.Edge', int]) -> 'Qt.Edges': ... + def __xor__(self, other: typing.Union['Qt.Edges', 'Qt.Edge', int]) -> 'Qt.Edges': ... + def __ror__ (self, other: 'Qt.Edge') -> 'Qt.Edges': ... + def __rand__(self, other: 'Qt.Edge') -> 'Qt.Edges': ... + def __rxor__(self, other: 'Qt.Edge') -> 'Qt.Edges': ... class MouseEventFlags(sip.simplewrapper): @@ -3019,12 +3246,20 @@ class Qt(sip.simplewrapper): def __init__(self, f: typing.Union['Qt.MouseEventFlags', 'Qt.MouseEventFlag']) -> None: ... @typing.overload def __init__(self, a0: 'Qt.MouseEventFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'Qt.MouseEventFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['Qt.MouseEventFlags', 'Qt.MouseEventFlag', int]) -> 'Qt.MouseEventFlags': ... + def __and__(self, other: typing.Union['Qt.MouseEventFlags', 'Qt.MouseEventFlag', int]) -> 'Qt.MouseEventFlags': ... + def __xor__(self, other: typing.Union['Qt.MouseEventFlags', 'Qt.MouseEventFlag', int]) -> 'Qt.MouseEventFlags': ... + def __ror__ (self, other: 'Qt.MouseEventFlag') -> 'Qt.MouseEventFlags': ... + def __rand__(self, other: 'Qt.MouseEventFlag') -> 'Qt.MouseEventFlags': ... + def __rxor__(self, other: 'Qt.MouseEventFlag') -> 'Qt.MouseEventFlags': ... def convertFromPlainText(self, plain: str, mode: QtCore.Qt.WhiteSpaceMode = ...) -> str: ... def mightBeRichText(self, a0: str) -> bool: ... @@ -3093,7 +3328,6 @@ class QObject(sip.wrapper): def tr(self, sourceText: str, disambiguation: typing.Optional[str] = ..., n: int = ...) -> str: ... def eventFilter(self, a0: 'QObject', a1: 'QEvent') -> bool: ... def event(self, a0: 'QEvent') -> bool: ... - def __getattr__(self, name: str) -> typing.Any: ... def pyqtConfigure(self, a0: typing.Any) -> None: ... def metaObject(self) -> 'QMetaObject': ... @@ -3135,10 +3369,10 @@ class QAbstractAnimation(QObject): def resume(self) -> None: ... def pause(self) -> None: ... def start(self, policy: 'QAbstractAnimation.DeletionPolicy' = ...) -> None: ... - def directionChanged(self, a0: 'QAbstractAnimation.Direction') -> None: ... - def currentLoopChanged(self, currentLoop: int) -> None: ... - def stateChanged(self, newState: 'QAbstractAnimation.State', oldState: 'QAbstractAnimation.State') -> None: ... - def finished(self) -> None: ... + directionChanged: typing.ClassVar[QtCore.pyqtSignal] + currentLoopChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def totalDuration(self) -> int: ... def duration(self) -> int: ... def currentLoop(self) -> int: ... @@ -3167,8 +3401,8 @@ class QAbstractEventDispatcher(QObject): def __init__(self, parent: typing.Optional[QObject] = ...) -> None: ... - def awake(self) -> None: ... - def aboutToBlock(self) -> None: ... + awake: typing.ClassVar[QtCore.pyqtSignal] + aboutToBlock: typing.ClassVar[QtCore.pyqtSignal] def filterNativeEvent(self, eventType: typing.Union['QByteArray', bytes, bytearray], message: sip.voidptr) -> typing.Tuple[bool, int]: ... def removeNativeEventFilter(self, filterObj: 'QAbstractNativeEventFilter') -> None: ... def installNativeEventFilter(self, filterObj: 'QAbstractNativeEventFilter') -> None: ... @@ -3243,6 +3477,9 @@ class QPersistentModelIndex(sip.simplewrapper): class QAbstractItemModel(QObject): class CheckIndexOption(int): + def __or__ (self, other: 'QAbstractItemModel.CheckIndexOption') -> int: ... # type: ignore[override] + def __ror__ (self, other: int) -> int: ... + NoOption = ... # type: QAbstractItemModel.CheckIndexOption IndexIsValid = ... # type: QAbstractItemModel.CheckIndexOption DoNotUseParent = ... # type: QAbstractItemModel.CheckIndexOption @@ -3270,12 +3507,20 @@ class QAbstractItemModel(QObject): def __init__(self, f: typing.Union['QAbstractItemModel.CheckIndexOptions', 'QAbstractItemModel.CheckIndexOption']) -> None: ... @typing.overload def __init__(self, a0: 'QAbstractItemModel.CheckIndexOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QAbstractItemModel.CheckIndexOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QAbstractItemModel.CheckIndexOptions', 'QAbstractItemModel.CheckIndexOption', int]) -> 'QAbstractItemModel.CheckIndexOptions': ... + def __and__(self, other: typing.Union['QAbstractItemModel.CheckIndexOptions', 'QAbstractItemModel.CheckIndexOption', int]) -> 'QAbstractItemModel.CheckIndexOptions': ... + def __xor__(self, other: typing.Union['QAbstractItemModel.CheckIndexOptions', 'QAbstractItemModel.CheckIndexOption', int]) -> 'QAbstractItemModel.CheckIndexOptions': ... + def __ror__ (self, other: 'QAbstractItemModel.CheckIndexOption') -> 'QAbstractItemModel.CheckIndexOptions': ... + def __rand__(self, other: 'QAbstractItemModel.CheckIndexOption') -> 'QAbstractItemModel.CheckIndexOptions': ... + def __rxor__(self, other: 'QAbstractItemModel.CheckIndexOption') -> 'QAbstractItemModel.CheckIndexOptions': ... def __init__(self, parent: typing.Optional[QObject] = ...) -> None: ... @@ -3292,10 +3537,10 @@ class QAbstractItemModel(QObject): def beginMoveColumns(self, sourceParent: QModelIndex, sourceFirst: int, sourceLast: int, destinationParent: QModelIndex, destinationColumn: int) -> bool: ... def endMoveRows(self) -> None: ... def beginMoveRows(self, sourceParent: QModelIndex, sourceFirst: int, sourceLast: int, destinationParent: QModelIndex, destinationRow: int) -> bool: ... - def columnsMoved(self, parent: QModelIndex, start: int, end: int, destination: QModelIndex, column: int) -> None: ... - def columnsAboutToBeMoved(self, sourceParent: QModelIndex, sourceStart: int, sourceEnd: int, destinationParent: QModelIndex, destinationColumn: int) -> None: ... - def rowsMoved(self, parent: QModelIndex, start: int, end: int, destination: QModelIndex, row: int) -> None: ... - def rowsAboutToBeMoved(self, sourceParent: QModelIndex, sourceStart: int, sourceEnd: int, destinationParent: QModelIndex, destinationRow: int) -> None: ... + columnsMoved: typing.ClassVar[QtCore.pyqtSignal] + columnsAboutToBeMoved: typing.ClassVar[QtCore.pyqtSignal] + rowsMoved: typing.ClassVar[QtCore.pyqtSignal] + rowsAboutToBeMoved: typing.ClassVar[QtCore.pyqtSignal] def createIndex(self, row: int, column: int, object: typing.Any = ...) -> QModelIndex: ... def roleNames(self) -> typing.Dict[int, 'QByteArray']: ... def supportedDragActions(self) -> Qt.DropActions: ... @@ -3318,19 +3563,19 @@ class QAbstractItemModel(QObject): def encodeData(self, indexes: typing.Iterable[QModelIndex], stream: 'QDataStream') -> None: ... def revert(self) -> None: ... def submit(self) -> bool: ... - def modelReset(self) -> None: ... - def modelAboutToBeReset(self) -> None: ... - def columnsRemoved(self, parent: QModelIndex, first: int, last: int) -> None: ... - def columnsAboutToBeRemoved(self, parent: QModelIndex, first: int, last: int) -> None: ... - def columnsInserted(self, parent: QModelIndex, first: int, last: int) -> None: ... - def columnsAboutToBeInserted(self, parent: QModelIndex, first: int, last: int) -> None: ... - def rowsRemoved(self, parent: QModelIndex, first: int, last: int) -> None: ... - def rowsAboutToBeRemoved(self, parent: QModelIndex, first: int, last: int) -> None: ... - def rowsInserted(self, parent: QModelIndex, first: int, last: int) -> None: ... - def rowsAboutToBeInserted(self, parent: QModelIndex, first: int, last: int) -> None: ... - def layoutChanged(self, parents: typing.Iterable[QPersistentModelIndex] = ..., hint: 'QAbstractItemModel.LayoutChangeHint' = ...) -> None: ... - def layoutAboutToBeChanged(self, parents: typing.Iterable[QPersistentModelIndex] = ..., hint: 'QAbstractItemModel.LayoutChangeHint' = ...) -> None: ... - def headerDataChanged(self, orientation: Qt.Orientation, first: int, last: int) -> None: ... + modelReset: typing.ClassVar[QtCore.pyqtSignal] + modelAboutToBeReset: typing.ClassVar[QtCore.pyqtSignal] + columnsRemoved: typing.ClassVar[QtCore.pyqtSignal] + columnsAboutToBeRemoved: typing.ClassVar[QtCore.pyqtSignal] + columnsInserted: typing.ClassVar[QtCore.pyqtSignal] + columnsAboutToBeInserted: typing.ClassVar[QtCore.pyqtSignal] + rowsRemoved: typing.ClassVar[QtCore.pyqtSignal] + rowsAboutToBeRemoved: typing.ClassVar[QtCore.pyqtSignal] + rowsInserted: typing.ClassVar[QtCore.pyqtSignal] + rowsAboutToBeInserted: typing.ClassVar[QtCore.pyqtSignal] + layoutChanged: typing.ClassVar[QtCore.pyqtSignal] + layoutAboutToBeChanged: typing.ClassVar[QtCore.pyqtSignal] + headerDataChanged: typing.ClassVar[QtCore.pyqtSignal] dataChanged: typing.ClassVar[pyqtSignal] def span(self, index: QModelIndex) -> 'QSize': ... def match(self, start: QModelIndex, role: int, value: typing.Any, hits: int = ..., flags: typing.Union[Qt.MatchFlags, Qt.MatchFlag] = ...) -> typing.List[QModelIndex]: ... @@ -3401,7 +3646,7 @@ class QAbstractProxyModel(QAbstractItemModel): def supportedDragActions(self) -> Qt.DropActions: ... def dropMimeData(self, data: 'QMimeData', action: Qt.DropAction, row: int, column: int, parent: QModelIndex) -> bool: ... def canDropMimeData(self, data: 'QMimeData', action: Qt.DropAction, row: int, column: int, parent: QModelIndex) -> bool: ... - def sourceModelChanged(self) -> None: ... + sourceModelChanged: typing.ClassVar[QtCore.pyqtSignal] def resetInternalData(self) -> None: ... def sibling(self, row: int, column: int, idx: QModelIndex) -> QModelIndex: ... def supportedDropActions(self) -> Qt.DropActions: ... @@ -3437,9 +3682,9 @@ class QAbstractState(QObject): def event(self, e: 'QEvent') -> bool: ... def onExit(self, event: 'QEvent') -> None: ... def onEntry(self, event: 'QEvent') -> None: ... - def exited(self) -> None: ... - def entered(self) -> None: ... - def activeChanged(self, active: bool) -> None: ... + exited: typing.ClassVar[QtCore.pyqtSignal] + entered: typing.ClassVar[QtCore.pyqtSignal] + activeChanged: typing.ClassVar[QtCore.pyqtSignal] def active(self) -> bool: ... def machine(self) -> 'QStateMachine': ... def parentState(self) -> 'QState': ... @@ -3461,9 +3706,9 @@ class QAbstractTransition(QObject): def event(self, e: 'QEvent') -> bool: ... def onTransition(self, event: 'QEvent') -> None: ... def eventTest(self, event: 'QEvent') -> bool: ... - def targetStatesChanged(self) -> None: ... - def targetStateChanged(self) -> None: ... - def triggered(self) -> None: ... + targetStatesChanged: typing.ClassVar[QtCore.pyqtSignal] + targetStateChanged: typing.ClassVar[QtCore.pyqtSignal] + triggered: typing.ClassVar[QtCore.pyqtSignal] def animations(self) -> typing.List[QAbstractAnimation]: ... def removeAnimation(self, animation: QAbstractAnimation) -> None: ... def addAnimation(self, animation: QAbstractAnimation) -> None: ... @@ -3553,6 +3798,9 @@ class QBitArray(sip.simplewrapper): class QIODevice(QObject): class OpenModeFlag(int): + def __or__ (self, other: 'QIODevice.OpenModeFlag') -> 'QIODevice.OpenMode': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QIODevice.OpenMode': ... # type: ignore[override, misc] + NotOpen = ... # type: QIODevice.OpenModeFlag ReadOnly = ... # type: QIODevice.OpenModeFlag WriteOnly = ... # type: QIODevice.OpenModeFlag @@ -3564,8 +3812,6 @@ class QIODevice(QObject): NewOnly = ... # type: QIODevice.OpenModeFlag ExistingOnly = ... # type: QIODevice.OpenModeFlag - def __or__(self, other: typing.Union['QIODevice.OpenModeFlag', 'QIODevice.OpenMode']) -> 'QIODevice.OpenModeFlag': ... #type: ignore[override] - NotOpen = ... # type: QIODevice.OpenModeFlag ReadOnly = ... # type: QIODevice.OpenModeFlag WriteOnly = ... # type: QIODevice.OpenModeFlag @@ -3584,19 +3830,19 @@ class QIODevice(QObject): @typing.overload def __init__(self, f: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag']) -> None: ... @typing.overload - def __init__(self, a0: 'QIODevice.OpenMode') -> None: ... + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QIODevice.OpenMode': ... def __index__(self) -> int: ... def __int__(self) -> int: ... - def __and__(self, other: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag']) -> 'QIODevice.OpenMode': ... - def __iand__(self, other: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag']) -> 'QIODevice.OpenMode': ... - def __or__(self, other: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag']) -> 'QIODevice.OpenMode': ... - def __ior__(self, other: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag']) -> 'QIODevice.OpenMode': ... - def __xor__(self, other: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag']) -> 'QIODevice.OpenMode': ... - def __ixor__(self, other: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag']) -> 'QIODevice.OpenMode': ... + def __or__ (self, other: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag', int]) -> 'QIODevice.OpenMode': ... + def __and__(self, other: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag', int]) -> 'QIODevice.OpenMode': ... + def __xor__(self, other: typing.Union['QIODevice.OpenMode', 'QIODevice.OpenModeFlag', int]) -> 'QIODevice.OpenMode': ... + def __ror__ (self, other: 'QIODevice.OpenModeFlag') -> 'QIODevice.OpenMode': ... + def __rand__(self, other: 'QIODevice.OpenModeFlag') -> 'QIODevice.OpenMode': ... + def __rxor__(self, other: 'QIODevice.OpenModeFlag') -> 'QIODevice.OpenMode': ... @typing.overload def __init__(self) -> None: ... @@ -3604,8 +3850,8 @@ class QIODevice(QObject): def __init__(self, parent: QObject) -> None: ... def skip(self, maxSize: int) -> int: ... - def channelBytesWritten(self, channel: int, bytes: int) -> None: ... - def channelReadyRead(self, channel: int) -> None: ... + channelBytesWritten: typing.ClassVar[QtCore.pyqtSignal] + channelReadyRead: typing.ClassVar[QtCore.pyqtSignal] def isTransactionStarted(self) -> bool: ... def rollbackTransaction(self) -> None: ... def commitTransaction(self) -> None: ... @@ -3621,10 +3867,10 @@ class QIODevice(QObject): def writeData(self, data: bytes) -> int: ... def readLineData(self, maxlen: int) -> bytes: ... def readData(self, maxlen: int) -> bytes: ... - def readChannelFinished(self) -> None: ... - def aboutToClose(self) -> None: ... - def bytesWritten(self, bytes: int) -> None: ... - def readyRead(self) -> None: ... + readChannelFinished: typing.ClassVar[QtCore.pyqtSignal] + aboutToClose: typing.ClassVar[QtCore.pyqtSignal] + bytesWritten: typing.ClassVar[QtCore.pyqtSignal] + readyRead: typing.ClassVar[QtCore.pyqtSignal] def errorString(self) -> str: ... def getChar(self) -> typing.Tuple[bool, bytes]: ... def putChar(self, c: str) -> bool: ... @@ -3696,6 +3942,9 @@ class QByteArray(sip.simplewrapper): IllegalPadding = ... # type: QByteArray.Base64DecodingStatus class Base64Option(int): + def __or__ (self, other: 'QByteArray.Base64Option') -> 'QByteArray.Base64Options': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QByteArray.Base64Options': ... # type: ignore[override, misc] + Base64Encoding = ... # type: QByteArray.Base64Option Base64UrlEncoding = ... # type: QByteArray.Base64Option KeepTrailingEquals = ... # type: QByteArray.Base64Option @@ -3718,12 +3967,20 @@ class QByteArray(sip.simplewrapper): def __init__(self, f: typing.Union['QByteArray.Base64Options', 'QByteArray.Base64Option']) -> None: ... @typing.overload def __init__(self, a0: 'QByteArray.Base64Options') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QByteArray.Base64Options': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QByteArray.Base64Options', 'QByteArray.Base64Option', int]) -> 'QByteArray.Base64Options': ... + def __and__(self, other: typing.Union['QByteArray.Base64Options', 'QByteArray.Base64Option', int]) -> 'QByteArray.Base64Options': ... + def __xor__(self, other: typing.Union['QByteArray.Base64Options', 'QByteArray.Base64Option', int]) -> 'QByteArray.Base64Options': ... + def __ror__ (self, other: 'QByteArray.Base64Option') -> 'QByteArray.Base64Options': ... + def __rand__(self, other: 'QByteArray.Base64Option') -> 'QByteArray.Base64Options': ... + def __rxor__(self, other: 'QByteArray.Base64Option') -> 'QByteArray.Base64Options': ... class FromBase64Result(sip.simplewrapper): @@ -4177,6 +4434,9 @@ class QCollator(sip.simplewrapper): class QCommandLineOption(sip.simplewrapper): class Flag(int): + def __or__ (self, other: 'QCommandLineOption.Flag') -> 'QCommandLineOption.Flags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QCommandLineOption.Flags': ... # type: ignore[override, misc] + HiddenFromHelp = ... # type: QCommandLineOption.Flag ShortOptionStyle = ... # type: QCommandLineOption.Flag @@ -4191,12 +4451,20 @@ class QCommandLineOption(sip.simplewrapper): def __init__(self, f: typing.Union['QCommandLineOption.Flags', 'QCommandLineOption.Flag']) -> None: ... @typing.overload def __init__(self, a0: 'QCommandLineOption.Flags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QCommandLineOption.Flags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QCommandLineOption.Flags', 'QCommandLineOption.Flag', int]) -> 'QCommandLineOption.Flags': ... + def __and__(self, other: typing.Union['QCommandLineOption.Flags', 'QCommandLineOption.Flag', int]) -> 'QCommandLineOption.Flags': ... + def __xor__(self, other: typing.Union['QCommandLineOption.Flags', 'QCommandLineOption.Flag', int]) -> 'QCommandLineOption.Flags': ... + def __ror__ (self, other: 'QCommandLineOption.Flag') -> 'QCommandLineOption.Flags': ... + def __rand__(self, other: 'QCommandLineOption.Flag') -> 'QCommandLineOption.Flags': ... + def __rxor__(self, other: 'QCommandLineOption.Flag') -> 'QCommandLineOption.Flags': ... @typing.overload def __init__(self, name: str) -> None: ... @@ -5282,6 +5550,9 @@ class QDeadlineTimer(sip.simplewrapper): class QDir(sip.simplewrapper): class SortFlag(int): + def __or__ (self, other: 'QDir.SortFlag') -> 'QDir.SortFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QDir.SortFlags': ... # type: ignore[override, misc] + Name = ... # type: QDir.SortFlag Time = ... # type: QDir.SortFlag Size = ... # type: QDir.SortFlag @@ -5309,6 +5580,9 @@ class QDir(sip.simplewrapper): NoSort = ... # type: QDir.SortFlag class Filter(int): + def __or__ (self, other: 'QDir.Filter') -> 'QDir.Filters': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QDir.Filters': ... # type: ignore[override, misc] + Dirs = ... # type: QDir.Filter Files = ... # type: QDir.Filter Drives = ... # type: QDir.Filter @@ -5359,12 +5633,20 @@ class QDir(sip.simplewrapper): def __init__(self, f: typing.Union['QDir.Filters', 'QDir.Filter']) -> None: ... @typing.overload def __init__(self, a0: 'QDir.Filters') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDir.Filters': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDir.Filters', 'QDir.Filter', int]) -> 'QDir.Filters': ... + def __and__(self, other: typing.Union['QDir.Filters', 'QDir.Filter', int]) -> 'QDir.Filters': ... + def __xor__(self, other: typing.Union['QDir.Filters', 'QDir.Filter', int]) -> 'QDir.Filters': ... + def __ror__ (self, other: 'QDir.Filter') -> 'QDir.Filters': ... + def __rand__(self, other: 'QDir.Filter') -> 'QDir.Filters': ... + def __rxor__(self, other: 'QDir.Filter') -> 'QDir.Filters': ... class SortFlags(sip.simplewrapper): @@ -5374,12 +5656,20 @@ class QDir(sip.simplewrapper): def __init__(self, f: typing.Union['QDir.SortFlags', 'QDir.SortFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QDir.SortFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDir.SortFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDir.SortFlags', 'QDir.SortFlag', int]) -> 'QDir.SortFlags': ... + def __and__(self, other: typing.Union['QDir.SortFlags', 'QDir.SortFlag', int]) -> 'QDir.SortFlags': ... + def __xor__(self, other: typing.Union['QDir.SortFlags', 'QDir.SortFlag', int]) -> 'QDir.SortFlags': ... + def __ror__ (self, other: 'QDir.SortFlag') -> 'QDir.SortFlags': ... + def __rand__(self, other: 'QDir.SortFlag') -> 'QDir.SortFlags': ... + def __rxor__(self, other: 'QDir.SortFlag') -> 'QDir.SortFlags': ... @typing.overload def __init__(self, a0: 'QDir') -> None: ... @@ -5491,6 +5781,9 @@ class QDir(sip.simplewrapper): class QDirIterator(sip.simplewrapper): class IteratorFlag(int): + def __or__ (self, other: 'QDirIterator.IteratorFlag') -> 'QDirIterator.IteratorFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QDirIterator.IteratorFlags': ... # type: ignore[override, misc] + NoIteratorFlags = ... # type: QDirIterator.IteratorFlag FollowSymlinks = ... # type: QDirIterator.IteratorFlag Subdirectories = ... # type: QDirIterator.IteratorFlag @@ -5507,12 +5800,20 @@ class QDirIterator(sip.simplewrapper): def __init__(self, f: typing.Union['QDirIterator.IteratorFlags', 'QDirIterator.IteratorFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QDirIterator.IteratorFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDirIterator.IteratorFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDirIterator.IteratorFlags', 'QDirIterator.IteratorFlag', int]) -> 'QDirIterator.IteratorFlags': ... + def __and__(self, other: typing.Union['QDirIterator.IteratorFlags', 'QDirIterator.IteratorFlag', int]) -> 'QDirIterator.IteratorFlags': ... + def __xor__(self, other: typing.Union['QDirIterator.IteratorFlags', 'QDirIterator.IteratorFlag', int]) -> 'QDirIterator.IteratorFlags': ... + def __ror__ (self, other: 'QDirIterator.IteratorFlag') -> 'QDirIterator.IteratorFlags': ... + def __rand__(self, other: 'QDirIterator.IteratorFlag') -> 'QDirIterator.IteratorFlags': ... + def __rxor__(self, other: 'QDirIterator.IteratorFlag') -> 'QDirIterator.IteratorFlags': ... @typing.overload def __init__(self, dir: QDir, flags: 'QDirIterator.IteratorFlags' = ...) -> None: ... @@ -5693,6 +5994,9 @@ class QElapsedTimer(sip.simplewrapper): class QEventLoop(QObject): class ProcessEventsFlag(int): + def __or__ (self, other: 'QEventLoop.ProcessEventsFlag') -> 'QEventLoop.ProcessEventsFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QEventLoop.ProcessEventsFlags': ... # type: ignore[override, misc] + AllEvents = ... # type: QEventLoop.ProcessEventsFlag ExcludeUserInputEvents = ... # type: QEventLoop.ProcessEventsFlag ExcludeSocketNotifiers = ... # type: QEventLoop.ProcessEventsFlag @@ -5713,12 +6017,20 @@ class QEventLoop(QObject): def __init__(self, f: typing.Union['QEventLoop.ProcessEventsFlags', 'QEventLoop.ProcessEventsFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QEventLoop.ProcessEventsFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QEventLoop.ProcessEventsFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QEventLoop.ProcessEventsFlags', 'QEventLoop.ProcessEventsFlag', int]) -> 'QEventLoop.ProcessEventsFlags': ... + def __and__(self, other: typing.Union['QEventLoop.ProcessEventsFlags', 'QEventLoop.ProcessEventsFlag', int]) -> 'QEventLoop.ProcessEventsFlags': ... + def __xor__(self, other: typing.Union['QEventLoop.ProcessEventsFlags', 'QEventLoop.ProcessEventsFlag', int]) -> 'QEventLoop.ProcessEventsFlags': ... + def __ror__ (self, other: 'QEventLoop.ProcessEventsFlag') -> 'QEventLoop.ProcessEventsFlags': ... + def __rand__(self, other: 'QEventLoop.ProcessEventsFlag') -> 'QEventLoop.ProcessEventsFlags': ... + def __rxor__(self, other: 'QEventLoop.ProcessEventsFlag') -> 'QEventLoop.ProcessEventsFlags': ... def __init__(self, parent: typing.Optional[QObject] = ...) -> None: ... @@ -5789,6 +6101,9 @@ class QFileDevice(QIODevice): DontCloseHandle = ... # type: QFileDevice.FileHandleFlag class Permission(int): + def __or__ (self, other: 'QFileDevice.Permission') -> 'QFileDevice.Permissions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QFileDevice.Permissions': ... # type: ignore[override, misc] + ReadOwner = ... # type: QFileDevice.Permission WriteOwner = ... # type: QFileDevice.Permission ExeOwner = ... # type: QFileDevice.Permission @@ -5856,12 +6171,20 @@ class QFileDevice(QIODevice): def __init__(self, f: typing.Union['QFileDevice.Permissions', 'QFileDevice.Permission']) -> None: ... @typing.overload def __init__(self, a0: 'QFileDevice.Permissions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QFileDevice.Permissions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QFileDevice.Permissions', 'QFileDevice.Permission', int]) -> 'QFileDevice.Permissions': ... + def __and__(self, other: typing.Union['QFileDevice.Permissions', 'QFileDevice.Permission', int]) -> 'QFileDevice.Permissions': ... + def __xor__(self, other: typing.Union['QFileDevice.Permissions', 'QFileDevice.Permission', int]) -> 'QFileDevice.Permissions': ... + def __ror__ (self, other: 'QFileDevice.Permission') -> 'QFileDevice.Permissions': ... + def __rand__(self, other: 'QFileDevice.Permission') -> 'QFileDevice.Permissions': ... + def __rxor__(self, other: 'QFileDevice.Permission') -> 'QFileDevice.Permissions': ... class FileHandleFlags(sip.simplewrapper): @@ -5871,12 +6194,20 @@ class QFileDevice(QIODevice): def __init__(self, f: typing.Union['QFileDevice.FileHandleFlags', 'QFileDevice.FileHandleFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QFileDevice.FileHandleFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QFileDevice.FileHandleFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QFileDevice.FileHandleFlags', 'QFileDevice.FileHandleFlag', int]) -> 'QFileDevice.FileHandleFlags': ... + def __and__(self, other: typing.Union['QFileDevice.FileHandleFlags', 'QFileDevice.FileHandleFlag', int]) -> 'QFileDevice.FileHandleFlags': ... + def __xor__(self, other: typing.Union['QFileDevice.FileHandleFlags', 'QFileDevice.FileHandleFlag', int]) -> 'QFileDevice.FileHandleFlags': ... + def __ror__ (self, other: 'QFileDevice.FileHandleFlag') -> 'QFileDevice.FileHandleFlags': ... + def __rand__(self, other: 'QFileDevice.FileHandleFlag') -> 'QFileDevice.FileHandleFlags': ... + def __rxor__(self, other: 'QFileDevice.FileHandleFlag') -> 'QFileDevice.FileHandleFlags': ... def setFileTime(self, newDate: typing.Union[QDateTime, datetime.datetime], fileTime: 'QFileDevice.FileTime') -> bool: ... def fileTime(self, time: 'QFileDevice.FileTime') -> QDateTime: ... @@ -6074,8 +6405,8 @@ class QFileSystemWatcher(QObject): @typing.overload def __init__(self, paths: typing.Iterable[str], parent: typing.Optional[QObject] = ...) -> None: ... - def fileChanged(self, path: str) -> None: ... - def directoryChanged(self, path: str) -> None: ... + fileChanged: typing.ClassVar[QtCore.pyqtSignal] + directoryChanged: typing.ClassVar[QtCore.pyqtSignal] def removePaths(self, files: typing.Iterable[str]) -> typing.List[str]: ... def removePath(self, file: str) -> bool: ... def files(self) -> typing.List[str]: ... @@ -6107,11 +6438,11 @@ class QHistoryState(QAbstractState): @typing.overload def __init__(self, type: 'QHistoryState.HistoryType', parent: typing.Optional['QState'] = ...) -> None: ... - def defaultTransitionChanged(self) -> None: ... + defaultTransitionChanged: typing.ClassVar[QtCore.pyqtSignal] def setDefaultTransition(self, transition: QAbstractTransition) -> None: ... def defaultTransition(self) -> QAbstractTransition: ... - def historyTypeChanged(self) -> None: ... - def defaultStateChanged(self) -> None: ... + historyTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + defaultStateChanged: typing.ClassVar[QtCore.pyqtSignal] def event(self, e: QEvent) -> bool: ... def onExit(self, event: QEvent) -> None: ... def onEntry(self, event: QEvent) -> None: ... @@ -6183,6 +6514,9 @@ class QItemSelectionRange(sip.simplewrapper): class QItemSelectionModel(QObject): class SelectionFlag(int): + def __or__ (self, other: 'QItemSelectionModel.SelectionFlag') -> 'QItemSelectionModel.SelectionFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QItemSelectionModel.SelectionFlags': ... # type: ignore[override, misc] + NoUpdate = ... # type: QItemSelectionModel.SelectionFlag Clear = ... # type: QItemSelectionModel.SelectionFlag Select = ... # type: QItemSelectionModel.SelectionFlag @@ -6215,27 +6549,35 @@ class QItemSelectionModel(QObject): def __init__(self, f: typing.Union['QItemSelectionModel.SelectionFlags', 'QItemSelectionModel.SelectionFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QItemSelectionModel.SelectionFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QItemSelectionModel.SelectionFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QItemSelectionModel.SelectionFlags', 'QItemSelectionModel.SelectionFlag', int]) -> 'QItemSelectionModel.SelectionFlags': ... + def __and__(self, other: typing.Union['QItemSelectionModel.SelectionFlags', 'QItemSelectionModel.SelectionFlag', int]) -> 'QItemSelectionModel.SelectionFlags': ... + def __xor__(self, other: typing.Union['QItemSelectionModel.SelectionFlags', 'QItemSelectionModel.SelectionFlag', int]) -> 'QItemSelectionModel.SelectionFlags': ... + def __ror__ (self, other: 'QItemSelectionModel.SelectionFlag') -> 'QItemSelectionModel.SelectionFlags': ... + def __rand__(self, other: 'QItemSelectionModel.SelectionFlag') -> 'QItemSelectionModel.SelectionFlags': ... + def __rxor__(self, other: 'QItemSelectionModel.SelectionFlag') -> 'QItemSelectionModel.SelectionFlags': ... @typing.overload def __init__(self, model: typing.Optional[QAbstractItemModel] = ...) -> None: ... @typing.overload def __init__(self, model: QAbstractItemModel, parent: QObject) -> None: ... - def modelChanged(self, model: QAbstractItemModel) -> None: ... + modelChanged: typing.ClassVar[QtCore.pyqtSignal] def setModel(self, model: QAbstractItemModel) -> None: ... def selectedColumns(self, row: int = ...) -> typing.List[QModelIndex]: ... def selectedRows(self, column: int = ...) -> typing.List[QModelIndex]: ... def hasSelection(self) -> bool: ... def emitSelectionChanged(self, newSelection: 'QItemSelection', oldSelection: 'QItemSelection') -> None: ... - def currentColumnChanged(self, current: QModelIndex, previous: QModelIndex) -> None: ... - def currentRowChanged(self, current: QModelIndex, previous: QModelIndex) -> None: ... - def currentChanged(self, current: QModelIndex, previous: QModelIndex) -> None: ... + currentColumnChanged: typing.ClassVar[QtCore.pyqtSignal] + currentRowChanged: typing.ClassVar[QtCore.pyqtSignal] + currentChanged: typing.ClassVar[QtCore.pyqtSignal] selectionChanged: typing.ClassVar[pyqtSignal] def clearCurrentIndex(self) -> None: ... def setCurrentIndex(self, index: QModelIndex, command: typing.Union['QItemSelectionModel.SelectionFlags', 'QItemSelectionModel.SelectionFlag']) -> None: ... @@ -6471,6 +6813,9 @@ class QJsonValue(sip.simplewrapper): class QLibrary(QObject): class LoadHint(int): + def __or__ (self, other: 'QLibrary.LoadHint') -> 'QLibrary.LoadHints': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QLibrary.LoadHints': ... # type: ignore[override, misc] + ResolveAllSymbolsHint = ... # type: QLibrary.LoadHint ExportExternalSymbolsHint = ... # type: QLibrary.LoadHint LoadArchiveMemberHint = ... # type: QLibrary.LoadHint @@ -6491,12 +6836,20 @@ class QLibrary(QObject): def __init__(self, f: typing.Union['QLibrary.LoadHints', 'QLibrary.LoadHint']) -> None: ... @typing.overload def __init__(self, a0: 'QLibrary.LoadHints') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QLibrary.LoadHints': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QLibrary.LoadHints', 'QLibrary.LoadHint', int]) -> 'QLibrary.LoadHints': ... + def __and__(self, other: typing.Union['QLibrary.LoadHints', 'QLibrary.LoadHint', int]) -> 'QLibrary.LoadHints': ... + def __xor__(self, other: typing.Union['QLibrary.LoadHints', 'QLibrary.LoadHint', int]) -> 'QLibrary.LoadHints': ... + def __ror__ (self, other: 'QLibrary.LoadHint') -> 'QLibrary.LoadHints': ... + def __rand__(self, other: 'QLibrary.LoadHint') -> 'QLibrary.LoadHints': ... + def __rxor__(self, other: 'QLibrary.LoadHint') -> 'QLibrary.LoadHints': ... @typing.overload def __init__(self, parent: typing.Optional[QObject] = ...) -> None: ... @@ -7027,6 +7380,9 @@ class QLocale(sip.simplewrapper): NarrowFormat = ... # type: QLocale.FormatType class NumberOption(int): + def __or__ (self, other: 'QLocale.NumberOption') -> 'QLocale.NumberOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QLocale.NumberOptions': ... # type: ignore[override, misc] + OmitGroupSeparator = ... # type: QLocale.NumberOption RejectGroupSeparator = ... # type: QLocale.NumberOption DefaultNumberOptions = ... # type: QLocale.NumberOption @@ -8371,12 +8727,20 @@ class QLocale(sip.simplewrapper): def __init__(self, f: typing.Union['QLocale.NumberOptions', 'QLocale.NumberOption']) -> None: ... @typing.overload def __init__(self, a0: 'QLocale.NumberOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QLocale.NumberOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QLocale.NumberOptions', 'QLocale.NumberOption', int]) -> 'QLocale.NumberOptions': ... + def __and__(self, other: typing.Union['QLocale.NumberOptions', 'QLocale.NumberOption', int]) -> 'QLocale.NumberOptions': ... + def __xor__(self, other: typing.Union['QLocale.NumberOptions', 'QLocale.NumberOption', int]) -> 'QLocale.NumberOptions': ... + def __ror__ (self, other: 'QLocale.NumberOption') -> 'QLocale.NumberOptions': ... + def __rand__(self, other: 'QLocale.NumberOption') -> 'QLocale.NumberOptions': ... + def __rxor__(self, other: 'QLocale.NumberOption') -> 'QLocale.NumberOptions': ... class DataSizeFormats(sip.simplewrapper): @@ -8386,12 +8750,20 @@ class QLocale(sip.simplewrapper): def __init__(self, f: typing.Union['QLocale.DataSizeFormats', 'QLocale.DataSizeFormat']) -> None: ... @typing.overload def __init__(self, a0: 'QLocale.DataSizeFormats') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QLocale.DataSizeFormats': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QLocale.DataSizeFormats', 'QLocale.DataSizeFormat', int]) -> 'QLocale.DataSizeFormats': ... + def __and__(self, other: typing.Union['QLocale.DataSizeFormats', 'QLocale.DataSizeFormat', int]) -> 'QLocale.DataSizeFormats': ... + def __xor__(self, other: typing.Union['QLocale.DataSizeFormats', 'QLocale.DataSizeFormat', int]) -> 'QLocale.DataSizeFormats': ... + def __ror__ (self, other: 'QLocale.DataSizeFormat') -> 'QLocale.DataSizeFormats': ... + def __rand__(self, other: 'QLocale.DataSizeFormat') -> 'QLocale.DataSizeFormats': ... + def __rxor__(self, other: 'QLocale.DataSizeFormat') -> 'QLocale.DataSizeFormats': ... @typing.overload def __init__(self) -> None: ... @@ -8780,6 +9152,9 @@ class QMetaClassInfo(sip.simplewrapper): class QMetaType(sip.simplewrapper): class TypeFlag(int): + def __or__ (self, other: 'QMetaType.TypeFlag') -> 'QMetaType.TypeFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QMetaType.TypeFlags': ... # type: ignore[override, misc] + NeedsConstruction = ... # type: QMetaType.TypeFlag NeedsDestruction = ... # type: QMetaType.TypeFlag MovableType = ... # type: QMetaType.TypeFlag @@ -8969,12 +9344,20 @@ class QMetaType(sip.simplewrapper): def __init__(self, f: typing.Union['QMetaType.TypeFlags', 'QMetaType.TypeFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QMetaType.TypeFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QMetaType.TypeFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QMetaType.TypeFlags', 'QMetaType.TypeFlag', int]) -> 'QMetaType.TypeFlags': ... + def __and__(self, other: typing.Union['QMetaType.TypeFlags', 'QMetaType.TypeFlag', int]) -> 'QMetaType.TypeFlags': ... + def __xor__(self, other: typing.Union['QMetaType.TypeFlags', 'QMetaType.TypeFlag', int]) -> 'QMetaType.TypeFlags': ... + def __ror__ (self, other: 'QMetaType.TypeFlag') -> 'QMetaType.TypeFlags': ... + def __rand__(self, other: 'QMetaType.TypeFlag') -> 'QMetaType.TypeFlags': ... + def __rxor__(self, other: 'QMetaType.TypeFlag') -> 'QMetaType.TypeFlags': ... def __init__(self, type: int = ...) -> None: ... @@ -9302,7 +9685,7 @@ class QVariantAnimation(QAbstractAnimation): def updateState(self, newState: QAbstractAnimation.State, oldState: QAbstractAnimation.State) -> None: ... def updateCurrentTime(self, a0: int) -> None: ... def event(self, event: QEvent) -> bool: ... - def valueChanged(self, value: typing.Any) -> None: ... + valueChanged: typing.ClassVar[QtCore.pyqtSignal] def setEasingCurve(self, easing: typing.Union[QEasingCurve, QEasingCurve.Type]) -> None: ... def easingCurve(self) -> QEasingCurve: ... def setDuration(self, msecs: int) -> None: ... @@ -9540,10 +9923,7 @@ class QProcess(QIODevice): def waitForStarted(self, msecs: int = ...) -> bool: ... def pid(self) -> int: ... def state(self) -> 'QProcess.ProcessState': ... - @typing.overload - def error(self) -> 'QProcess.ProcessError': ... - @typing.overload - def error(self, error: 'QProcess.ProcessError') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def setWorkingDirectory(self, dir: str) -> None: ... def workingDirectory(self) -> str: ... def closeWriteChannel(self) -> None: ... @@ -9908,6 +10288,9 @@ class QRegExp(sip.simplewrapper): class QRegularExpression(sip.simplewrapper): class MatchOption(int): + def __or__ (self, other: 'QRegularExpression.MatchOption') -> 'QRegularExpression.MatchOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QRegularExpression.MatchOptions': ... # type: ignore[override, misc] + NoMatchOption = ... # type: QRegularExpression.MatchOption AnchoredMatchOption = ... # type: QRegularExpression.MatchOption DontCheckSubjectStringMatchOption = ... # type: QRegularExpression.MatchOption @@ -9928,6 +10311,9 @@ class QRegularExpression(sip.simplewrapper): NoMatch = ... # type: QRegularExpression.MatchType class PatternOption(int): + def __or__ (self, other: 'QRegularExpression.PatternOption') -> 'QRegularExpression.PatternOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QRegularExpression.PatternOptions': ... # type: ignore[override, misc] + NoPatternOption = ... # type: QRegularExpression.PatternOption CaseInsensitiveOption = ... # type: QRegularExpression.PatternOption DotMatchesEverythingOption = ... # type: QRegularExpression.PatternOption @@ -9958,12 +10344,20 @@ class QRegularExpression(sip.simplewrapper): def __init__(self, f: typing.Union['QRegularExpression.PatternOptions', 'QRegularExpression.PatternOption']) -> None: ... @typing.overload def __init__(self, a0: 'QRegularExpression.PatternOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QRegularExpression.PatternOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QRegularExpression.PatternOptions', 'QRegularExpression.PatternOption', int]) -> 'QRegularExpression.PatternOptions': ... + def __and__(self, other: typing.Union['QRegularExpression.PatternOptions', 'QRegularExpression.PatternOption', int]) -> 'QRegularExpression.PatternOptions': ... + def __xor__(self, other: typing.Union['QRegularExpression.PatternOptions', 'QRegularExpression.PatternOption', int]) -> 'QRegularExpression.PatternOptions': ... + def __ror__ (self, other: 'QRegularExpression.PatternOption') -> 'QRegularExpression.PatternOptions': ... + def __rand__(self, other: 'QRegularExpression.PatternOption') -> 'QRegularExpression.PatternOptions': ... + def __rxor__(self, other: 'QRegularExpression.PatternOption') -> 'QRegularExpression.PatternOptions': ... class MatchOptions(sip.simplewrapper): @@ -9973,12 +10367,20 @@ class QRegularExpression(sip.simplewrapper): def __init__(self, f: typing.Union['QRegularExpression.MatchOptions', 'QRegularExpression.MatchOption']) -> None: ... @typing.overload def __init__(self, a0: 'QRegularExpression.MatchOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QRegularExpression.MatchOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QRegularExpression.MatchOptions', 'QRegularExpression.MatchOption', int]) -> 'QRegularExpression.MatchOptions': ... + def __and__(self, other: typing.Union['QRegularExpression.MatchOptions', 'QRegularExpression.MatchOption', int]) -> 'QRegularExpression.MatchOptions': ... + def __xor__(self, other: typing.Union['QRegularExpression.MatchOptions', 'QRegularExpression.MatchOption', int]) -> 'QRegularExpression.MatchOptions': ... + def __ror__ (self, other: 'QRegularExpression.MatchOption') -> 'QRegularExpression.MatchOptions': ... + def __rand__(self, other: 'QRegularExpression.MatchOption') -> 'QRegularExpression.MatchOptions': ... + def __rxor__(self, other: 'QRegularExpression.MatchOption') -> 'QRegularExpression.MatchOptions': ... @typing.overload def __init__(self) -> None: ... @@ -10166,7 +10568,7 @@ class QSequentialAnimationGroup(QAnimationGroup): def updateState(self, newState: QAbstractAnimation.State, oldState: QAbstractAnimation.State) -> None: ... def updateCurrentTime(self, a0: int) -> None: ... def event(self, event: QEvent) -> bool: ... - def currentAnimationChanged(self, current: QAbstractAnimation) -> None: ... + currentAnimationChanged: typing.ClassVar[QtCore.pyqtSignal] def duration(self) -> int: ... def currentAnimation(self) -> QAbstractAnimation: ... def insertPause(self, index: int, msecs: int) -> QPauseAnimation: ... @@ -10314,10 +10716,10 @@ class QSignalMapper(QObject): def map(self) -> None: ... @typing.overload def map(self, sender: QObject) -> None: ... - def mappedObject(self, a0: QObject) -> None: ... - def mappedWidget(self, a0: QtWidgets.QWidget) -> None: ... - def mappedString(self, a0: str) -> None: ... - def mappedInt(self, a0: int) -> None: ... + mappedObject: typing.ClassVar[QtCore.pyqtSignal] + mappedWidget: typing.ClassVar[QtCore.pyqtSignal] + mappedString: typing.ClassVar[QtCore.pyqtSignal] + mappedInt: typing.ClassVar[QtCore.pyqtSignal] mapped: typing.ClassVar[pyqtSignal] @typing.overload def mapping(self, id: int) -> QObject: ... @@ -10345,8 +10747,8 @@ class QSignalTransition(QAbstractTransition): @typing.overload def __init__(self, signal: pyqtBoundSignal, sourceState: typing.Optional['QState'] = ...) -> None: ... - def signalChanged(self) -> None: ... - def senderObjectChanged(self) -> None: ... + signalChanged: typing.ClassVar[QtCore.pyqtSignal] + senderObjectChanged: typing.ClassVar[QtCore.pyqtSignal] def event(self, e: QEvent) -> bool: ... def onTransition(self, event: QEvent) -> None: ... def eventTest(self, event: QEvent) -> bool: ... @@ -10365,6 +10767,18 @@ class QSize(sip.simplewrapper): @typing.overload def __init__(self, a0: 'QSize') -> None: ... + def __eq__(self, value: object) -> bool: ... + def __ne__(self, value: object) -> bool: ... + def __add__(self, value: 'QSize') -> 'QSize': ... + def __iadd__(self, value: 'QSize') -> 'QSize': ... + def __sub__(self, value: 'QSize') -> 'QSize': ... + def __isub__(self, value: 'QSize') -> 'QSize': ... + def __mul__(self, value: float) -> 'QSize': ... + def __rmul__(self, value: float) -> 'QSize': ... + def __imul__(self, value: float) -> 'QSize': ... + def __truediv__(self, value: float) -> 'QSize': ... + def __itruediv__(self, value: float) -> 'QSize': ... + def shrunkBy(self, m: QMargins) -> 'QSize': ... def grownBy(self, m: QMargins) -> 'QSize': ... def transposed(self) -> 'QSize': ... @@ -10401,6 +10815,18 @@ class QSizeF(sip.simplewrapper): @typing.overload def __init__(self, a0: 'QSizeF') -> None: ... + def __eq__(self, value: object) -> bool: ... + def __ne__(self, value: object) -> bool: ... + def __add__(self, value: 'QSizeF') -> 'QSizeF': ... + def __iadd__(self, value: 'QSizeF') -> 'QSizeF': ... + def __sub__(self, value: 'QSizeF') -> 'QSizeF': ... + def __isub__(self, value: 'QSizeF') -> 'QSizeF': ... + def __mul__(self, value: float) -> 'QSizeF': ... + def __rmul__(self, value: float) -> 'QSizeF': ... + def __imul__(self, value: float) -> 'QSizeF': ... + def __truediv__(self, value: float) -> 'QSizeF': ... + def __itruediv__(self, value: float) -> 'QSizeF': ... + def shrunkBy(self, m: QMarginsF) -> 'QSizeF': ... def grownBy(self, m: QMarginsF) -> 'QSizeF': ... def transposed(self) -> 'QSizeF': ... @@ -10441,7 +10867,7 @@ class QSocketNotifier(QObject): def __init__(self, socket: sip.voidptr, a1: 'QSocketNotifier.Type', parent: typing.Optional[QObject] = ...) -> None: ... def event(self, a0: QEvent) -> bool: ... - def activated(self, socket: int) -> None: ... + activated: typing.ClassVar[QtCore.pyqtSignal] def setEnabled(self, a0: bool) -> None: ... def isEnabled(self) -> bool: ... def type(self) -> 'QSocketNotifier.Type': ... @@ -10452,13 +10878,13 @@ class QSortFilterProxyModel(QAbstractProxyModel): def __init__(self, parent: typing.Optional[QObject] = ...) -> None: ... - def recursiveFilteringEnabledChanged(self, recursiveFilteringEnabled: bool) -> None: ... - def filterRoleChanged(self, filterRole: int) -> None: ... - def sortRoleChanged(self, sortRole: int) -> None: ... - def sortLocaleAwareChanged(self, sortLocaleAware: bool) -> None: ... - def sortCaseSensitivityChanged(self, sortCaseSensitivity: Qt.CaseSensitivity) -> None: ... - def filterCaseSensitivityChanged(self, filterCaseSensitivity: Qt.CaseSensitivity) -> None: ... - def dynamicSortFilterChanged(self, dynamicSortFilter: bool) -> None: ... + recursiveFilteringEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + filterRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + sortRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + sortLocaleAwareChanged: typing.ClassVar[QtCore.pyqtSignal] + sortCaseSensitivityChanged: typing.ClassVar[QtCore.pyqtSignal] + filterCaseSensitivityChanged: typing.ClassVar[QtCore.pyqtSignal] + dynamicSortFilterChanged: typing.ClassVar[QtCore.pyqtSignal] def invalidateFilter(self) -> None: ... def setRecursiveFilteringEnabled(self, recursive: bool) -> None: ... def isRecursiveFilteringEnabled(self) -> bool: ... @@ -10532,6 +10958,9 @@ class QSortFilterProxyModel(QAbstractProxyModel): class QStandardPaths(sip.simplewrapper): class LocateOption(int): + def __or__ (self, other: 'QStandardPaths.LocateOption') -> 'QStandardPaths.LocateOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QStandardPaths.LocateOptions': ... # type: ignore[override, misc] + LocateFile = ... # type: QStandardPaths.LocateOption LocateDirectory = ... # type: QStandardPaths.LocateOption @@ -10589,12 +11018,20 @@ class QStandardPaths(sip.simplewrapper): def __init__(self, f: typing.Union['QStandardPaths.LocateOptions', 'QStandardPaths.LocateOption']) -> None: ... @typing.overload def __init__(self, a0: 'QStandardPaths.LocateOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStandardPaths.LocateOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStandardPaths.LocateOptions', 'QStandardPaths.LocateOption', int]) -> 'QStandardPaths.LocateOptions': ... + def __and__(self, other: typing.Union['QStandardPaths.LocateOptions', 'QStandardPaths.LocateOption', int]) -> 'QStandardPaths.LocateOptions': ... + def __xor__(self, other: typing.Union['QStandardPaths.LocateOptions', 'QStandardPaths.LocateOption', int]) -> 'QStandardPaths.LocateOptions': ... + def __ror__ (self, other: 'QStandardPaths.LocateOption') -> 'QStandardPaths.LocateOptions': ... + def __rand__(self, other: 'QStandardPaths.LocateOption') -> 'QStandardPaths.LocateOptions': ... + def __rxor__(self, other: 'QStandardPaths.LocateOption') -> 'QStandardPaths.LocateOptions': ... def __init__(self, a0: 'QStandardPaths') -> None: ... @@ -10637,14 +11074,14 @@ class QState(QAbstractState): @typing.overload def __init__(self, childMode: 'QState.ChildMode', parent: typing.Optional['QState'] = ...) -> None: ... - def errorStateChanged(self) -> None: ... - def initialStateChanged(self) -> None: ... - def childModeChanged(self) -> None: ... + errorStateChanged: typing.ClassVar[QtCore.pyqtSignal] + initialStateChanged: typing.ClassVar[QtCore.pyqtSignal] + childModeChanged: typing.ClassVar[QtCore.pyqtSignal] def event(self, e: QEvent) -> bool: ... def onExit(self, event: QEvent) -> None: ... def onEntry(self, event: QEvent) -> None: ... - def propertiesAssigned(self) -> None: ... - def finished(self) -> None: ... + propertiesAssigned: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def assignProperty(self, object: QObject, name: str, value: typing.Any) -> None: ... def setChildMode(self, mode: 'QState.ChildMode') -> None: ... def childMode(self) -> 'QState.ChildMode': ... @@ -10703,9 +11140,9 @@ class QStateMachine(QState): def event(self, e: QEvent) -> bool: ... def onExit(self, event: QEvent) -> None: ... def onEntry(self, event: QEvent) -> None: ... - def runningChanged(self, running: bool) -> None: ... - def stopped(self) -> None: ... - def started(self) -> None: ... + runningChanged: typing.ClassVar[QtCore.pyqtSignal] + stopped: typing.ClassVar[QtCore.pyqtSignal] + started: typing.ClassVar[QtCore.pyqtSignal] def setRunning(self, running: bool) -> None: ... def stop(self) -> None: ... def start(self) -> None: ... @@ -10881,6 +11318,9 @@ class QTextBoundaryFinder(sip.simplewrapper): Sentence = ... # type: QTextBoundaryFinder.BoundaryType class BoundaryReason(int): + def __or__ (self, other: 'QTextBoundaryFinder.BoundaryReason') -> 'QTextBoundaryFinder.BoundaryReasons': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTextBoundaryFinder.BoundaryReasons': ... # type: ignore[override, misc] + NotAtBoundary = ... # type: QTextBoundaryFinder.BoundaryReason SoftHyphen = ... # type: QTextBoundaryFinder.BoundaryReason BreakOpportunity = ... # type: QTextBoundaryFinder.BoundaryReason @@ -10903,12 +11343,20 @@ class QTextBoundaryFinder(sip.simplewrapper): def __init__(self, f: typing.Union['QTextBoundaryFinder.BoundaryReasons', 'QTextBoundaryFinder.BoundaryReason']) -> None: ... @typing.overload def __init__(self, a0: 'QTextBoundaryFinder.BoundaryReasons') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTextBoundaryFinder.BoundaryReasons': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTextBoundaryFinder.BoundaryReasons', 'QTextBoundaryFinder.BoundaryReason', int]) -> 'QTextBoundaryFinder.BoundaryReasons': ... + def __and__(self, other: typing.Union['QTextBoundaryFinder.BoundaryReasons', 'QTextBoundaryFinder.BoundaryReason', int]) -> 'QTextBoundaryFinder.BoundaryReasons': ... + def __xor__(self, other: typing.Union['QTextBoundaryFinder.BoundaryReasons', 'QTextBoundaryFinder.BoundaryReason', int]) -> 'QTextBoundaryFinder.BoundaryReasons': ... + def __ror__ (self, other: 'QTextBoundaryFinder.BoundaryReason') -> 'QTextBoundaryFinder.BoundaryReasons': ... + def __rand__(self, other: 'QTextBoundaryFinder.BoundaryReason') -> 'QTextBoundaryFinder.BoundaryReasons': ... + def __rxor__(self, other: 'QTextBoundaryFinder.BoundaryReason') -> 'QTextBoundaryFinder.BoundaryReasons': ... @typing.overload def __init__(self) -> None: ... @@ -10933,6 +11381,9 @@ class QTextBoundaryFinder(sip.simplewrapper): class QTextCodec(sip.wrapper): class ConversionFlag(int): + def __or__ (self, other: 'QTextCodec.ConversionFlag') -> 'QTextCodec.ConversionFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTextCodec.ConversionFlags': ... # type: ignore[override, misc] + DefaultConversion = ... # type: QTextCodec.ConversionFlag ConvertInvalidToNull = ... # type: QTextCodec.ConversionFlag IgnoreHeader = ... # type: QTextCodec.ConversionFlag @@ -10949,12 +11400,20 @@ class QTextCodec(sip.wrapper): def __init__(self, f: typing.Union['QTextCodec.ConversionFlags', 'QTextCodec.ConversionFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QTextCodec.ConversionFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTextCodec.ConversionFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTextCodec.ConversionFlags', 'QTextCodec.ConversionFlag', int]) -> 'QTextCodec.ConversionFlags': ... + def __and__(self, other: typing.Union['QTextCodec.ConversionFlags', 'QTextCodec.ConversionFlag', int]) -> 'QTextCodec.ConversionFlags': ... + def __xor__(self, other: typing.Union['QTextCodec.ConversionFlags', 'QTextCodec.ConversionFlag', int]) -> 'QTextCodec.ConversionFlags': ... + def __ror__ (self, other: 'QTextCodec.ConversionFlag') -> 'QTextCodec.ConversionFlags': ... + def __rand__(self, other: 'QTextCodec.ConversionFlag') -> 'QTextCodec.ConversionFlags': ... + def __rxor__(self, other: 'QTextCodec.ConversionFlag') -> 'QTextCodec.ConversionFlags': ... class ConverterState(sip.simplewrapper): @@ -11042,6 +11501,9 @@ class QTextStream(sip.simplewrapper): WriteFailed = ... # type: QTextStream.Status class NumberFlag(int): + def __or__ (self, other: 'QTextStream.NumberFlag') -> 'QTextStream.NumberFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTextStream.NumberFlags': ... # type: ignore[override, misc] + ShowBase = ... # type: QTextStream.NumberFlag ForcePoint = ... # type: QTextStream.NumberFlag ForceSign = ... # type: QTextStream.NumberFlag @@ -11082,12 +11544,20 @@ class QTextStream(sip.simplewrapper): def __init__(self, f: typing.Union['QTextStream.NumberFlags', 'QTextStream.NumberFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QTextStream.NumberFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTextStream.NumberFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTextStream.NumberFlags', 'QTextStream.NumberFlag', int]) -> 'QTextStream.NumberFlags': ... + def __and__(self, other: typing.Union['QTextStream.NumberFlags', 'QTextStream.NumberFlag', int]) -> 'QTextStream.NumberFlags': ... + def __xor__(self, other: typing.Union['QTextStream.NumberFlags', 'QTextStream.NumberFlag', int]) -> 'QTextStream.NumberFlags': ... + def __ror__ (self, other: 'QTextStream.NumberFlag') -> 'QTextStream.NumberFlags': ... + def __rand__(self, other: 'QTextStream.NumberFlag') -> 'QTextStream.NumberFlags': ... + def __rxor__(self, other: 'QTextStream.NumberFlag') -> 'QTextStream.NumberFlags': ... @typing.overload def __init__(self) -> None: ... @@ -11273,10 +11743,10 @@ class QTimeLine(QObject): def setEasingCurve(self, curve: typing.Union[QEasingCurve, QEasingCurve.Type]) -> None: ... def easingCurve(self) -> QEasingCurve: ... def timerEvent(self, event: QTimerEvent) -> None: ... - def valueChanged(self, x: float) -> None: ... - def stateChanged(self, newState: 'QTimeLine.State') -> None: ... - def frameChanged(self, a0: int) -> None: ... - def finished(self) -> None: ... + valueChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + frameChanged: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def toggleDirection(self) -> None: ... def stop(self) -> None: ... def start(self) -> None: ... @@ -11483,6 +11953,9 @@ class QUrl(sip.simplewrapper): AssumeLocalFile = ... # type: QUrl.UserInputResolutionOption class ComponentFormattingOption(int): + def __or__ (self, other: 'QUrl.ComponentFormattingOption') -> 'QUrl.ComponentFormattingOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QUrl.ComponentFormattingOptions': ... # type: ignore[override, misc] + PrettyDecoded = ... # type: QUrl.ComponentFormattingOption EncodeSpaces = ... # type: QUrl.ComponentFormattingOption EncodeUnicode = ... # type: QUrl.ComponentFormattingOption @@ -11502,6 +11975,9 @@ class QUrl(sip.simplewrapper): FullyDecoded = ... # type: QUrl.ComponentFormattingOption class UrlFormattingOption(int): + def __or__(self, other: 'QUrl.UrlFormattingOption') -> 'QUrl.FormattingOptions': ... # type: ignore[override] + def __ror__(self, other: int) -> 'QUrl.FormattingOptions': ... # type: ignore[override, misc] + None_ = ... # type: QUrl.UrlFormattingOption RemoveScheme = ... # type: QUrl.UrlFormattingOption RemovePassword = ... # type: QUrl.UrlFormattingOption @@ -11552,12 +12028,20 @@ class QUrl(sip.simplewrapper): def __init__(self, f: typing.Union['QUrl.ComponentFormattingOptions', 'QUrl.ComponentFormattingOption']) -> None: ... @typing.overload def __init__(self, a0: 'QUrl.ComponentFormattingOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QUrl.ComponentFormattingOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QUrl.ComponentFormattingOptions', 'QUrl.ComponentFormattingOption', int]) -> 'QUrl.ComponentFormattingOptions': ... + def __and__(self, other: typing.Union['QUrl.ComponentFormattingOptions', 'QUrl.ComponentFormattingOption', int]) -> 'QUrl.ComponentFormattingOptions': ... + def __xor__(self, other: typing.Union['QUrl.ComponentFormattingOptions', 'QUrl.ComponentFormattingOption', int]) -> 'QUrl.ComponentFormattingOptions': ... + def __ror__ (self, other: 'QUrl.ComponentFormattingOption') -> 'QUrl.ComponentFormattingOptions': ... + def __rand__(self, other: 'QUrl.ComponentFormattingOption') -> 'QUrl.ComponentFormattingOptions': ... + def __rxor__(self, other: 'QUrl.ComponentFormattingOption') -> 'QUrl.ComponentFormattingOptions': ... class UserInputResolutionOptions(sip.simplewrapper): @@ -11567,12 +12051,20 @@ class QUrl(sip.simplewrapper): def __init__(self, f: typing.Union['QUrl.UserInputResolutionOptions', 'QUrl.UserInputResolutionOption']) -> None: ... @typing.overload def __init__(self, a0: 'QUrl.UserInputResolutionOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QUrl.UserInputResolutionOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QUrl.UserInputResolutionOptions', 'QUrl.UserInputResolutionOption', int]) -> 'QUrl.UserInputResolutionOptions': ... + def __and__(self, other: typing.Union['QUrl.UserInputResolutionOptions', 'QUrl.UserInputResolutionOption', int]) -> 'QUrl.UserInputResolutionOptions': ... + def __xor__(self, other: typing.Union['QUrl.UserInputResolutionOptions', 'QUrl.UserInputResolutionOption', int]) -> 'QUrl.UserInputResolutionOptions': ... + def __ror__ (self, other: 'QUrl.UserInputResolutionOption') -> 'QUrl.UserInputResolutionOptions': ... + def __rand__(self, other: 'QUrl.UserInputResolutionOption') -> 'QUrl.UserInputResolutionOptions': ... + def __rxor__(self, other: 'QUrl.UserInputResolutionOption') -> 'QUrl.UserInputResolutionOptions': ... @typing.overload def __init__(self) -> None: ... @@ -12297,6 +12789,194 @@ class QSysInfo(sip.simplewrapper): WordSize = ... # type: QSysInfo.Sizes + if sys.platform == "win32": + class WinVersion(int): + WV_10_0 = ... # type: int + WV_2000 = ... # type: int + WV_2003 = ... # type: int + WV_32s = ... # type: int + WV_4_0 = ... # type: int + WV_5_0 = ... # type: int + WV_5_1 = ... # type: int + WV_5_2 = ... # type: int + WV_6_0 = ... # type: int + WV_6_1 = ... # type: int + WV_6_2 = ... # type: int + WV_6_3 = ... # type: int + WV_95 = ... # type: int + WV_98 = ... # type: int + WV_CE = ... # type: int + WV_CENET = ... # type: int + WV_CE_5 = ... # type: int + WV_CE_6 = ... # type: int + WV_CE_based = ... # type: int + WV_DOS_based = ... # type: int + WV_Me = ... # type: int + WV_NT = ... # type: int + WV_NT_based = ... # type: int + WV_VISTA = ... # type: int + WV_WINDOWS10 = ... # type: int + WV_WINDOWS7 = ... # type: int + WV_WINDOWS8 = ... # type: int + WV_WINDOWS8_1 = ... # type: int + WV_XP = ... # type: int + + WindowsVersion = ... # type: QSysInfo.WinVersion + + WV_10_0 = ... # type: int + WV_2000 = ... # type: int + WV_2003 = ... # type: int + WV_32s = ... # type: int + WV_4_0 = ... # type: int + WV_5_0 = ... # type: int + WV_5_1 = ... # type: int + WV_5_2 = ... # type: int + WV_6_0 = ... # type: int + WV_6_1 = ... # type: int + WV_6_2 = ... # type: int + WV_6_3 = ... # type: int + WV_95 = ... # type: int + WV_98 = ... # type: int + WV_CE = ... # type: int + WV_CENET = ... # type: int + WV_CE_5 = ... # type: int + WV_CE_6 = ... # type: int + WV_CE_based = ... # type: int + WV_DOS_based = ... # type: int + WV_Me = ... # type: int + WV_NT = ... # type: int + WV_NT_based = ... # type: int + WV_VISTA = ... # type: int + WV_WINDOWS10 = ... # type: int + WV_WINDOWS7 = ... # type: int + WV_WINDOWS8 = ... # type: int + WV_WINDOWS8_1 = ... # type: int + WV_XP = ... # type: int + + @staticmethod + def windowsVersion() -> 'QSysInfo.WinVersion': ... + + if sys.platform == "darwin": + class MacVersion(int): + MV_10_0 = ... # type: int + MV_10_1 = ... # type: int + MV_10_10 = ... # type: int + MV_10_11 = ... # type: int + MV_10_12 = ... # type: int + MV_10_2 = ... # type: int + MV_10_3 = ... # type: int + MV_10_4 = ... # type: int + MV_10_5 = ... # type: int + MV_10_6 = ... # type: int + MV_10_7 = ... # type: int + MV_10_8 = ... # type: int + MV_10_9 = ... # type: int + MV_9 = ... # type: int + MV_CHEETAH = ... # type: int + MV_ELCAPITAN = ... # type: int + MV_IOS = ... # type: int + MV_IOS_10_0 = ... # type: int + MV_IOS_4_3 = ... # type: int + MV_IOS_5_0 = ... # type: int + MV_IOS_5_1 = ... # type: int + MV_IOS_6_0 = ... # type: int + MV_IOS_6_1 = ... # type: int + MV_IOS_7_0 = ... # type: int + MV_IOS_7_1 = ... # type: int + MV_IOS_8_0 = ... # type: int + MV_IOS_8_1 = ... # type: int + MV_IOS_8_2 = ... # type: int + MV_IOS_8_3 = ... # type: int + MV_IOS_8_4 = ... # type: int + MV_IOS_9_0 = ... # type: int + MV_IOS_9_1 = ... # type: int + MV_IOS_9_2 = ... # type: int + MV_IOS_9_3 = ... # type: int + MV_JAGUAR = ... # type: int + MV_LEOPARD = ... # type: int + MV_LION = ... # type: int + MV_MAVERICKS = ... # type: int + MV_MOUNTAINLION = ... # type: int + MV_PANTHER = ... # type: int + MV_PUMA = ... # type: int + MV_SIERRA = ... # type: int + MV_SNOWLEOPARD = ... # type: int + MV_TIGER = ... # type: int + MV_TVOS = ... # type: int + MV_TVOS_10_0 = ... # type: int + MV_TVOS_9_0 = ... # type: int + MV_TVOS_9_1 = ... # type: int + MV_TVOS_9_2 = ... # type: int + MV_Unknown = ... # type: int + MV_WATCHOS = ... # type: int + MV_WATCHOS_2_0 = ... # type: int + MV_WATCHOS_2_1 = ... # type: int + MV_WATCHOS_2_2 = ... # type: int + MV_WATCHOS_3_0 = ... # type: int + MV_YOSEMITE = ... # type: int + + MV_10_0 = ... # type: int + MV_10_1 = ... # type: int + MV_10_10 = ... # type: int + MV_10_11 = ... # type: int + MV_10_12 = ... # type: int + MV_10_2 = ... # type: int + MV_10_3 = ... # type: int + MV_10_4 = ... # type: int + MV_10_5 = ... # type: int + MV_10_6 = ... # type: int + MV_10_7 = ... # type: int + MV_10_8 = ... # type: int + MV_10_9 = ... # type: int + MV_9 = ... # type: int + MV_CHEETAH = ... # type: int + MV_ELCAPITAN = ... # type: int + MV_IOS = ... # type: int + MV_IOS_10_0 = ... # type: int + MV_IOS_4_3 = ... # type: int + MV_IOS_5_0 = ... # type: int + MV_IOS_5_1 = ... # type: int + MV_IOS_6_0 = ... # type: int + MV_IOS_6_1 = ... # type: int + MV_IOS_7_0 = ... # type: int + MV_IOS_7_1 = ... # type: int + MV_IOS_8_0 = ... # type: int + MV_IOS_8_1 = ... # type: int + MV_IOS_8_2 = ... # type: int + MV_IOS_8_3 = ... # type: int + MV_IOS_8_4 = ... # type: int + MV_IOS_9_0 = ... # type: int + MV_IOS_9_1 = ... # type: int + MV_IOS_9_2 = ... # type: int + MV_IOS_9_3 = ... # type: int + MV_JAGUAR = ... # type: int + MV_LEOPARD = ... # type: int + MV_LION = ... # type: int + MV_MAVERICKS = ... # type: int + MV_MOUNTAINLION = ... # type: int + MV_PANTHER = ... # type: int + MV_PUMA = ... # type: int + MV_SIERRA = ... # type: int + MV_SNOWLEOPARD = ... # type: int + MV_TIGER = ... # type: int + MV_TVOS = ... # type: int + MV_TVOS_10_0 = ... # type: int + MV_TVOS_9_0 = ... # type: int + MV_TVOS_9_1 = ... # type: int + MV_TVOS_9_2 = ... # type: int + MV_Unknown = ... # type: int + MV_WATCHOS = ... # type: int + MV_WATCHOS_2_0 = ... # type: int + MV_WATCHOS_2_1 = ... # type: int + MV_WATCHOS_2_2 = ... # type: int + MV_WATCHOS_3_0 = ... # type: int + MV_YOSEMITE = ... # type: int + + MacintoshVersion = ... # type: QSysInfo.MacVersion + + @staticmethod + def macVersion() -> 'QSysInfo.MacVersion': ... + @typing.overload def __init__(self) -> None: ... @typing.overload @@ -12324,6 +13004,7 @@ class QSysInfo(sip.simplewrapper): PYQT_VERSION = ... # type: int PYQT_VERSION_STR = ... # type: str +PYQT_CONFIGURATION = ... # type: typing.Dict[str, str] QT_VERSION = ... # type: int QT_VERSION_STR = ... # type: str diff --git a/PyQt5-stubs/QtDBus.pyi b/PyQt5-stubs/QtDBus.pyi index ac26141b..03b0ccb5 100644 --- a/PyQt5-stubs/QtDBus.pyi +++ b/PyQt5-stubs/QtDBus.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtDBus module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -106,6 +106,9 @@ class QDBus(sip.simplewrapper): class QDBusConnection(sip.simplewrapper): class ConnectionCapability(int): + def __or__ (self, other: 'QDBusConnection.ConnectionCapability') -> 'QDBusConnection.ConnectionCapabilities': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QDBusConnection.ConnectionCapabilities': ... # type: ignore[override, misc] + UnixFileDescriptorPassing = ... # type: QDBusConnection.ConnectionCapability UnixFileDescriptorPassing = ... # type: QDBusConnection.ConnectionCapability @@ -118,6 +121,9 @@ class QDBusConnection(sip.simplewrapper): UnregisterTree = ... # type: QDBusConnection.UnregisterMode class RegisterOption(int): + def __or__ (self, other: typing.Union[int, 'QDBusConnection.RegisterOption']) -> 'QDBusConnection.RegisterOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QDBusConnection.RegisterOptions': ... # type: ignore[override, misc] + ExportAdaptors = ... # type: QDBusConnection.RegisterOption ExportScriptableSlots = ... # type: QDBusConnection.RegisterOption ExportScriptableSignals = ... # type: QDBusConnection.RegisterOption @@ -173,12 +179,20 @@ class QDBusConnection(sip.simplewrapper): def __init__(self, f: typing.Union['QDBusConnection.RegisterOptions', 'QDBusConnection.RegisterOption']) -> None: ... @typing.overload def __init__(self, a0: 'QDBusConnection.RegisterOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDBusConnection.RegisterOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDBusConnection.RegisterOptions', 'QDBusConnection.RegisterOption', int]) -> 'QDBusConnection.RegisterOptions': ... + def __and__(self, other: typing.Union['QDBusConnection.RegisterOptions', 'QDBusConnection.RegisterOption', int]) -> 'QDBusConnection.RegisterOptions': ... + def __xor__(self, other: typing.Union['QDBusConnection.RegisterOptions', 'QDBusConnection.RegisterOption', int]) -> 'QDBusConnection.RegisterOptions': ... + def __ror__ (self, other: 'QDBusConnection.RegisterOption') -> 'QDBusConnection.RegisterOptions': ... + def __rand__(self, other: 'QDBusConnection.RegisterOption') -> 'QDBusConnection.RegisterOptions': ... + def __rxor__(self, other: 'QDBusConnection.RegisterOption') -> 'QDBusConnection.RegisterOptions': ... class ConnectionCapabilities(sip.simplewrapper): @@ -188,12 +202,20 @@ class QDBusConnection(sip.simplewrapper): def __init__(self, f: typing.Union['QDBusConnection.ConnectionCapabilities', 'QDBusConnection.ConnectionCapability']) -> None: ... @typing.overload def __init__(self, a0: 'QDBusConnection.ConnectionCapabilities') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDBusConnection.ConnectionCapabilities': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDBusConnection.ConnectionCapabilities', 'QDBusConnection.ConnectionCapability', int]) -> 'QDBusConnection.ConnectionCapabilities': ... + def __and__(self, other: typing.Union['QDBusConnection.ConnectionCapabilities', 'QDBusConnection.ConnectionCapability', int]) -> 'QDBusConnection.ConnectionCapabilities': ... + def __xor__(self, other: typing.Union['QDBusConnection.ConnectionCapabilities', 'QDBusConnection.ConnectionCapability', int]) -> 'QDBusConnection.ConnectionCapabilities': ... + def __ror__ (self, other: 'QDBusConnection.ConnectionCapability') -> 'QDBusConnection.ConnectionCapabilities': ... + def __rand__(self, other: 'QDBusConnection.ConnectionCapability') -> 'QDBusConnection.ConnectionCapabilities': ... + def __rxor__(self, other: 'QDBusConnection.ConnectionCapability') -> 'QDBusConnection.ConnectionCapabilities': ... @typing.overload def __init__(self, name: str) -> None: ... @@ -282,10 +304,10 @@ class QDBusConnectionInterface(QDBusAbstractInterface): def disconnectNotify(self, a0: QtCore.QMetaMethod) -> None: ... def connectNotify(self, a0: QtCore.QMetaMethod) -> None: ... - def callWithCallbackFailed(self, error: 'QDBusError', call: 'QDBusMessage') -> None: ... - def serviceOwnerChanged(self, name: str, oldOwner: str, newOwner: str) -> None: ... - def serviceUnregistered(self, service: str) -> None: ... - def serviceRegistered(self, service: str) -> None: ... + callWithCallbackFailed: typing.ClassVar[QtCore.pyqtSignal] + serviceOwnerChanged: typing.ClassVar[QtCore.pyqtSignal] + serviceUnregistered: typing.ClassVar[QtCore.pyqtSignal] + serviceRegistered: typing.ClassVar[QtCore.pyqtSignal] def startService(self, name: str) -> QDBusReply: ... def serviceUid(self, serviceName: str) -> QDBusReply: ... def servicePid(self, serviceName: str) -> QDBusReply: ... @@ -498,7 +520,7 @@ class QDBusPendingCallWatcher(QtCore.QObject, QDBusPendingCall): def __init__(self, call: QDBusPendingCall, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def finished(self, watcher: typing.Optional['QDBusPendingCallWatcher'] = ...) -> None: ... + finished: typing.ClassVar[QtCore.pyqtSignal] def waitForFinished(self) -> None: ... def isFinished(self) -> bool: ... @@ -506,6 +528,9 @@ class QDBusPendingCallWatcher(QtCore.QObject, QDBusPendingCall): class QDBusServiceWatcher(QtCore.QObject): class WatchModeFlag(int): + def __or__ (self, other: typing.Union[int, 'QDBusServiceWatcher.WatchModeFlag']) -> 'QDBusServiceWatcher.WatchMode': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QDBusServiceWatcher.WatchMode': ... # type: ignore[override, misc] + WatchForRegistration = ... # type: QDBusServiceWatcher.WatchModeFlag WatchForUnregistration = ... # type: QDBusServiceWatcher.WatchModeFlag WatchForOwnerChange = ... # type: QDBusServiceWatcher.WatchModeFlag @@ -522,21 +547,29 @@ class QDBusServiceWatcher(QtCore.QObject): def __init__(self, f: typing.Union['QDBusServiceWatcher.WatchMode', 'QDBusServiceWatcher.WatchModeFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QDBusServiceWatcher.WatchMode') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDBusServiceWatcher.WatchMode': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDBusServiceWatcher.WatchMode', 'QDBusServiceWatcher.WatchModeFlag', int]) -> 'QDBusServiceWatcher.WatchMode': ... + def __and__(self, other: typing.Union['QDBusServiceWatcher.WatchMode', 'QDBusServiceWatcher.WatchModeFlag', int]) -> 'QDBusServiceWatcher.WatchMode': ... + def __xor__(self, other: typing.Union['QDBusServiceWatcher.WatchMode', 'QDBusServiceWatcher.WatchModeFlag', int]) -> 'QDBusServiceWatcher.WatchMode': ... + def __ror__ (self, other: 'QDBusServiceWatcher.WatchModeFlag') -> 'QDBusServiceWatcher.WatchMode': ... + def __rand__(self, other: 'QDBusServiceWatcher.WatchModeFlag') -> 'QDBusServiceWatcher.WatchMode': ... + def __rxor__(self, other: 'QDBusServiceWatcher.WatchModeFlag') -> 'QDBusServiceWatcher.WatchMode': ... @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @typing.overload def __init__(self, service: str, connection: QDBusConnection, watchMode: typing.Union['QDBusServiceWatcher.WatchMode', 'QDBusServiceWatcher.WatchModeFlag'] = ..., parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def serviceOwnerChanged(self, service: str, oldOwner: str, newOwner: str) -> None: ... - def serviceUnregistered(self, service: str) -> None: ... - def serviceRegistered(self, service: str) -> None: ... + serviceOwnerChanged: typing.ClassVar[QtCore.pyqtSignal] + serviceUnregistered: typing.ClassVar[QtCore.pyqtSignal] + serviceRegistered: typing.ClassVar[QtCore.pyqtSignal] def setConnection(self, connection: QDBusConnection) -> None: ... def connection(self) -> QDBusConnection: ... def setWatchMode(self, mode: typing.Union['QDBusServiceWatcher.WatchMode', 'QDBusServiceWatcher.WatchModeFlag']) -> None: ... diff --git a/PyQt5-stubs/QtDataVisualization.pyi b/PyQt5-stubs/QtDataVisualization.pyi index b4c86933..410adb71 100644 --- a/PyQt5-stubs/QtDataVisualization.pyi +++ b/PyQt5-stubs/QtDataVisualization.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtDataVisualization module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -42,6 +42,9 @@ PYQT_OPENGL_BOUND_ARRAY = typing.Union[typing.Sequence[int], class QAbstract3DGraph(QtGui.QWindow): class OptimizationHint(int): + def __or__ (self, other: 'QAbstract3DGraph.OptimizationHint') -> 'QAbstract3DGraph.OptimizationHints': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QAbstract3DGraph.OptimizationHints': ... # type: ignore[override, misc] + OptimizationDefault = ... # type: QAbstract3DGraph.OptimizationHint OptimizationStatic = ... # type: QAbstract3DGraph.OptimizationHint @@ -81,6 +84,9 @@ class QAbstract3DGraph(QtGui.QWindow): ShadowQualitySoftHigh = ... # type: QAbstract3DGraph.ShadowQuality class SelectionFlag(int): + def __or__ (self, other: 'QAbstract3DGraph.SelectionFlag') -> 'QAbstract3DGraph.SelectionFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QAbstract3DGraph.SelectionFlags': ... # type: ignore[override, misc] + SelectionNone = ... # type: QAbstract3DGraph.SelectionFlag SelectionItem = ... # type: QAbstract3DGraph.SelectionFlag SelectionRow = ... # type: QAbstract3DGraph.SelectionFlag @@ -111,12 +117,20 @@ class QAbstract3DGraph(QtGui.QWindow): def __init__(self, f: typing.Union['QAbstract3DGraph.SelectionFlags', 'QAbstract3DGraph.SelectionFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QAbstract3DGraph.SelectionFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QAbstract3DGraph.SelectionFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QAbstract3DGraph.SelectionFlags', 'QAbstract3DGraph.SelectionFlag', int]) -> 'QAbstract3DGraph.SelectionFlags': ... + def __and__(self, other: typing.Union['QAbstract3DGraph.SelectionFlags', 'QAbstract3DGraph.SelectionFlag', int]) -> 'QAbstract3DGraph.SelectionFlags': ... + def __xor__(self, other: typing.Union['QAbstract3DGraph.SelectionFlags', 'QAbstract3DGraph.SelectionFlag', int]) -> 'QAbstract3DGraph.SelectionFlags': ... + def __ror__ (self, other: 'QAbstract3DGraph.SelectionFlag') -> 'QAbstract3DGraph.SelectionFlags': ... + def __rand__(self, other: 'QAbstract3DGraph.SelectionFlag') -> 'QAbstract3DGraph.SelectionFlags': ... + def __rxor__(self, other: 'QAbstract3DGraph.SelectionFlag') -> 'QAbstract3DGraph.SelectionFlags': ... class OptimizationHints(sip.simplewrapper): @@ -126,22 +140,30 @@ class QAbstract3DGraph(QtGui.QWindow): def __init__(self, f: typing.Union['QAbstract3DGraph.OptimizationHints', 'QAbstract3DGraph.OptimizationHint']) -> None: ... @typing.overload def __init__(self, a0: 'QAbstract3DGraph.OptimizationHints') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QAbstract3DGraph.OptimizationHints': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QAbstract3DGraph.OptimizationHints', 'QAbstract3DGraph.OptimizationHint', int]) -> 'QAbstract3DGraph.OptimizationHints': ... + def __and__(self, other: typing.Union['QAbstract3DGraph.OptimizationHints', 'QAbstract3DGraph.OptimizationHint', int]) -> 'QAbstract3DGraph.OptimizationHints': ... + def __xor__(self, other: typing.Union['QAbstract3DGraph.OptimizationHints', 'QAbstract3DGraph.OptimizationHint', int]) -> 'QAbstract3DGraph.OptimizationHints': ... + def __ror__ (self, other: 'QAbstract3DGraph.OptimizationHint') -> 'QAbstract3DGraph.OptimizationHints': ... + def __rand__(self, other: 'QAbstract3DGraph.OptimizationHint') -> 'QAbstract3DGraph.OptimizationHints': ... + def __rxor__(self, other: 'QAbstract3DGraph.OptimizationHint') -> 'QAbstract3DGraph.OptimizationHints': ... def hasContext(self) -> bool: ... - def marginChanged(self, margin: float) -> None: ... - def queriedGraphPositionChanged(self, data: QtGui.QVector3D) -> None: ... - def localeChanged(self, locale: QtCore.QLocale) -> None: ... - def reflectivityChanged(self, reflectivity: float) -> None: ... - def reflectionChanged(self, enabled: bool) -> None: ... - def horizontalAspectRatioChanged(self, ratio: float) -> None: ... - def radialLabelOffsetChanged(self, offset: float) -> None: ... - def polarChanged(self, enabled: bool) -> None: ... + marginChanged: typing.ClassVar[QtCore.pyqtSignal] + queriedGraphPositionChanged: typing.ClassVar[QtCore.pyqtSignal] + localeChanged: typing.ClassVar[QtCore.pyqtSignal] + reflectivityChanged: typing.ClassVar[QtCore.pyqtSignal] + reflectionChanged: typing.ClassVar[QtCore.pyqtSignal] + horizontalAspectRatioChanged: typing.ClassVar[QtCore.pyqtSignal] + radialLabelOffsetChanged: typing.ClassVar[QtCore.pyqtSignal] + polarChanged: typing.ClassVar[QtCore.pyqtSignal] def margin(self) -> float: ... def setMargin(self, margin: float) -> None: ... def queriedGraphPosition(self) -> QtGui.QVector3D: ... @@ -158,12 +180,12 @@ class QAbstract3DGraph(QtGui.QWindow): def isPolar(self) -> bool: ... def setPolar(self, enable: bool) -> None: ... def customItems(self) -> typing.List['QCustom3DItem']: ... - def optimizationHintsChanged(self, hints: typing.Union['QAbstract3DGraph.OptimizationHints', 'QAbstract3DGraph.OptimizationHint']) -> None: ... - def aspectRatioChanged(self, ratio: float) -> None: ... - def orthoProjectionChanged(self, enabled: bool) -> None: ... - def currentFpsChanged(self, fps: float) -> None: ... - def measureFpsChanged(self, enabled: bool) -> None: ... - def selectedElementChanged(self, type: 'QAbstract3DGraph.ElementType') -> None: ... + optimizationHintsChanged: typing.ClassVar[QtCore.pyqtSignal] + aspectRatioChanged: typing.ClassVar[QtCore.pyqtSignal] + orthoProjectionChanged: typing.ClassVar[QtCore.pyqtSignal] + currentFpsChanged: typing.ClassVar[QtCore.pyqtSignal] + measureFpsChanged: typing.ClassVar[QtCore.pyqtSignal] + selectedElementChanged: typing.ClassVar[QtCore.pyqtSignal] def optimizationHints(self) -> 'QAbstract3DGraph.OptimizationHints': ... def setOptimizationHints(self, hints: typing.Union['QAbstract3DGraph.OptimizationHints', 'QAbstract3DGraph.OptimizationHint']) -> None: ... def aspectRatio(self) -> float: ... @@ -193,10 +215,10 @@ class QAbstract3DGraph(QtGui.QWindow): def exposeEvent(self, event: QtGui.QExposeEvent) -> None: ... def resizeEvent(self, event: QtGui.QResizeEvent) -> None: ... def event(self, event: QtCore.QEvent) -> bool: ... - def shadowQualityChanged(self, quality: 'QAbstract3DGraph.ShadowQuality') -> None: ... - def selectionModeChanged(self, mode: typing.Union['QAbstract3DGraph.SelectionFlags', 'QAbstract3DGraph.SelectionFlag']) -> None: ... - def activeThemeChanged(self, theme: 'Q3DTheme') -> None: ... - def activeInputHandlerChanged(self, inputHandler: 'QAbstract3DInputHandler') -> None: ... + shadowQualityChanged: typing.ClassVar[QtCore.pyqtSignal] + selectionModeChanged: typing.ClassVar[QtCore.pyqtSignal] + activeThemeChanged: typing.ClassVar[QtCore.pyqtSignal] + activeInputHandlerChanged: typing.ClassVar[QtCore.pyqtSignal] def shadowsSupported(self) -> bool: ... def activeInputHandler(self) -> 'QAbstract3DInputHandler': ... def clearSelection(self) -> None: ... @@ -219,18 +241,18 @@ class Q3DBars('QAbstract3DGraph'): def __init__(self, format: typing.Optional[QtGui.QSurfaceFormat] = ..., parent: typing.Optional[QtGui.QWindow] = ...) -> None: ... - def floorLevelChanged(self, level: float) -> None: ... + floorLevelChanged: typing.ClassVar[QtCore.pyqtSignal] def floorLevel(self) -> float: ... def setFloorLevel(self, level: float) -> None: ... - def selectedSeriesChanged(self, series: 'QBar3DSeries') -> None: ... - def primarySeriesChanged(self, series: 'QBar3DSeries') -> None: ... - def valueAxisChanged(self, axis: 'QValue3DAxis') -> None: ... - def columnAxisChanged(self, axis: 'QCategory3DAxis') -> None: ... - def rowAxisChanged(self, axis: 'QCategory3DAxis') -> None: ... - def barSpacingRelativeChanged(self, relative: bool) -> None: ... - def barSpacingChanged(self, spacing: QtCore.QSizeF) -> None: ... - def barThicknessChanged(self, thicknessRatio: float) -> None: ... - def multiSeriesUniformChanged(self, uniform: bool) -> None: ... + selectedSeriesChanged: typing.ClassVar[QtCore.pyqtSignal] + primarySeriesChanged: typing.ClassVar[QtCore.pyqtSignal] + valueAxisChanged: typing.ClassVar[QtCore.pyqtSignal] + columnAxisChanged: typing.ClassVar[QtCore.pyqtSignal] + rowAxisChanged: typing.ClassVar[QtCore.pyqtSignal] + barSpacingRelativeChanged: typing.ClassVar[QtCore.pyqtSignal] + barSpacingChanged: typing.ClassVar[QtCore.pyqtSignal] + barThicknessChanged: typing.ClassVar[QtCore.pyqtSignal] + multiSeriesUniformChanged: typing.ClassVar[QtCore.pyqtSignal] def selectedSeries(self) -> 'QBar3DSeries': ... def axes(self) -> typing.List['QAbstract3DAxis']: ... def releaseAxis(self, axis: 'QAbstract3DAxis') -> None: ... @@ -262,7 +284,7 @@ class Q3DObject(QtCore.QObject): def isDirty(self) -> bool: ... def setDirty(self, dirty: bool) -> None: ... - def positionChanged(self, position: QtGui.QVector3D) -> None: ... + positionChanged: typing.ClassVar[QtCore.pyqtSignal] def setPosition(self, position: QtGui.QVector3D) -> None: ... def position(self) -> QtGui.QVector3D: ... def parentScene(self) -> 'Q3DScene': ... @@ -325,21 +347,21 @@ class Q3DCamera('Q3DObject'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def targetChanged(self, target: QtGui.QVector3D) -> None: ... - def maxZoomLevelChanged(self, zoomLevel: float) -> None: ... - def minZoomLevelChanged(self, zoomLevel: float) -> None: ... + targetChanged: typing.ClassVar[QtCore.pyqtSignal] + maxZoomLevelChanged: typing.ClassVar[QtCore.pyqtSignal] + minZoomLevelChanged: typing.ClassVar[QtCore.pyqtSignal] def setTarget(self, target: QtGui.QVector3D) -> None: ... def target(self) -> QtGui.QVector3D: ... def setMaxZoomLevel(self, zoomLevel: float) -> None: ... def maxZoomLevel(self) -> float: ... def setMinZoomLevel(self, zoomLevel: float) -> None: ... def minZoomLevel(self) -> float: ... - def wrapYRotationChanged(self, isEnabled: bool) -> None: ... - def wrapXRotationChanged(self, isEnabled: bool) -> None: ... - def cameraPresetChanged(self, preset: 'Q3DCamera.CameraPreset') -> None: ... - def zoomLevelChanged(self, zoomLevel: float) -> None: ... - def yRotationChanged(self, rotation: float) -> None: ... - def xRotationChanged(self, rotation: float) -> None: ... + wrapYRotationChanged: typing.ClassVar[QtCore.pyqtSignal] + wrapXRotationChanged: typing.ClassVar[QtCore.pyqtSignal] + cameraPresetChanged: typing.ClassVar[QtCore.pyqtSignal] + zoomLevelChanged: typing.ClassVar[QtCore.pyqtSignal] + yRotationChanged: typing.ClassVar[QtCore.pyqtSignal] + xRotationChanged: typing.ClassVar[QtCore.pyqtSignal] def setZoomLevel(self, zoomLevel: float) -> None: ... def zoomLevel(self) -> float: ... def setCameraPosition(self, horizontal: float, vertical: float, zoom: float = ...) -> None: ... @@ -372,9 +394,9 @@ class QAbstract3DInputHandler(QtCore.QObject): def setPreviousInputPos(self, position: QtCore.QPoint) -> None: ... def prevDistance(self) -> int: ... def setPrevDistance(self, distance: int) -> None: ... - def sceneChanged(self, scene: 'Q3DScene') -> None: ... - def inputViewChanged(self, view: 'QAbstract3DInputHandler.InputView') -> None: ... - def positionChanged(self, position: QtCore.QPoint) -> None: ... + sceneChanged: typing.ClassVar[QtCore.pyqtSignal] + inputViewChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] def setScene(self, scene: 'Q3DScene') -> None: ... def scene(self) -> 'Q3DScene': ... def setInputPosition(self, position: QtCore.QPoint) -> None: ... @@ -392,10 +414,10 @@ class Q3DInputHandler('QAbstract3DInputHandler'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def zoomAtTargetEnabledChanged(self, enable: bool) -> None: ... - def selectionEnabledChanged(self, enable: bool) -> None: ... - def zoomEnabledChanged(self, enable: bool) -> None: ... - def rotationEnabledChanged(self, enable: bool) -> None: ... + zoomAtTargetEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + selectionEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + zoomEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] def isZoomAtTargetEnabled(self) -> bool: ... def setZoomAtTargetEnabled(self, enable: bool) -> None: ... def isSelectionEnabled(self) -> bool: ... @@ -413,7 +435,7 @@ class Q3DLight('Q3DObject'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def autoPositionChanged(self, autoPosition: bool) -> None: ... + autoPositionChanged: typing.ClassVar[QtCore.pyqtSignal] def isAutoPosition(self) -> bool: ... def setAutoPosition(self, enabled: bool) -> None: ... @@ -421,10 +443,10 @@ class Q3DScatter('QAbstract3DGraph'): def __init__(self, format: typing.Optional[QtGui.QSurfaceFormat] = ..., parent: typing.Optional[QtGui.QWindow] = ...) -> None: ... - def selectedSeriesChanged(self, series: 'QScatter3DSeries') -> None: ... - def axisZChanged(self, axis: 'QValue3DAxis') -> None: ... - def axisYChanged(self, axis: 'QValue3DAxis') -> None: ... - def axisXChanged(self, axis: 'QValue3DAxis') -> None: ... + selectedSeriesChanged: typing.ClassVar[QtCore.pyqtSignal] + axisZChanged: typing.ClassVar[QtCore.pyqtSignal] + axisYChanged: typing.ClassVar[QtCore.pyqtSignal] + axisXChanged: typing.ClassVar[QtCore.pyqtSignal] def selectedSeries(self) -> 'QScatter3DSeries': ... def axes(self) -> typing.List['QValue3DAxis']: ... def releaseAxis(self, axis: 'QValue3DAxis') -> None: ... @@ -443,18 +465,18 @@ class Q3DScene(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def graphPositionQueryChanged(self, position: QtCore.QPoint) -> None: ... + graphPositionQueryChanged: typing.ClassVar[QtCore.pyqtSignal] def graphPositionQuery(self) -> QtCore.QPoint: ... def setGraphPositionQuery(self, point: QtCore.QPoint) -> None: ... - def selectionQueryPositionChanged(self, position: QtCore.QPoint) -> None: ... - def devicePixelRatioChanged(self, pixelRatio: float) -> None: ... - def activeLightChanged(self, light: 'Q3DLight') -> None: ... - def activeCameraChanged(self, camera: 'Q3DCamera') -> None: ... - def slicingActiveChanged(self, isSlicingActive: bool) -> None: ... - def secondarySubviewOnTopChanged(self, isSecondaryOnTop: bool) -> None: ... - def secondarySubViewportChanged(self, subViewport: QtCore.QRect) -> None: ... - def primarySubViewportChanged(self, subViewport: QtCore.QRect) -> None: ... - def viewportChanged(self, viewport: QtCore.QRect) -> None: ... + selectionQueryPositionChanged: typing.ClassVar[QtCore.pyqtSignal] + devicePixelRatioChanged: typing.ClassVar[QtCore.pyqtSignal] + activeLightChanged: typing.ClassVar[QtCore.pyqtSignal] + activeCameraChanged: typing.ClassVar[QtCore.pyqtSignal] + slicingActiveChanged: typing.ClassVar[QtCore.pyqtSignal] + secondarySubviewOnTopChanged: typing.ClassVar[QtCore.pyqtSignal] + secondarySubViewportChanged: typing.ClassVar[QtCore.pyqtSignal] + primarySubViewportChanged: typing.ClassVar[QtCore.pyqtSignal] + viewportChanged: typing.ClassVar[QtCore.pyqtSignal] def setDevicePixelRatio(self, pixelRatio: float) -> None: ... def devicePixelRatio(self) -> float: ... def setActiveLight(self, light: 'Q3DLight') -> None: ... @@ -481,13 +503,13 @@ class Q3DSurface('QAbstract3DGraph'): def __init__(self, format: typing.Optional[QtGui.QSurfaceFormat] = ..., parent: typing.Optional[QtGui.QWindow] = ...) -> None: ... - def flipHorizontalGridChanged(self, flip: bool) -> None: ... + flipHorizontalGridChanged: typing.ClassVar[QtCore.pyqtSignal] def flipHorizontalGrid(self) -> bool: ... def setFlipHorizontalGrid(self, flip: bool) -> None: ... - def selectedSeriesChanged(self, series: 'QSurface3DSeries') -> None: ... - def axisZChanged(self, axis: 'QValue3DAxis') -> None: ... - def axisYChanged(self, axis: 'QValue3DAxis') -> None: ... - def axisXChanged(self, axis: 'QValue3DAxis') -> None: ... + selectedSeriesChanged: typing.ClassVar[QtCore.pyqtSignal] + axisZChanged: typing.ClassVar[QtCore.pyqtSignal] + axisYChanged: typing.ClassVar[QtCore.pyqtSignal] + axisXChanged: typing.ClassVar[QtCore.pyqtSignal] def selectedSeries(self) -> 'QSurface3DSeries': ... def axes(self) -> typing.List['QValue3DAxis']: ... def releaseAxis(self, axis: 'QValue3DAxis') -> None: ... @@ -539,28 +561,28 @@ class Q3DTheme(QtCore.QObject): @typing.overload def __init__(self, themeType: 'Q3DTheme.Theme', parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def colorStyleChanged(self, style: 'Q3DTheme.ColorStyle') -> None: ... - def labelBackgroundEnabledChanged(self, enabled: bool) -> None: ... - def gridEnabledChanged(self, enabled: bool) -> None: ... - def backgroundEnabledChanged(self, enabled: bool) -> None: ... - def fontChanged(self, font: QtGui.QFont) -> None: ... - def labelBorderEnabledChanged(self, enabled: bool) -> None: ... - def highlightLightStrengthChanged(self, strength: float) -> None: ... - def ambientLightStrengthChanged(self, strength: float) -> None: ... - def lightStrengthChanged(self, strength: float) -> None: ... - def multiHighlightGradientChanged(self, gradient: QtGui.QLinearGradient) -> None: ... - def singleHighlightGradientChanged(self, gradient: QtGui.QLinearGradient) -> None: ... - def baseGradientsChanged(self, gradients: typing.Iterable[QtGui.QLinearGradient]) -> None: ... - def lightColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def multiHighlightColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def singleHighlightColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def gridLineColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def labelBackgroundColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def labelTextColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def windowColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def backgroundColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def baseColorsChanged(self, colors: typing.Iterable[typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]]) -> None: ... - def typeChanged(self, themeType: 'Q3DTheme.Theme') -> None: ... + colorStyleChanged: typing.ClassVar[QtCore.pyqtSignal] + labelBackgroundEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + gridEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + backgroundEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + fontChanged: typing.ClassVar[QtCore.pyqtSignal] + labelBorderEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + highlightLightStrengthChanged: typing.ClassVar[QtCore.pyqtSignal] + ambientLightStrengthChanged: typing.ClassVar[QtCore.pyqtSignal] + lightStrengthChanged: typing.ClassVar[QtCore.pyqtSignal] + multiHighlightGradientChanged: typing.ClassVar[QtCore.pyqtSignal] + singleHighlightGradientChanged: typing.ClassVar[QtCore.pyqtSignal] + baseGradientsChanged: typing.ClassVar[QtCore.pyqtSignal] + lightColorChanged: typing.ClassVar[QtCore.pyqtSignal] + multiHighlightColorChanged: typing.ClassVar[QtCore.pyqtSignal] + singleHighlightColorChanged: typing.ClassVar[QtCore.pyqtSignal] + gridLineColorChanged: typing.ClassVar[QtCore.pyqtSignal] + labelBackgroundColorChanged: typing.ClassVar[QtCore.pyqtSignal] + labelTextColorChanged: typing.ClassVar[QtCore.pyqtSignal] + windowColorChanged: typing.ClassVar[QtCore.pyqtSignal] + backgroundColorChanged: typing.ClassVar[QtCore.pyqtSignal] + baseColorsChanged: typing.ClassVar[QtCore.pyqtSignal] + typeChanged: typing.ClassVar[QtCore.pyqtSignal] def colorStyle(self) -> 'Q3DTheme.ColorStyle': ... def setColorStyle(self, style: 'Q3DTheme.ColorStyle') -> None: ... def isLabelBackgroundEnabled(self) -> bool: ... @@ -628,22 +650,22 @@ class QAbstract3DAxis(QtCore.QObject): AxisOrientationY = ... # type: QAbstract3DAxis.AxisOrientation AxisOrientationZ = ... # type: QAbstract3DAxis.AxisOrientation - def titleFixedChanged(self, fixed: bool) -> None: ... - def titleVisibilityChanged(self, visible: bool) -> None: ... - def labelAutoRotationChanged(self, angle: float) -> None: ... + titleFixedChanged: typing.ClassVar[QtCore.pyqtSignal] + titleVisibilityChanged: typing.ClassVar[QtCore.pyqtSignal] + labelAutoRotationChanged: typing.ClassVar[QtCore.pyqtSignal] def isTitleFixed(self) -> bool: ... def setTitleFixed(self, fixed: bool) -> None: ... def isTitleVisible(self) -> bool: ... def setTitleVisible(self, visible: bool) -> None: ... def labelAutoRotation(self) -> float: ... def setLabelAutoRotation(self, angle: float) -> None: ... - def autoAdjustRangeChanged(self, autoAdjust: bool) -> None: ... - def rangeChanged(self, min: float, max: float) -> None: ... - def maxChanged(self, value: float) -> None: ... - def minChanged(self, value: float) -> None: ... - def orientationChanged(self, orientation: 'QAbstract3DAxis.AxisOrientation') -> None: ... - def labelsChanged(self) -> None: ... - def titleChanged(self, newTitle: str) -> None: ... + autoAdjustRangeChanged: typing.ClassVar[QtCore.pyqtSignal] + rangeChanged: typing.ClassVar[QtCore.pyqtSignal] + maxChanged: typing.ClassVar[QtCore.pyqtSignal] + minChanged: typing.ClassVar[QtCore.pyqtSignal] + orientationChanged: typing.ClassVar[QtCore.pyqtSignal] + labelsChanged: typing.ClassVar[QtCore.pyqtSignal] + titleChanged: typing.ClassVar[QtCore.pyqtSignal] def setTitle(self, title: str) -> None: ... def setRange(self, min: float, max: float) -> None: ... def isAutoAdjustRange(self) -> bool: ... @@ -698,25 +720,25 @@ class QAbstract3DSeries(QtCore.QObject): SeriesTypeScatter = ... # type: QAbstract3DSeries.SeriesType SeriesTypeSurface = ... # type: QAbstract3DSeries.SeriesType - def itemLabelVisibilityChanged(self, visible: bool) -> None: ... - def itemLabelChanged(self, label: str) -> None: ... + itemLabelVisibilityChanged: typing.ClassVar[QtCore.pyqtSignal] + itemLabelChanged: typing.ClassVar[QtCore.pyqtSignal] def isItemLabelVisible(self) -> bool: ... def setItemLabelVisible(self, visible: bool) -> None: ... def itemLabel(self) -> str: ... - def nameChanged(self, name: str) -> None: ... - def multiHighlightGradientChanged(self, gradient: QtGui.QLinearGradient) -> None: ... - def multiHighlightColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def singleHighlightGradientChanged(self, gradient: QtGui.QLinearGradient) -> None: ... - def singleHighlightColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def baseGradientChanged(self, gradient: QtGui.QLinearGradient) -> None: ... - def baseColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def colorStyleChanged(self, style: 'Q3DTheme.ColorStyle') -> None: ... - def userDefinedMeshChanged(self, fileName: str) -> None: ... - def meshRotationChanged(self, rotation: QtGui.QQuaternion) -> None: ... - def meshSmoothChanged(self, enabled: bool) -> None: ... - def meshChanged(self, mesh: 'QAbstract3DSeries.Mesh') -> None: ... - def visibilityChanged(self, visible: bool) -> None: ... - def itemLabelFormatChanged(self, format: str) -> None: ... + nameChanged: typing.ClassVar[QtCore.pyqtSignal] + multiHighlightGradientChanged: typing.ClassVar[QtCore.pyqtSignal] + multiHighlightColorChanged: typing.ClassVar[QtCore.pyqtSignal] + singleHighlightGradientChanged: typing.ClassVar[QtCore.pyqtSignal] + singleHighlightColorChanged: typing.ClassVar[QtCore.pyqtSignal] + baseGradientChanged: typing.ClassVar[QtCore.pyqtSignal] + baseColorChanged: typing.ClassVar[QtCore.pyqtSignal] + colorStyleChanged: typing.ClassVar[QtCore.pyqtSignal] + userDefinedMeshChanged: typing.ClassVar[QtCore.pyqtSignal] + meshRotationChanged: typing.ClassVar[QtCore.pyqtSignal] + meshSmoothChanged: typing.ClassVar[QtCore.pyqtSignal] + meshChanged: typing.ClassVar[QtCore.pyqtSignal] + visibilityChanged: typing.ClassVar[QtCore.pyqtSignal] + itemLabelFormatChanged: typing.ClassVar[QtCore.pyqtSignal] def setMeshAxisAndAngle(self, axis: QtGui.QVector3D, angle: float) -> None: ... def name(self) -> str: ... def setName(self, name: str) -> None: ... @@ -770,9 +792,9 @@ class QBar3DSeries('QAbstract3DSeries'): @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def meshAngleChanged(self, angle: float) -> None: ... - def selectedBarChanged(self, position: QtCore.QPoint) -> None: ... - def dataProxyChanged(self, proxy: 'QBarDataProxy') -> None: ... + meshAngleChanged: typing.ClassVar[QtCore.pyqtSignal] + selectedBarChanged: typing.ClassVar[QtCore.pyqtSignal] + dataProxyChanged: typing.ClassVar[QtCore.pyqtSignal] def meshAngle(self) -> float: ... def setMeshAngle(self, angle: float) -> None: ... @staticmethod @@ -802,16 +824,16 @@ class QBarDataProxy('QAbstractDataProxy'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def seriesChanged(self, series: 'QBar3DSeries') -> None: ... - def columnLabelsChanged(self) -> None: ... - def rowLabelsChanged(self) -> None: ... - def rowCountChanged(self, count: int) -> None: ... - def itemChanged(self, rowIndex: int, columnIndex: int) -> None: ... - def rowsInserted(self, startIndex: int, count: int) -> None: ... - def rowsRemoved(self, startIndex: int, count: int) -> None: ... - def rowsChanged(self, startIndex: int, count: int) -> None: ... - def rowsAdded(self, startIndex: int, count: int) -> None: ... - def arrayReset(self) -> None: ... + seriesChanged: typing.ClassVar[QtCore.pyqtSignal] + columnLabelsChanged: typing.ClassVar[QtCore.pyqtSignal] + rowLabelsChanged: typing.ClassVar[QtCore.pyqtSignal] + rowCountChanged: typing.ClassVar[QtCore.pyqtSignal] + itemChanged: typing.ClassVar[QtCore.pyqtSignal] + rowsInserted: typing.ClassVar[QtCore.pyqtSignal] + rowsRemoved: typing.ClassVar[QtCore.pyqtSignal] + rowsChanged: typing.ClassVar[QtCore.pyqtSignal] + rowsAdded: typing.ClassVar[QtCore.pyqtSignal] + arrayReset: typing.ClassVar[QtCore.pyqtSignal] def series(self) -> 'QBar3DSeries': ... def removeRows(self, rowIndex: int, removeCount: int, removeLabels: bool = ...) -> None: ... @typing.overload @@ -864,7 +886,7 @@ class QCategory3DAxis('QAbstract3DAxis'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def labelsChanged(self) -> None: ... + labelsChanged: typing.ClassVar[QtCore.pyqtSignal] def labels(self) -> typing.List[str]: ... def setLabels(self, labels: typing.Iterable[str]) -> None: ... @@ -875,17 +897,17 @@ class QCustom3DItem(QtCore.QObject): @typing.overload def __init__(self, meshFile: str, position: QtGui.QVector3D, scaling: QtGui.QVector3D, rotation: QtGui.QQuaternion, texture: QtGui.QImage, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def scalingAbsoluteChanged(self, scalingAbsolute: bool) -> None: ... + scalingAbsoluteChanged: typing.ClassVar[QtCore.pyqtSignal] def isScalingAbsolute(self) -> bool: ... def setScalingAbsolute(self, scalingAbsolute: bool) -> None: ... - def shadowCastingChanged(self, shadowCasting: bool) -> None: ... - def visibleChanged(self, visible: bool) -> None: ... - def rotationChanged(self, rotation: QtGui.QQuaternion) -> None: ... - def scalingChanged(self, scaling: QtGui.QVector3D) -> None: ... - def positionAbsoluteChanged(self, positionAbsolute: bool) -> None: ... - def positionChanged(self, position: QtGui.QVector3D) -> None: ... - def textureFileChanged(self, textureFile: str) -> None: ... - def meshFileChanged(self, meshFile: str) -> None: ... + shadowCastingChanged: typing.ClassVar[QtCore.pyqtSignal] + visibleChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationChanged: typing.ClassVar[QtCore.pyqtSignal] + scalingChanged: typing.ClassVar[QtCore.pyqtSignal] + positionAbsoluteChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + textureFileChanged: typing.ClassVar[QtCore.pyqtSignal] + meshFileChanged: typing.ClassVar[QtCore.pyqtSignal] def setTextureImage(self, textureImage: QtGui.QImage) -> None: ... def setRotationAxisAndAngle(self, axis: QtGui.QVector3D, angle: float) -> None: ... def isShadowCasting(self) -> bool: ... @@ -912,13 +934,13 @@ class QCustom3DLabel('QCustom3DItem'): @typing.overload def __init__(self, text: str, font: QtGui.QFont, position: QtGui.QVector3D, scaling: QtGui.QVector3D, rotation: QtGui.QQuaternion, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def facingCameraChanged(self, enabled: bool) -> None: ... - def backgroundEnabledChanged(self, enabled: bool) -> None: ... - def borderEnabledChanged(self, enabled: bool) -> None: ... - def backgroundColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def textColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def fontChanged(self, font: QtGui.QFont) -> None: ... - def textChanged(self, text: str) -> None: ... + facingCameraChanged: typing.ClassVar[QtCore.pyqtSignal] + backgroundEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + borderEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + backgroundColorChanged: typing.ClassVar[QtCore.pyqtSignal] + textColorChanged: typing.ClassVar[QtCore.pyqtSignal] + fontChanged: typing.ClassVar[QtCore.pyqtSignal] + textChanged: typing.ClassVar[QtCore.pyqtSignal] def isFacingCamera(self) -> bool: ... def setFacingCamera(self, enabled: bool) -> None: ... def isBackgroundEnabled(self) -> bool: ... @@ -941,24 +963,24 @@ class QCustom3DVolume('QCustom3DItem'): @typing.overload def __init__(self, position: QtGui.QVector3D, scaling: QtGui.QVector3D, rotation: QtGui.QQuaternion, textureWidth: int, textureHeight: int, textureDepth: int, textureData: sip.array[int], textureFormat: QtGui.QImage.Format, colorTable: typing.Iterable[int], parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def sliceFrameThicknessesChanged(self, values: QtGui.QVector3D) -> None: ... - def sliceFrameGapsChanged(self, values: QtGui.QVector3D) -> None: ... - def sliceFrameWidthsChanged(self, values: QtGui.QVector3D) -> None: ... - def sliceFrameColorChanged(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... - def drawSliceFramesChanged(self, enabled: bool) -> None: ... - def drawSlicesChanged(self, enabled: bool) -> None: ... - def useHighDefShaderChanged(self, enabled: bool) -> None: ... - def preserveOpacityChanged(self, enabled: bool) -> None: ... - def alphaMultiplierChanged(self, mult: float) -> None: ... - def textureFormatChanged(self, format: QtGui.QImage.Format) -> None: ... - def textureDataChanged(self, data: sip.array[int]) -> None: ... - def colorTableChanged(self) -> None: ... - def sliceIndexZChanged(self, value: int) -> None: ... - def sliceIndexYChanged(self, value: int) -> None: ... - def sliceIndexXChanged(self, value: int) -> None: ... - def textureDepthChanged(self, value: int) -> None: ... - def textureHeightChanged(self, value: int) -> None: ... - def textureWidthChanged(self, value: int) -> None: ... + sliceFrameThicknessesChanged: typing.ClassVar[QtCore.pyqtSignal] + sliceFrameGapsChanged: typing.ClassVar[QtCore.pyqtSignal] + sliceFrameWidthsChanged: typing.ClassVar[QtCore.pyqtSignal] + sliceFrameColorChanged: typing.ClassVar[QtCore.pyqtSignal] + drawSliceFramesChanged: typing.ClassVar[QtCore.pyqtSignal] + drawSlicesChanged: typing.ClassVar[QtCore.pyqtSignal] + useHighDefShaderChanged: typing.ClassVar[QtCore.pyqtSignal] + preserveOpacityChanged: typing.ClassVar[QtCore.pyqtSignal] + alphaMultiplierChanged: typing.ClassVar[QtCore.pyqtSignal] + textureFormatChanged: typing.ClassVar[QtCore.pyqtSignal] + textureDataChanged: typing.ClassVar[QtCore.pyqtSignal] + colorTableChanged: typing.ClassVar[QtCore.pyqtSignal] + sliceIndexZChanged: typing.ClassVar[QtCore.pyqtSignal] + sliceIndexYChanged: typing.ClassVar[QtCore.pyqtSignal] + sliceIndexXChanged: typing.ClassVar[QtCore.pyqtSignal] + textureDepthChanged: typing.ClassVar[QtCore.pyqtSignal] + textureHeightChanged: typing.ClassVar[QtCore.pyqtSignal] + textureWidthChanged: typing.ClassVar[QtCore.pyqtSignal] def renderSlice(self, axis: QtCore.Qt.Axis, index: int) -> QtGui.QImage: ... def sliceFrameThicknesses(self) -> QtGui.QVector3D: ... def setSliceFrameThicknesses(self, values: QtGui.QVector3D) -> None: ... @@ -1009,15 +1031,15 @@ class QSurfaceDataProxy('QAbstractDataProxy'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def seriesChanged(self, series: 'QSurface3DSeries') -> None: ... - def columnCountChanged(self, count: int) -> None: ... - def rowCountChanged(self, count: int) -> None: ... - def itemChanged(self, rowIndex: int, columnIndex: int) -> None: ... - def rowsInserted(self, startIndex: int, count: int) -> None: ... - def rowsRemoved(self, startIndex: int, count: int) -> None: ... - def rowsChanged(self, startIndex: int, count: int) -> None: ... - def rowsAdded(self, startIndex: int, count: int) -> None: ... - def arrayReset(self) -> None: ... + seriesChanged: typing.ClassVar[QtCore.pyqtSignal] + columnCountChanged: typing.ClassVar[QtCore.pyqtSignal] + rowCountChanged: typing.ClassVar[QtCore.pyqtSignal] + itemChanged: typing.ClassVar[QtCore.pyqtSignal] + rowsInserted: typing.ClassVar[QtCore.pyqtSignal] + rowsRemoved: typing.ClassVar[QtCore.pyqtSignal] + rowsChanged: typing.ClassVar[QtCore.pyqtSignal] + rowsAdded: typing.ClassVar[QtCore.pyqtSignal] + arrayReset: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def itemAt(self, rowIndex: int, columnIndex: int) -> 'QSurfaceDataItem': ... @typing.overload @@ -1048,12 +1070,12 @@ class QHeightMapSurfaceDataProxy('QSurfaceDataProxy'): @typing.overload def __init__(self, filename: str, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def maxZValueChanged(self, value: float) -> None: ... - def minZValueChanged(self, value: float) -> None: ... - def maxXValueChanged(self, value: float) -> None: ... - def minXValueChanged(self, value: float) -> None: ... - def heightMapFileChanged(self, filename: str) -> None: ... - def heightMapChanged(self, image: QtGui.QImage) -> None: ... + maxZValueChanged: typing.ClassVar[QtCore.pyqtSignal] + minZValueChanged: typing.ClassVar[QtCore.pyqtSignal] + maxXValueChanged: typing.ClassVar[QtCore.pyqtSignal] + minXValueChanged: typing.ClassVar[QtCore.pyqtSignal] + heightMapFileChanged: typing.ClassVar[QtCore.pyqtSignal] + heightMapChanged: typing.ClassVar[QtCore.pyqtSignal] def maxZValue(self) -> float: ... def setMaxZValue(self, max: float) -> None: ... def minZValue(self) -> float: ... @@ -1096,15 +1118,15 @@ class QItemModelBarDataProxy('QBarDataProxy'): @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def multiMatchBehaviorChanged(self, behavior: 'QItemModelBarDataProxy.MultiMatchBehavior') -> None: ... - def rotationRoleReplaceChanged(self, replace: str) -> None: ... - def valueRoleReplaceChanged(self, replace: str) -> None: ... - def columnRoleReplaceChanged(self, replace: str) -> None: ... - def rowRoleReplaceChanged(self, replace: str) -> None: ... - def rotationRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def valueRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def columnRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def rowRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... + multiMatchBehaviorChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + valueRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + columnRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + rowRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + valueRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + columnRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + rowRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] def multiMatchBehavior(self) -> 'QItemModelBarDataProxy.MultiMatchBehavior': ... def setMultiMatchBehavior(self, behavior: 'QItemModelBarDataProxy.MultiMatchBehavior') -> None: ... def rotationRoleReplace(self) -> str: ... @@ -1123,16 +1145,16 @@ class QItemModelBarDataProxy('QBarDataProxy'): def setColumnRolePattern(self, pattern: QtCore.QRegExp) -> None: ... def rowRolePattern(self) -> QtCore.QRegExp: ... def setRowRolePattern(self, pattern: QtCore.QRegExp) -> None: ... - def autoColumnCategoriesChanged(self, enable: bool) -> None: ... - def autoRowCategoriesChanged(self, enable: bool) -> None: ... - def useModelCategoriesChanged(self, enable: bool) -> None: ... - def columnCategoriesChanged(self) -> None: ... - def rowCategoriesChanged(self) -> None: ... - def rotationRoleChanged(self, role: str) -> None: ... - def valueRoleChanged(self, role: str) -> None: ... - def columnRoleChanged(self, role: str) -> None: ... - def rowRoleChanged(self, role: str) -> None: ... - def itemModelChanged(self, itemModel: QtCore.QAbstractItemModel) -> None: ... + autoColumnCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + autoRowCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + useModelCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + columnCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + rowCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + valueRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + columnRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + rowRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + itemModelChanged: typing.ClassVar[QtCore.pyqtSignal] def remap(self, rowRole: str, columnRole: str, valueRole: str, rotationRole: str, rowCategories: typing.Iterable[str], columnCategories: typing.Iterable[str]) -> None: ... def rotationRole(self) -> str: ... def setRotationRole(self, role: str) -> None: ... @@ -1161,13 +1183,13 @@ class QScatterDataProxy('QAbstractDataProxy'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def seriesChanged(self, series: 'QScatter3DSeries') -> None: ... - def itemCountChanged(self, count: int) -> None: ... - def itemsInserted(self, startIndex: int, count: int) -> None: ... - def itemsRemoved(self, startIndex: int, count: int) -> None: ... - def itemsChanged(self, startIndex: int, count: int) -> None: ... - def itemsAdded(self, startIndex: int, count: int) -> None: ... - def arrayReset(self) -> None: ... + seriesChanged: typing.ClassVar[QtCore.pyqtSignal] + itemCountChanged: typing.ClassVar[QtCore.pyqtSignal] + itemsInserted: typing.ClassVar[QtCore.pyqtSignal] + itemsRemoved: typing.ClassVar[QtCore.pyqtSignal] + itemsChanged: typing.ClassVar[QtCore.pyqtSignal] + itemsAdded: typing.ClassVar[QtCore.pyqtSignal] + arrayReset: typing.ClassVar[QtCore.pyqtSignal] def series(self) -> 'QScatter3DSeries': ... def removeItems(self, index: int, removeCount: int) -> None: ... def insertItems(self, index: int, items: typing.Iterable['QScatterDataItem']) -> None: ... @@ -1192,14 +1214,14 @@ class QItemModelScatterDataProxy('QScatterDataProxy'): @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def zPosRoleReplaceChanged(self, replace: str) -> None: ... - def yPosRoleReplaceChanged(self, replace: str) -> None: ... - def xPosRoleReplaceChanged(self, replace: str) -> None: ... - def rotationRoleReplaceChanged(self, replace: str) -> None: ... - def rotationRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def zPosRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def yPosRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def xPosRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... + zPosRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + yPosRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + xPosRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + rotationRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + zPosRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + yPosRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + xPosRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] def rotationRoleReplace(self) -> str: ... def setRotationRoleReplace(self, replace: str) -> None: ... def zPosRoleReplace(self) -> str: ... @@ -1216,11 +1238,11 @@ class QItemModelScatterDataProxy('QScatterDataProxy'): def setYPosRolePattern(self, pattern: QtCore.QRegExp) -> None: ... def xPosRolePattern(self) -> QtCore.QRegExp: ... def setXPosRolePattern(self, pattern: QtCore.QRegExp) -> None: ... - def rotationRoleChanged(self, role: str) -> None: ... - def zPosRoleChanged(self, role: str) -> None: ... - def yPosRoleChanged(self, role: str) -> None: ... - def xPosRoleChanged(self, role: str) -> None: ... - def itemModelChanged(self, itemModel: QtCore.QAbstractItemModel) -> None: ... + rotationRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + zPosRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + yPosRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + xPosRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + itemModelChanged: typing.ClassVar[QtCore.pyqtSignal] def remap(self, xPosRole: str, yPosRole: str, zPosRole: str, rotationRole: str) -> None: ... def rotationRole(self) -> str: ... def setRotationRole(self, role: str) -> None: ... @@ -1261,17 +1283,17 @@ class QItemModelSurfaceDataProxy('QSurfaceDataProxy'): @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def multiMatchBehaviorChanged(self, behavior: 'QItemModelSurfaceDataProxy.MultiMatchBehavior') -> None: ... - def zPosRoleReplaceChanged(self, replace: str) -> None: ... - def yPosRoleReplaceChanged(self, replace: str) -> None: ... - def xPosRoleReplaceChanged(self, replace: str) -> None: ... - def columnRoleReplaceChanged(self, replace: str) -> None: ... - def rowRoleReplaceChanged(self, replace: str) -> None: ... - def zPosRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def yPosRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def xPosRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def columnRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... - def rowRolePatternChanged(self, pattern: QtCore.QRegExp) -> None: ... + multiMatchBehaviorChanged: typing.ClassVar[QtCore.pyqtSignal] + zPosRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + yPosRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + xPosRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + columnRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + rowRoleReplaceChanged: typing.ClassVar[QtCore.pyqtSignal] + zPosRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + yPosRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + xPosRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + columnRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] + rowRolePatternChanged: typing.ClassVar[QtCore.pyqtSignal] def multiMatchBehavior(self) -> 'QItemModelSurfaceDataProxy.MultiMatchBehavior': ... def setMultiMatchBehavior(self, behavior: 'QItemModelSurfaceDataProxy.MultiMatchBehavior') -> None: ... def zPosRoleReplace(self) -> str: ... @@ -1294,17 +1316,17 @@ class QItemModelSurfaceDataProxy('QSurfaceDataProxy'): def setColumnRolePattern(self, pattern: QtCore.QRegExp) -> None: ... def rowRolePattern(self) -> QtCore.QRegExp: ... def setRowRolePattern(self, pattern: QtCore.QRegExp) -> None: ... - def autoColumnCategoriesChanged(self, enable: bool) -> None: ... - def autoRowCategoriesChanged(self, enable: bool) -> None: ... - def useModelCategoriesChanged(self, enable: bool) -> None: ... - def columnCategoriesChanged(self) -> None: ... - def rowCategoriesChanged(self) -> None: ... - def zPosRoleChanged(self, role: str) -> None: ... - def yPosRoleChanged(self, role: str) -> None: ... - def xPosRoleChanged(self, role: str) -> None: ... - def columnRoleChanged(self, role: str) -> None: ... - def rowRoleChanged(self, role: str) -> None: ... - def itemModelChanged(self, itemModel: QtCore.QAbstractItemModel) -> None: ... + autoColumnCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + autoRowCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + useModelCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + columnCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + rowCategoriesChanged: typing.ClassVar[QtCore.pyqtSignal] + zPosRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + yPosRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + xPosRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + columnRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + rowRoleChanged: typing.ClassVar[QtCore.pyqtSignal] + itemModelChanged: typing.ClassVar[QtCore.pyqtSignal] def remap(self, rowRole: str, columnRole: str, xPosRole: str, yPosRole: str, zPosRole: str, rowCategories: typing.Iterable[str], columnCategories: typing.Iterable[str]) -> None: ... def zPosRole(self) -> str: ... def setZPosRole(self, role: str) -> None: ... @@ -1363,9 +1385,9 @@ class QLogValue3DAxisFormatter('QValue3DAxisFormatter'): def positionAt(self, value: float) -> float: ... def recalculate(self) -> None: ... def createNewInstance(self) -> 'QValue3DAxisFormatter': ... - def showEdgeLabelsChanged(self, enabled: bool) -> None: ... - def autoSubGridChanged(self, enabled: bool) -> None: ... - def baseChanged(self, base: float) -> None: ... + showEdgeLabelsChanged: typing.ClassVar[QtCore.pyqtSignal] + autoSubGridChanged: typing.ClassVar[QtCore.pyqtSignal] + baseChanged: typing.ClassVar[QtCore.pyqtSignal] def showEdgeLabels(self) -> bool: ... def setShowEdgeLabels(self, enabled: bool) -> None: ... def autoSubGrid(self) -> bool: ... @@ -1380,9 +1402,9 @@ class QScatter3DSeries('QAbstract3DSeries'): @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def itemSizeChanged(self, size: float) -> None: ... - def selectedItemChanged(self, index: int) -> None: ... - def dataProxyChanged(self, proxy: 'QScatterDataProxy') -> None: ... + itemSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + selectedItemChanged: typing.ClassVar[QtCore.pyqtSignal] + dataProxyChanged: typing.ClassVar[QtCore.pyqtSignal] def itemSize(self) -> float: ... def setItemSize(self, size: float) -> None: ... @staticmethod @@ -1433,29 +1455,37 @@ class QSurface3DSeries('QAbstract3DSeries'): def __init__(self, f: typing.Union['QSurface3DSeries.DrawFlags', 'QSurface3DSeries.DrawFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QSurface3DSeries.DrawFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSurface3DSeries.DrawFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSurface3DSeries.DrawFlags', 'QSurface3DSeries.DrawFlag', int]) -> 'QSurface3DSeries.DrawFlags': ... + def __and__(self, other: typing.Union['QSurface3DSeries.DrawFlags', 'QSurface3DSeries.DrawFlag', int]) -> 'QSurface3DSeries.DrawFlags': ... + def __xor__(self, other: typing.Union['QSurface3DSeries.DrawFlags', 'QSurface3DSeries.DrawFlag', int]) -> 'QSurface3DSeries.DrawFlags': ... + def __ror__ (self, other: 'QSurface3DSeries.DrawFlag') -> 'QSurface3DSeries.DrawFlags': ... + def __rand__(self, other: 'QSurface3DSeries.DrawFlag') -> 'QSurface3DSeries.DrawFlags': ... + def __rxor__(self, other: 'QSurface3DSeries.DrawFlag') -> 'QSurface3DSeries.DrawFlags': ... @typing.overload def __init__(self, dataProxy: 'QSurfaceDataProxy', parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def textureFileChanged(self, filename: str) -> None: ... - def textureChanged(self, image: QtGui.QImage) -> None: ... + textureFileChanged: typing.ClassVar[QtCore.pyqtSignal] + textureChanged: typing.ClassVar[QtCore.pyqtSignal] def textureFile(self) -> str: ... def setTextureFile(self, filename: str) -> None: ... def texture(self) -> QtGui.QImage: ... def setTexture(self, texture: QtGui.QImage) -> None: ... - def drawModeChanged(self, mode: typing.Union['QSurface3DSeries.DrawFlags', 'QSurface3DSeries.DrawFlag']) -> None: ... - def flatShadingSupportedChanged(self, enable: bool) -> None: ... - def flatShadingEnabledChanged(self, enable: bool) -> None: ... - def selectedPointChanged(self, position: QtCore.QPoint) -> None: ... - def dataProxyChanged(self, proxy: 'QSurfaceDataProxy') -> None: ... + drawModeChanged: typing.ClassVar[QtCore.pyqtSignal] + flatShadingSupportedChanged: typing.ClassVar[QtCore.pyqtSignal] + flatShadingEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + selectedPointChanged: typing.ClassVar[QtCore.pyqtSignal] + dataProxyChanged: typing.ClassVar[QtCore.pyqtSignal] def isFlatShadingSupported(self) -> bool: ... def drawMode(self) -> 'QSurface3DSeries.DrawFlags': ... def setDrawMode(self, mode: typing.Union['QSurface3DSeries.DrawFlags', 'QSurface3DSeries.DrawFlag']) -> None: ... @@ -1496,15 +1526,15 @@ class QValue3DAxis('QAbstract3DAxis'): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def reversedChanged(self, enable: bool) -> None: ... - def formatterChanged(self, formatter: 'QValue3DAxisFormatter') -> None: ... + reversedChanged: typing.ClassVar[QtCore.pyqtSignal] + formatterChanged: typing.ClassVar[QtCore.pyqtSignal] def reversed(self) -> bool: ... def setReversed(self, enable: bool) -> None: ... def formatter(self) -> 'QValue3DAxisFormatter': ... def setFormatter(self, formatter: 'QValue3DAxisFormatter') -> None: ... - def labelFormatChanged(self, format: str) -> None: ... - def subSegmentCountChanged(self, count: int) -> None: ... - def segmentCountChanged(self, count: int) -> None: ... + labelFormatChanged: typing.ClassVar[QtCore.pyqtSignal] + subSegmentCountChanged: typing.ClassVar[QtCore.pyqtSignal] + segmentCountChanged: typing.ClassVar[QtCore.pyqtSignal] def labelFormat(self) -> str: ... def setLabelFormat(self, format: str) -> None: ... def subSegmentCount(self) -> int: ... diff --git a/PyQt5-stubs/QtDesigner.pyi b/PyQt5-stubs/QtDesigner.pyi index 8bd1874d..8993a7c4 100644 --- a/PyQt5-stubs/QtDesigner.pyi +++ b/PyQt5-stubs/QtDesigner.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtDesigner module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -99,12 +99,20 @@ class QDesignerFormWindowInterface(QtWidgets.QWidget): def __init__(self, f: typing.Union['QDesignerFormWindowInterface.Feature', 'QDesignerFormWindowInterface.FeatureFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QDesignerFormWindowInterface.Feature') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDesignerFormWindowInterface.Feature': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDesignerFormWindowInterface.Feature', 'QDesignerFormWindowInterface.FeatureFlag', int]) -> 'QDesignerFormWindowInterface.Feature': ... + def __and__(self, other: typing.Union['QDesignerFormWindowInterface.Feature', 'QDesignerFormWindowInterface.FeatureFlag', int]) -> 'QDesignerFormWindowInterface.Feature': ... + def __xor__(self, other: typing.Union['QDesignerFormWindowInterface.Feature', 'QDesignerFormWindowInterface.FeatureFlag', int]) -> 'QDesignerFormWindowInterface.Feature': ... + def __ror__ (self, other: 'QDesignerFormWindowInterface.FeatureFlag') -> 'QDesignerFormWindowInterface.Feature': ... + def __rand__(self, other: 'QDesignerFormWindowInterface.FeatureFlag') -> 'QDesignerFormWindowInterface.Feature': ... + def __rxor__(self, other: 'QDesignerFormWindowInterface.FeatureFlag') -> 'QDesignerFormWindowInterface.Feature': ... def __init__(self, parent: typing.Optional[QtWidgets.QWidget] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> None: ... @@ -112,19 +120,19 @@ class QDesignerFormWindowInterface(QtWidgets.QWidget): def formContainer(self) -> QtWidgets.QWidget: ... def activeResourceFilePaths(self) -> typing.List[str]: ... def checkContents(self) -> typing.List[str]: ... - def objectRemoved(self, o: QtCore.QObject) -> None: ... - def widgetRemoved(self, w: QtWidgets.QWidget) -> None: ... - def changed(self) -> None: ... - def activated(self, widget: QtWidgets.QWidget) -> None: ... - def aboutToUnmanageWidget(self, widget: QtWidgets.QWidget) -> None: ... - def widgetUnmanaged(self, widget: QtWidgets.QWidget) -> None: ... - def widgetManaged(self, widget: QtWidgets.QWidget) -> None: ... - def resourceFilesChanged(self) -> None: ... - def geometryChanged(self) -> None: ... - def selectionChanged(self) -> None: ... - def featureChanged(self, f: typing.Union['QDesignerFormWindowInterface.Feature', 'QDesignerFormWindowInterface.FeatureFlag']) -> None: ... - def fileNameChanged(self, fileName: str) -> None: ... - def mainContainerChanged(self, mainContainer: QtWidgets.QWidget) -> None: ... + objectRemoved: typing.ClassVar[QtCore.pyqtSignal] + widgetRemoved: typing.ClassVar[QtCore.pyqtSignal] + changed: typing.ClassVar[QtCore.pyqtSignal] + activated: typing.ClassVar[QtCore.pyqtSignal] + aboutToUnmanageWidget: typing.ClassVar[QtCore.pyqtSignal] + widgetUnmanaged: typing.ClassVar[QtCore.pyqtSignal] + widgetManaged: typing.ClassVar[QtCore.pyqtSignal] + resourceFilesChanged: typing.ClassVar[QtCore.pyqtSignal] + geometryChanged: typing.ClassVar[QtCore.pyqtSignal] + selectionChanged: typing.ClassVar[QtCore.pyqtSignal] + featureChanged: typing.ClassVar[QtCore.pyqtSignal] + fileNameChanged: typing.ClassVar[QtCore.pyqtSignal] + mainContainerChanged: typing.ClassVar[QtCore.pyqtSignal] def setFileName(self, fileName: str) -> None: ... def setGrid(self, grid: QtCore.QPoint) -> None: ... def selectWidget(self, widget: QtWidgets.QWidget, select: bool = ...) -> None: ... @@ -286,10 +294,10 @@ class QDesignerFormWindowManagerInterface(QtCore.QObject): def setActiveFormWindow(self, formWindow: QDesignerFormWindowInterface) -> None: ... def removeFormWindow(self, formWindow: QDesignerFormWindowInterface) -> None: ... def addFormWindow(self, formWindow: QDesignerFormWindowInterface) -> None: ... - def formWindowSettingsChanged(self, fw: QDesignerFormWindowInterface) -> None: ... - def activeFormWindowChanged(self, formWindow: QDesignerFormWindowInterface) -> None: ... - def formWindowRemoved(self, formWindow: QDesignerFormWindowInterface) -> None: ... - def formWindowAdded(self, formWindow: QDesignerFormWindowInterface) -> None: ... + formWindowSettingsChanged: typing.ClassVar[QtCore.pyqtSignal] + activeFormWindowChanged: typing.ClassVar[QtCore.pyqtSignal] + formWindowRemoved: typing.ClassVar[QtCore.pyqtSignal] + formWindowAdded: typing.ClassVar[QtCore.pyqtSignal] def core(self) -> QDesignerFormEditorInterface: ... def createFormWindow(self, parent: typing.Optional[QtWidgets.QWidget] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> QDesignerFormWindowInterface: ... def formWindow(self, index: int) -> QDesignerFormWindowInterface: ... @@ -314,7 +322,7 @@ class QDesignerPropertyEditorInterface(QtWidgets.QWidget): def setReadOnly(self, readOnly: bool) -> None: ... def setPropertyValue(self, name: str, value: typing.Any, changed: bool = ...) -> None: ... def setObject(self, object: QtCore.QObject) -> None: ... - def propertyChanged(self, name: str, value: typing.Any) -> None: ... + propertyChanged: typing.ClassVar[QtCore.pyqtSignal] def currentPropertyName(self) -> str: ... def object(self) -> QtCore.QObject: ... def isReadOnly(self) -> bool: ... diff --git a/PyQt5-stubs/QtGui.pyi b/PyQt5-stubs/QtGui.pyi index 2dddd700..1332a703 100644 --- a/PyQt5-stubs/QtGui.pyi +++ b/PyQt5-stubs/QtGui.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtGui module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -80,10 +80,10 @@ class QAbstractTextDocumentLayout(QtCore.QObject): def positionInlineObject(self, item: 'QTextInlineObject', posInDocument: int, format: 'QTextFormat') -> None: ... def resizeInlineObject(self, item: 'QTextInlineObject', posInDocument: int, format: 'QTextFormat') -> None: ... def documentChanged(self, from_: int, charsRemoved: int, charsAdded: int) -> None: ... - def updateBlock(self, block: 'QTextBlock') -> None: ... - def pageCountChanged(self, newPages: int) -> None: ... - def documentSizeChanged(self, newSize: QtCore.QSizeF) -> None: ... - def update(self, rect: QtCore.QRectF = ...) -> None: ... + updateBlock: typing.ClassVar[QtCore.pyqtSignal] + pageCountChanged: typing.ClassVar[QtCore.pyqtSignal] + documentSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + update: typing.ClassVar[QtCore.pyqtSignal] def handlerForObject(self, objectType: int) -> 'QTextObjectInterface': ... def unregisterHandler(self, objectType: int, component: typing.Optional[QtCore.QObject] = ...) -> None: ... def registerHandler(self, objectType: int, component: QtCore.QObject) -> None: ... @@ -1291,8 +1291,8 @@ class QDrag(QtCore.QObject): def defaultAction(self) -> QtCore.Qt.DropAction: ... def supportedActions(self) -> QtCore.Qt.DropActions: ... def dragCursor(self, action: QtCore.Qt.DropAction) -> QPixmap: ... - def targetChanged(self, newTarget: QtCore.QObject) -> None: ... - def actionChanged(self, action: QtCore.Qt.DropAction) -> None: ... + targetChanged: typing.ClassVar[QtCore.pyqtSignal] + actionChanged: typing.ClassVar[QtCore.pyqtSignal] def setDragCursor(self, cursor: QPixmap, action: QtCore.Qt.DropAction) -> None: ... def target(self) -> QtCore.QObject: ... def source(self) -> QtCore.QObject: ... @@ -1768,6 +1768,9 @@ class QTouchEvent(QInputEvent): class TouchPoint(sip.simplewrapper): class InfoFlag(int): + def __or__ (self, other: typing.Union[int, 'QTouchEvent.TouchPoint.InfoFlag']) -> 'QTouchEvent.TouchPoint.InfoFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTouchEvent.TouchPoint.InfoFlags': ... # type: ignore[override, misc] + Pen = ... # type: QTouchEvent.TouchPoint.InfoFlag Token = ... # type: QTouchEvent.TouchPoint.InfoFlag @@ -1782,12 +1785,20 @@ class QTouchEvent(QInputEvent): def __init__(self, f: typing.Union['QTouchEvent.TouchPoint.InfoFlags', 'QTouchEvent.TouchPoint.InfoFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QTouchEvent.TouchPoint.InfoFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTouchEvent.TouchPoint.InfoFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTouchEvent.TouchPoint.InfoFlags', 'QTouchEvent.TouchPoint.InfoFlag', int]) -> 'QTouchEvent.TouchPoint.InfoFlags': ... + def __and__(self, other: typing.Union['QTouchEvent.TouchPoint.InfoFlags', 'QTouchEvent.TouchPoint.InfoFlag', int]) -> 'QTouchEvent.TouchPoint.InfoFlags': ... + def __xor__(self, other: typing.Union['QTouchEvent.TouchPoint.InfoFlags', 'QTouchEvent.TouchPoint.InfoFlag', int]) -> 'QTouchEvent.TouchPoint.InfoFlags': ... + def __ror__ (self, other: 'QTouchEvent.TouchPoint.InfoFlag') -> 'QTouchEvent.TouchPoint.InfoFlags': ... + def __rand__(self, other: 'QTouchEvent.TouchPoint.InfoFlag') -> 'QTouchEvent.TouchPoint.InfoFlags': ... + def __rxor__(self, other: 'QTouchEvent.TouchPoint.InfoFlag') -> 'QTouchEvent.TouchPoint.InfoFlags': ... def ellipseDiameters(self) -> QtCore.QSizeF: ... def rotation(self) -> float: ... @@ -2609,12 +2620,20 @@ class QGlyphRun(sip.simplewrapper): def __init__(self, f: typing.Union['QGlyphRun.GlyphRunFlags', 'QGlyphRun.GlyphRunFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QGlyphRun.GlyphRunFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGlyphRun.GlyphRunFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGlyphRun.GlyphRunFlags', 'QGlyphRun.GlyphRunFlag', int]) -> 'QGlyphRun.GlyphRunFlags': ... + def __and__(self, other: typing.Union['QGlyphRun.GlyphRunFlags', 'QGlyphRun.GlyphRunFlag', int]) -> 'QGlyphRun.GlyphRunFlags': ... + def __xor__(self, other: typing.Union['QGlyphRun.GlyphRunFlags', 'QGlyphRun.GlyphRunFlag', int]) -> 'QGlyphRun.GlyphRunFlags': ... + def __ror__ (self, other: 'QGlyphRun.GlyphRunFlag') -> 'QGlyphRun.GlyphRunFlags': ... + def __rand__(self, other: 'QGlyphRun.GlyphRunFlag') -> 'QGlyphRun.GlyphRunFlags': ... + def __rxor__(self, other: 'QGlyphRun.GlyphRunFlag') -> 'QGlyphRun.GlyphRunFlags': ... @typing.overload def __init__(self) -> None: ... @@ -2653,21 +2672,21 @@ class QGuiApplication(QtCore.QCoreApplication): def highDpiScaleFactorRoundingPolicy() -> QtCore.Qt.HighDpiScaleFactorRoundingPolicy: ... @staticmethod def setHighDpiScaleFactorRoundingPolicy(policy: QtCore.Qt.HighDpiScaleFactorRoundingPolicy) -> None: ... - def fontChanged(self, font: QFont) -> None: ... + fontChanged: typing.ClassVar[QtCore.pyqtSignal] @staticmethod def screenAt(point: QtCore.QPoint) -> 'QScreen': ... @staticmethod def desktopFileName() -> str: ... @staticmethod def setDesktopFileName(name: str) -> None: ... - def primaryScreenChanged(self, screen: 'QScreen') -> None: ... + primaryScreenChanged: typing.ClassVar[QtCore.pyqtSignal] @staticmethod def setFallbackSessionManagementEnabled(a0: bool) -> None: ... @staticmethod def isFallbackSessionManagementEnabled() -> bool: ... - def paletteChanged(self, pal: 'QPalette') -> None: ... - def layoutDirectionChanged(self, direction: QtCore.Qt.LayoutDirection) -> None: ... - def screenRemoved(self, screen: 'QScreen') -> None: ... + paletteChanged: typing.ClassVar[QtCore.pyqtSignal] + layoutDirectionChanged: typing.ClassVar[QtCore.pyqtSignal] + screenRemoved: typing.ClassVar[QtCore.pyqtSignal] def event(self, a0: QtCore.QEvent) -> bool: ... @staticmethod def windowIcon() -> 'QIcon': ... @@ -2692,15 +2711,15 @@ class QGuiApplication(QtCore.QCoreApplication): def applicationDisplayName() -> str: ... @staticmethod def setApplicationDisplayName(name: str) -> None: ... - def applicationDisplayNameChanged(self) -> None: ... - def applicationStateChanged(self, state: QtCore.Qt.ApplicationState) -> None: ... - def focusWindowChanged(self, focusWindow: 'QWindow') -> None: ... - def saveStateRequest(self, sessionManager: 'QSessionManager') -> None: ... - def commitDataRequest(self, sessionManager: 'QSessionManager') -> None: ... - def focusObjectChanged(self, focusObject: QtCore.QObject) -> None: ... + applicationDisplayNameChanged: typing.ClassVar[QtCore.pyqtSignal] + applicationStateChanged: typing.ClassVar[QtCore.pyqtSignal] + focusWindowChanged: typing.ClassVar[QtCore.pyqtSignal] + saveStateRequest: typing.ClassVar[QtCore.pyqtSignal] + commitDataRequest: typing.ClassVar[QtCore.pyqtSignal] + focusObjectChanged: typing.ClassVar[QtCore.pyqtSignal] lastWindowClosed: typing.ClassVar[QtCore.pyqtSignal] - def screenAdded(self, screen: 'QScreen') -> None: ... - def fontDatabaseChanged(self) -> None: ... + screenAdded: typing.ClassVar[QtCore.pyqtSignal] + fontDatabaseChanged: typing.ClassVar[QtCore.pyqtSignal] def notify(self, a0: QtCore.QObject, a1: QtCore.QEvent) -> bool: ... @staticmethod def exec() -> int: ... @@ -3200,12 +3219,20 @@ class QImageIOHandler(sip.simplewrapper): def __init__(self, f: typing.Union['QImageIOHandler.Transformations', 'QImageIOHandler.Transformation']) -> None: ... @typing.overload def __init__(self, a0: 'QImageIOHandler.Transformations') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QImageIOHandler.Transformations': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QImageIOHandler.Transformations', 'QImageIOHandler.Transformation', int]) -> 'QImageIOHandler.Transformations': ... + def __and__(self, other: typing.Union['QImageIOHandler.Transformations', 'QImageIOHandler.Transformation', int]) -> 'QImageIOHandler.Transformations': ... + def __xor__(self, other: typing.Union['QImageIOHandler.Transformations', 'QImageIOHandler.Transformation', int]) -> 'QImageIOHandler.Transformations': ... + def __ror__ (self, other: 'QImageIOHandler.Transformation') -> 'QImageIOHandler.Transformations': ... + def __rand__(self, other: 'QImageIOHandler.Transformation') -> 'QImageIOHandler.Transformations': ... + def __rxor__(self, other: 'QImageIOHandler.Transformation') -> 'QImageIOHandler.Transformations': ... def __init__(self) -> None: ... @@ -3376,16 +3403,16 @@ class QInputMethod(QtCore.QObject): Click = ... # type: QInputMethod.Action ContextMenu = ... # type: QInputMethod.Action - def inputItemClipRectangleChanged(self) -> None: ... - def anchorRectangleChanged(self) -> None: ... + inputItemClipRectangleChanged: typing.ClassVar[QtCore.pyqtSignal] + anchorRectangleChanged: typing.ClassVar[QtCore.pyqtSignal] def inputItemClipRectangle(self) -> QtCore.QRectF: ... def anchorRectangle(self) -> QtCore.QRectF: ... - def inputDirectionChanged(self, newDirection: QtCore.Qt.LayoutDirection) -> None: ... - def localeChanged(self) -> None: ... - def animatingChanged(self) -> None: ... - def visibleChanged(self) -> None: ... - def keyboardRectangleChanged(self) -> None: ... - def cursorRectangleChanged(self) -> None: ... + inputDirectionChanged: typing.ClassVar[QtCore.pyqtSignal] + localeChanged: typing.ClassVar[QtCore.pyqtSignal] + animatingChanged: typing.ClassVar[QtCore.pyqtSignal] + visibleChanged: typing.ClassVar[QtCore.pyqtSignal] + keyboardRectangleChanged: typing.ClassVar[QtCore.pyqtSignal] + cursorRectangleChanged: typing.ClassVar[QtCore.pyqtSignal] def invokeAction(self, a: 'QInputMethod.Action', cursorPosition: int) -> None: ... def commit(self) -> None: ... def reset(self) -> None: ... @@ -3717,13 +3744,13 @@ class QMovie(QtCore.QObject): def setPaused(self, paused: bool) -> None: ... def jumpToNextFrame(self) -> bool: ... def start(self) -> None: ... - def frameChanged(self, frameNumber: int) -> None: ... - def finished(self) -> None: ... - def error(self, error: QImageReader.ImageReaderError) -> None: ... - def stateChanged(self, state: 'QMovie.MovieState') -> None: ... - def updated(self, rect: QtCore.QRect) -> None: ... - def resized(self, size: QtCore.QSize) -> None: ... - def started(self) -> None: ... + frameChanged: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + updated: typing.ClassVar[QtCore.pyqtSignal] + resized: typing.ClassVar[QtCore.pyqtSignal] + started: typing.ClassVar[QtCore.pyqtSignal] def setCacheMode(self, mode: 'QMovie.CacheMode') -> None: ... def cacheMode(self) -> 'QMovie.CacheMode': ... def setScaledSize(self, size: QtCore.QSize) -> None: ... @@ -3797,7 +3824,7 @@ class QOffscreenSurface(QtCore.QObject, QSurface): def setNativeHandle(self, handle: sip.voidptr) -> None: ... def nativeHandle(self) -> sip.voidptr: ... - def screenChanged(self, screen: 'QScreen') -> None: ... + screenChanged: typing.ClassVar[QtCore.pyqtSignal] def setScreen(self, screen: 'QScreen') -> None: ... def screen(self) -> 'QScreen': ... def size(self) -> QtCore.QSize: ... @@ -3813,6 +3840,9 @@ class QOffscreenSurface(QtCore.QObject, QSurface): class QOpenGLBuffer(sip.simplewrapper): class RangeAccessFlag(int): + def __or__ (self, other: 'QOpenGLBuffer.RangeAccessFlag') -> 'QOpenGLBuffer.RangeAccessFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QOpenGLBuffer.RangeAccessFlags': ... # type: ignore[override, misc] + RangeRead = ... # type: QOpenGLBuffer.RangeAccessFlag RangeWrite = ... # type: QOpenGLBuffer.RangeAccessFlag RangeInvalidate = ... # type: QOpenGLBuffer.RangeAccessFlag @@ -3876,12 +3906,20 @@ class QOpenGLBuffer(sip.simplewrapper): def __init__(self, f: typing.Union['QOpenGLBuffer.RangeAccessFlags', 'QOpenGLBuffer.RangeAccessFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QOpenGLBuffer.RangeAccessFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QOpenGLBuffer.RangeAccessFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QOpenGLBuffer.RangeAccessFlags', 'QOpenGLBuffer.RangeAccessFlag', int]) -> 'QOpenGLBuffer.RangeAccessFlags': ... + def __and__(self, other: typing.Union['QOpenGLBuffer.RangeAccessFlags', 'QOpenGLBuffer.RangeAccessFlag', int]) -> 'QOpenGLBuffer.RangeAccessFlags': ... + def __xor__(self, other: typing.Union['QOpenGLBuffer.RangeAccessFlags', 'QOpenGLBuffer.RangeAccessFlag', int]) -> 'QOpenGLBuffer.RangeAccessFlags': ... + def __ror__ (self, other: 'QOpenGLBuffer.RangeAccessFlag') -> 'QOpenGLBuffer.RangeAccessFlags': ... + def __rand__(self, other: 'QOpenGLBuffer.RangeAccessFlag') -> 'QOpenGLBuffer.RangeAccessFlags': ... + def __rxor__(self, other: 'QOpenGLBuffer.RangeAccessFlag') -> 'QOpenGLBuffer.RangeAccessFlags': ... @typing.overload def __init__(self) -> None: ... @@ -3946,7 +3984,7 @@ class QOpenGLContext(QtCore.QObject): @staticmethod def openGLModuleHandle() -> sip.voidptr: ... def versionFunctions(self, versionProfile: typing.Optional['QOpenGLVersionProfile'] = ...) -> typing.Any: ... - def aboutToBeDestroyed(self) -> None: ... + aboutToBeDestroyed: typing.ClassVar[QtCore.pyqtSignal] def hasExtension(self, extension: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> bool: ... def extensions(self) -> typing.Set[QtCore.QByteArray]: ... @staticmethod @@ -3991,6 +4029,9 @@ class QOpenGLVersionProfile(sip.simplewrapper): class QOpenGLDebugMessage(sip.simplewrapper): class Severity(int): + def __or__ (self, other: 'QOpenGLDebugMessage.Severity') -> 'QOpenGLDebugMessage.Severities': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QOpenGLDebugMessage.Severities': ... # type: ignore[override, misc] + InvalidSeverity = ... # type: QOpenGLDebugMessage.Severity HighSeverity = ... # type: QOpenGLDebugMessage.Severity MediumSeverity = ... # type: QOpenGLDebugMessage.Severity @@ -4006,6 +4047,9 @@ class QOpenGLDebugMessage(sip.simplewrapper): AnySeverity = ... # type: QOpenGLDebugMessage.Severity class Type(int): + def __or__ (self, other: 'QOpenGLDebugMessage.Type') -> 'QOpenGLDebugMessage.Types': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QOpenGLDebugMessage.Types': ... # type: ignore[override, misc] + InvalidType = ... # type: QOpenGLDebugMessage.Type ErrorType = ... # type: QOpenGLDebugMessage.Type DeprecatedBehaviorType = ... # type: QOpenGLDebugMessage.Type @@ -4031,6 +4075,9 @@ class QOpenGLDebugMessage(sip.simplewrapper): AnyType = ... # type: QOpenGLDebugMessage.Type class Source(int): + def __or__ (self, other: 'QOpenGLDebugMessage.Source') -> 'QOpenGLDebugMessage.Sources': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QOpenGLDebugMessage.Sources': ... # type: ignore[override, misc] + InvalidSource = ... # type: QOpenGLDebugMessage.Source APISource = ... # type: QOpenGLDebugMessage.Source WindowSystemSource = ... # type: QOpenGLDebugMessage.Source @@ -4057,12 +4104,20 @@ class QOpenGLDebugMessage(sip.simplewrapper): def __init__(self, f: typing.Union['QOpenGLDebugMessage.Sources', 'QOpenGLDebugMessage.Source']) -> None: ... @typing.overload def __init__(self, a0: 'QOpenGLDebugMessage.Sources') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QOpenGLDebugMessage.Sources': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QOpenGLDebugMessage.Sources', 'QOpenGLDebugMessage.Source', int]) -> 'QOpenGLDebugMessage.Sources': ... + def __and__(self, other: typing.Union['QOpenGLDebugMessage.Sources', 'QOpenGLDebugMessage.Source', int]) -> 'QOpenGLDebugMessage.Sources': ... + def __xor__(self, other: typing.Union['QOpenGLDebugMessage.Sources', 'QOpenGLDebugMessage.Source', int]) -> 'QOpenGLDebugMessage.Sources': ... + def __ror__ (self, other: 'QOpenGLDebugMessage.Source') -> 'QOpenGLDebugMessage.Sources': ... + def __rand__(self, other: 'QOpenGLDebugMessage.Source') -> 'QOpenGLDebugMessage.Sources': ... + def __rxor__(self, other: 'QOpenGLDebugMessage.Source') -> 'QOpenGLDebugMessage.Sources': ... class Types(sip.simplewrapper): @@ -4072,12 +4127,20 @@ class QOpenGLDebugMessage(sip.simplewrapper): def __init__(self, f: typing.Union['QOpenGLDebugMessage.Types', 'QOpenGLDebugMessage.Type']) -> None: ... @typing.overload def __init__(self, a0: 'QOpenGLDebugMessage.Types') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QOpenGLDebugMessage.Types': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QOpenGLDebugMessage.Types', 'QOpenGLDebugMessage.Type', int]) -> 'QOpenGLDebugMessage.Types': ... + def __and__(self, other: typing.Union['QOpenGLDebugMessage.Types', 'QOpenGLDebugMessage.Type', int]) -> 'QOpenGLDebugMessage.Types': ... + def __xor__(self, other: typing.Union['QOpenGLDebugMessage.Types', 'QOpenGLDebugMessage.Type', int]) -> 'QOpenGLDebugMessage.Types': ... + def __ror__ (self, other: 'QOpenGLDebugMessage.Type') -> 'QOpenGLDebugMessage.Types': ... + def __rand__(self, other: 'QOpenGLDebugMessage.Type') -> 'QOpenGLDebugMessage.Types': ... + def __rxor__(self, other: 'QOpenGLDebugMessage.Type') -> 'QOpenGLDebugMessage.Types': ... class Severities(sip.simplewrapper): @@ -4087,12 +4150,20 @@ class QOpenGLDebugMessage(sip.simplewrapper): def __init__(self, f: typing.Union['QOpenGLDebugMessage.Severities', 'QOpenGLDebugMessage.Severity']) -> None: ... @typing.overload def __init__(self, a0: 'QOpenGLDebugMessage.Severities') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QOpenGLDebugMessage.Severities': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QOpenGLDebugMessage.Severities', 'QOpenGLDebugMessage.Severity', int]) -> 'QOpenGLDebugMessage.Severities': ... + def __and__(self, other: typing.Union['QOpenGLDebugMessage.Severities', 'QOpenGLDebugMessage.Severity', int]) -> 'QOpenGLDebugMessage.Severities': ... + def __xor__(self, other: typing.Union['QOpenGLDebugMessage.Severities', 'QOpenGLDebugMessage.Severity', int]) -> 'QOpenGLDebugMessage.Severities': ... + def __ror__ (self, other: 'QOpenGLDebugMessage.Severity') -> 'QOpenGLDebugMessage.Severities': ... + def __rand__(self, other: 'QOpenGLDebugMessage.Severity') -> 'QOpenGLDebugMessage.Severities': ... + def __rxor__(self, other: 'QOpenGLDebugMessage.Severity') -> 'QOpenGLDebugMessage.Severities': ... @typing.overload def __init__(self) -> None: ... @@ -4122,7 +4193,7 @@ class QOpenGLDebugLogger(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def messageLogged(self, debugMessage: QOpenGLDebugMessage) -> None: ... + messageLogged: typing.ClassVar[QtCore.pyqtSignal] def stopLogging(self) -> None: ... def startLogging(self, loggingMode: 'QOpenGLDebugLogger.LoggingMode' = ...) -> None: ... def logMessage(self, debugMessage: QOpenGLDebugMessage) -> None: ... @@ -4296,6 +4367,9 @@ class QOpenGLPixelTransferOptions(sip.simplewrapper): class QOpenGLShader(QtCore.QObject): class ShaderTypeBit(int): + def __or__ (self, other: 'QOpenGLShader.ShaderTypeBit') -> 'QOpenGLShader.ShaderType': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QOpenGLShader.ShaderType': ... # type: ignore[override, misc] + Vertex = ... # type: QOpenGLShader.ShaderTypeBit Fragment = ... # type: QOpenGLShader.ShaderTypeBit Geometry = ... # type: QOpenGLShader.ShaderTypeBit @@ -4318,12 +4392,20 @@ class QOpenGLShader(QtCore.QObject): def __init__(self, f: typing.Union['QOpenGLShader.ShaderType', 'QOpenGLShader.ShaderTypeBit']) -> None: ... @typing.overload def __init__(self, a0: 'QOpenGLShader.ShaderType') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QOpenGLShader.ShaderType': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QOpenGLShader.ShaderType', 'QOpenGLShader.ShaderTypeBit', int]) -> 'QOpenGLShader.ShaderType': ... + def __and__(self, other: typing.Union['QOpenGLShader.ShaderType', 'QOpenGLShader.ShaderTypeBit', int]) -> 'QOpenGLShader.ShaderType': ... + def __xor__(self, other: typing.Union['QOpenGLShader.ShaderType', 'QOpenGLShader.ShaderTypeBit', int]) -> 'QOpenGLShader.ShaderType': ... + def __ror__ (self, other: 'QOpenGLShader.ShaderTypeBit') -> 'QOpenGLShader.ShaderType': ... + def __rand__(self, other: 'QOpenGLShader.ShaderTypeBit') -> 'QOpenGLShader.ShaderType': ... + def __rxor__(self, other: 'QOpenGLShader.ShaderTypeBit') -> 'QOpenGLShader.ShaderType': ... def __init__(self, type: typing.Union['QOpenGLShader.ShaderType', 'QOpenGLShader.ShaderTypeBit'], parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -4630,6 +4712,9 @@ class QOpenGLTexture(sip.simplewrapper): SwizzleAlpha = ... # type: QOpenGLTexture.SwizzleComponent class Feature(int): + def __or__ (self, other: 'QOpenGLTexture.Feature') -> 'QOpenGLTexture.Features': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QOpenGLTexture.Features': ... # type: ignore[override, misc] + ImmutableStorage = ... # type: QOpenGLTexture.Feature ImmutableMultisampleStorage = ... # type: QOpenGLTexture.Feature TextureRectangle = ... # type: QOpenGLTexture.Feature @@ -5102,12 +5187,20 @@ class QOpenGLTexture(sip.simplewrapper): def __init__(self, f: typing.Union['QOpenGLTexture.Features', 'QOpenGLTexture.Feature']) -> None: ... @typing.overload def __init__(self, a0: 'QOpenGLTexture.Features') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QOpenGLTexture.Features': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QOpenGLTexture.Features', 'QOpenGLTexture.Feature', int]) -> 'QOpenGLTexture.Features': ... + def __and__(self, other: typing.Union['QOpenGLTexture.Features', 'QOpenGLTexture.Feature', int]) -> 'QOpenGLTexture.Features': ... + def __xor__(self, other: typing.Union['QOpenGLTexture.Features', 'QOpenGLTexture.Feature', int]) -> 'QOpenGLTexture.Features': ... + def __ror__ (self, other: 'QOpenGLTexture.Feature') -> 'QOpenGLTexture.Features': ... + def __rand__(self, other: 'QOpenGLTexture.Feature') -> 'QOpenGLTexture.Features': ... + def __rxor__(self, other: 'QOpenGLTexture.Feature') -> 'QOpenGLTexture.Features': ... @typing.overload def __init__(self, target: 'QOpenGLTexture.Target') -> None: ... @@ -5548,7 +5641,7 @@ class QOpenGLWindow(QPaintDeviceWindow): def paintGL(self) -> None: ... def resizeGL(self, w: int, h: int) -> None: ... def initializeGL(self) -> None: ... - def frameSwapped(self) -> None: ... + frameSwapped: typing.ClassVar[QtCore.pyqtSignal] def shareContext(self) -> QOpenGLContext: ... def grabFramebuffer(self) -> QImage: ... def defaultFramebufferObject(self) -> int: ... @@ -6375,6 +6468,9 @@ class QPainter(sip.simplewrapper): RasterOp_NotDestination = ... # type: QPainter.CompositionMode class RenderHint(int): + def __or__ (self, other: 'QPainter.RenderHint') -> 'QPainter.RenderHints': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QPainter.RenderHints': ... # type: ignore[override, misc] + Antialiasing = ... # type: QPainter.RenderHint TextAntialiasing = ... # type: QPainter.RenderHint SmoothPixmapTransform = ... # type: QPainter.RenderHint @@ -6399,12 +6495,20 @@ class QPainter(sip.simplewrapper): def __init__(self, f: typing.Union['QPainter.RenderHints', 'QPainter.RenderHint']) -> None: ... @typing.overload def __init__(self, a0: 'QPainter.RenderHints') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QPainter.RenderHints': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QPainter.RenderHints', 'QPainter.RenderHint', int]) -> 'QPainter.RenderHints': ... + def __and__(self, other: typing.Union['QPainter.RenderHints', 'QPainter.RenderHint', int]) -> 'QPainter.RenderHints': ... + def __xor__(self, other: typing.Union['QPainter.RenderHints', 'QPainter.RenderHint', int]) -> 'QPainter.RenderHints': ... + def __ror__ (self, other: 'QPainter.RenderHint') -> 'QPainter.RenderHints': ... + def __rand__(self, other: 'QPainter.RenderHint') -> 'QPainter.RenderHints': ... + def __rxor__(self, other: 'QPainter.RenderHint') -> 'QPainter.RenderHints': ... class PixmapFragment(sip.simplewrapper): @@ -6435,12 +6539,20 @@ class QPainter(sip.simplewrapper): def __init__(self, f: typing.Union['QPainter.PixmapFragmentHints', 'QPainter.PixmapFragmentHint']) -> None: ... @typing.overload def __init__(self, a0: 'QPainter.PixmapFragmentHints') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QPainter.PixmapFragmentHints': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QPainter.PixmapFragmentHints', 'QPainter.PixmapFragmentHint', int]) -> 'QPainter.PixmapFragmentHints': ... + def __and__(self, other: typing.Union['QPainter.PixmapFragmentHints', 'QPainter.PixmapFragmentHint', int]) -> 'QPainter.PixmapFragmentHints': ... + def __xor__(self, other: typing.Union['QPainter.PixmapFragmentHints', 'QPainter.PixmapFragmentHint', int]) -> 'QPainter.PixmapFragmentHints': ... + def __ror__ (self, other: 'QPainter.PixmapFragmentHint') -> 'QPainter.PixmapFragmentHints': ... + def __rand__(self, other: 'QPainter.PixmapFragmentHint') -> 'QPainter.PixmapFragmentHints': ... + def __rxor__(self, other: 'QPainter.PixmapFragmentHint') -> 'QPainter.PixmapFragmentHints': ... @typing.overload def __init__(self) -> None: ... @@ -6776,6 +6888,9 @@ class QPainter(sip.simplewrapper): class QTextItem(sip.simplewrapper): class RenderFlag(int): + def __or__ (self, other: 'QTextItem.RenderFlag') -> 'QTextItem.RenderFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTextItem.RenderFlags': ... # type: ignore[override, misc] + RightToLeft = ... # type: QTextItem.RenderFlag Overline = ... # type: QTextItem.RenderFlag Underline = ... # type: QTextItem.RenderFlag @@ -6794,12 +6909,20 @@ class QTextItem(sip.simplewrapper): def __init__(self, f: typing.Union['QTextItem.RenderFlags', 'QTextItem.RenderFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QTextItem.RenderFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTextItem.RenderFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTextItem.RenderFlags', 'QTextItem.RenderFlag', int]) -> 'QTextItem.RenderFlags': ... + def __and__(self, other: typing.Union['QTextItem.RenderFlags', 'QTextItem.RenderFlag', int]) -> 'QTextItem.RenderFlags': ... + def __xor__(self, other: typing.Union['QTextItem.RenderFlags', 'QTextItem.RenderFlag', int]) -> 'QTextItem.RenderFlags': ... + def __ror__ (self, other: 'QTextItem.RenderFlag') -> 'QTextItem.RenderFlags': ... + def __rand__(self, other: 'QTextItem.RenderFlag') -> 'QTextItem.RenderFlags': ... + def __rxor__(self, other: 'QTextItem.RenderFlag') -> 'QTextItem.RenderFlags': ... @typing.overload def __init__(self) -> None: ... @@ -6902,6 +7025,9 @@ class QPaintEngine(sip.simplewrapper): AllDirty = ... # type: QPaintEngine.DirtyFlag class PaintEngineFeature(int): + def __or__ (self, other: 'QPaintEngine.PaintEngineFeature') -> 'QPaintEngine.PaintEngineFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QPaintEngine.PaintEngineFeatures': ... # type: ignore[override, misc] + PrimitiveTransform = ... # type: QPaintEngine.PaintEngineFeature PatternTransform = ... # type: QPaintEngine.PaintEngineFeature PixmapTransform = ... # type: QPaintEngine.PaintEngineFeature @@ -6952,12 +7078,20 @@ class QPaintEngine(sip.simplewrapper): def __init__(self, f: typing.Union['QPaintEngine.PaintEngineFeatures', 'QPaintEngine.PaintEngineFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QPaintEngine.PaintEngineFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QPaintEngine.PaintEngineFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QPaintEngine.PaintEngineFeatures', 'QPaintEngine.PaintEngineFeature', int]) -> 'QPaintEngine.PaintEngineFeatures': ... + def __and__(self, other: typing.Union['QPaintEngine.PaintEngineFeatures', 'QPaintEngine.PaintEngineFeature', int]) -> 'QPaintEngine.PaintEngineFeatures': ... + def __xor__(self, other: typing.Union['QPaintEngine.PaintEngineFeatures', 'QPaintEngine.PaintEngineFeature', int]) -> 'QPaintEngine.PaintEngineFeatures': ... + def __ror__ (self, other: 'QPaintEngine.PaintEngineFeature') -> 'QPaintEngine.PaintEngineFeatures': ... + def __rand__(self, other: 'QPaintEngine.PaintEngineFeature') -> 'QPaintEngine.PaintEngineFeatures': ... + def __rxor__(self, other: 'QPaintEngine.PaintEngineFeature') -> 'QPaintEngine.PaintEngineFeatures': ... class DirtyFlags(sip.simplewrapper): @@ -6967,12 +7101,20 @@ class QPaintEngine(sip.simplewrapper): def __init__(self, f: typing.Union['QPaintEngine.DirtyFlags', 'QPaintEngine.DirtyFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QPaintEngine.DirtyFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QPaintEngine.DirtyFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QPaintEngine.DirtyFlags', 'QPaintEngine.DirtyFlag', int]) -> 'QPaintEngine.DirtyFlags': ... + def __and__(self, other: typing.Union['QPaintEngine.DirtyFlags', 'QPaintEngine.DirtyFlag', int]) -> 'QPaintEngine.DirtyFlags': ... + def __xor__(self, other: typing.Union['QPaintEngine.DirtyFlags', 'QPaintEngine.DirtyFlag', int]) -> 'QPaintEngine.DirtyFlags': ... + def __ror__ (self, other: 'QPaintEngine.DirtyFlag') -> 'QPaintEngine.DirtyFlags': ... + def __rand__(self, other: 'QPaintEngine.DirtyFlag') -> 'QPaintEngine.DirtyFlags': ... + def __rxor__(self, other: 'QPaintEngine.DirtyFlag') -> 'QPaintEngine.DirtyFlags': ... def __init__(self, features: typing.Union['QPaintEngine.PaintEngineFeatures', 'QPaintEngine.PaintEngineFeature'] = ...) -> None: ... @@ -7359,7 +7501,10 @@ class QPdfWriter(QtCore.QObject, QPagedPaintDevice): def paintEngine(self) -> QPaintEngine: ... def setMargins(self, m: QPagedPaintDevice.Margins) -> None: ... def setPageSizeMM(self, size: QtCore.QSizeF) -> None: ... - def setPageSize(self, size: QPagedPaintDevice.PageSize) -> None: ... # type: ignore[override] + @typing.overload + def setPageSize(self, size: QPagedPaintDevice.PageSize) -> None: ... + @typing.overload + def setPageSize(self, pageSize: QPageSize) -> bool: ... def newPage(self) -> bool: ... def setCreator(self, creator: str) -> None: ... def creator(self) -> str: ... @@ -7901,6 +8046,9 @@ class QRasterWindow(QPaintDeviceWindow): class QRawFont(sip.simplewrapper): class LayoutFlag(int): + def __or__ (self, other: 'QRawFont.LayoutFlag') -> 'QRawFont.LayoutFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QRawFont.LayoutFlags': ... # type: ignore[override, misc] + SeparateAdvances = ... # type: QRawFont.LayoutFlag KernedAdvances = ... # type: QRawFont.LayoutFlag UseDesignMetrics = ... # type: QRawFont.LayoutFlag @@ -7924,12 +8072,20 @@ class QRawFont(sip.simplewrapper): def __init__(self, f: typing.Union['QRawFont.LayoutFlags', 'QRawFont.LayoutFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QRawFont.LayoutFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QRawFont.LayoutFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QRawFont.LayoutFlags', 'QRawFont.LayoutFlag', int]) -> 'QRawFont.LayoutFlags': ... + def __and__(self, other: typing.Union['QRawFont.LayoutFlags', 'QRawFont.LayoutFlag', int]) -> 'QRawFont.LayoutFlags': ... + def __xor__(self, other: typing.Union['QRawFont.LayoutFlags', 'QRawFont.LayoutFlag', int]) -> 'QRawFont.LayoutFlags': ... + def __ror__ (self, other: 'QRawFont.LayoutFlag') -> 'QRawFont.LayoutFlags': ... + def __rand__(self, other: 'QRawFont.LayoutFlag') -> 'QRawFont.LayoutFlags': ... + def __rxor__(self, other: 'QRawFont.LayoutFlag') -> 'QRawFont.LayoutFlags': ... @typing.overload def __init__(self) -> None: ... @@ -8088,15 +8244,15 @@ class QScreen(QtCore.QObject): def serialNumber(self) -> str: ... def model(self) -> str: ... def manufacturer(self) -> str: ... - def availableGeometryChanged(self, geometry: QtCore.QRect) -> None: ... - def virtualGeometryChanged(self, rect: QtCore.QRect) -> None: ... - def physicalSizeChanged(self, size: QtCore.QSizeF) -> None: ... - def refreshRateChanged(self, refreshRate: float) -> None: ... - def orientationChanged(self, orientation: QtCore.Qt.ScreenOrientation) -> None: ... - def primaryOrientationChanged(self, orientation: QtCore.Qt.ScreenOrientation) -> None: ... - def logicalDotsPerInchChanged(self, dpi: float) -> None: ... - def physicalDotsPerInchChanged(self, dpi: float) -> None: ... - def geometryChanged(self, geometry: QtCore.QRect) -> None: ... + availableGeometryChanged: typing.ClassVar[QtCore.pyqtSignal] + virtualGeometryChanged: typing.ClassVar[QtCore.pyqtSignal] + physicalSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + refreshRateChanged: typing.ClassVar[QtCore.pyqtSignal] + orientationChanged: typing.ClassVar[QtCore.pyqtSignal] + primaryOrientationChanged: typing.ClassVar[QtCore.pyqtSignal] + logicalDotsPerInchChanged: typing.ClassVar[QtCore.pyqtSignal] + physicalDotsPerInchChanged: typing.ClassVar[QtCore.pyqtSignal] + geometryChanged: typing.ClassVar[QtCore.pyqtSignal] def devicePixelRatio(self) -> float: ... def refreshRate(self) -> float: ... def grabWindow(self, window: sip.voidptr, x: int = ..., y: int = ..., width: int = ..., height: int = ...) -> QPixmap: ... @@ -8171,7 +8327,7 @@ class QStandardItemModel(QtCore.QAbstractItemModel): def __init__(self, rows: int, columns: int, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def clearItemData(self, index: QtCore.QModelIndex) -> bool: ... - def itemChanged(self, item: 'QStandardItem') -> None: ... + itemChanged: typing.ClassVar[QtCore.pyqtSignal] def setItemRoleNames(self, roleNames: typing.Dict[int, typing.Union[QtCore.QByteArray, bytes, bytearray]]) -> None: ... def sibling(self, row: int, column: int, idx: QtCore.QModelIndex) -> QtCore.QModelIndex: ... def dropMimeData(self, data: QtCore.QMimeData, action: QtCore.Qt.DropAction, row: int, column: int, parent: QtCore.QModelIndex) -> bool: ... @@ -8392,24 +8548,24 @@ class QStyleHints(QtCore.QObject): def touchDoubleTapDistance(self) -> int: ... def mouseDoubleClickDistance(self) -> int: ... - def showShortcutsInContextMenusChanged(self, a0: bool) -> None: ... + showShortcutsInContextMenusChanged: typing.ClassVar[QtCore.pyqtSignal] def setShowShortcutsInContextMenus(self, showShortcutsInContextMenus: bool) -> None: ... - def mouseQuickSelectionThresholdChanged(self, threshold: int) -> None: ... + mouseQuickSelectionThresholdChanged: typing.ClassVar[QtCore.pyqtSignal] def mouseQuickSelectionThreshold(self) -> int: ... def showShortcutsInContextMenus(self) -> bool: ... - def wheelScrollLinesChanged(self, scrollLines: int) -> None: ... + wheelScrollLinesChanged: typing.ClassVar[QtCore.pyqtSignal] def wheelScrollLines(self) -> int: ... - def useHoverEffectsChanged(self, useHoverEffects: bool) -> None: ... + useHoverEffectsChanged: typing.ClassVar[QtCore.pyqtSignal] def setUseHoverEffects(self, useHoverEffects: bool) -> None: ... def useHoverEffects(self) -> bool: ... def showIsMaximized(self) -> bool: ... - def tabFocusBehaviorChanged(self, tabFocusBehavior: QtCore.Qt.TabFocusBehavior) -> None: ... - def mousePressAndHoldIntervalChanged(self, mousePressAndHoldInterval: int) -> None: ... - def startDragTimeChanged(self, startDragTime: int) -> None: ... - def startDragDistanceChanged(self, startDragDistance: int) -> None: ... - def mouseDoubleClickIntervalChanged(self, mouseDoubleClickInterval: int) -> None: ... - def keyboardInputIntervalChanged(self, keyboardInputInterval: int) -> None: ... - def cursorFlashTimeChanged(self, cursorFlashTime: int) -> None: ... + tabFocusBehaviorChanged: typing.ClassVar[QtCore.pyqtSignal] + mousePressAndHoldIntervalChanged: typing.ClassVar[QtCore.pyqtSignal] + startDragTimeChanged: typing.ClassVar[QtCore.pyqtSignal] + startDragDistanceChanged: typing.ClassVar[QtCore.pyqtSignal] + mouseDoubleClickIntervalChanged: typing.ClassVar[QtCore.pyqtSignal] + keyboardInputIntervalChanged: typing.ClassVar[QtCore.pyqtSignal] + cursorFlashTimeChanged: typing.ClassVar[QtCore.pyqtSignal] def singleClickActivation(self) -> bool: ... def tabFocusBehavior(self) -> QtCore.Qt.TabFocusBehavior: ... def mousePressAndHoldInterval(self) -> int: ... @@ -8469,6 +8625,9 @@ class QSurfaceFormat(sip.simplewrapper): TripleBuffer = ... # type: QSurfaceFormat.SwapBehavior class FormatOption(int): + def __or__ (self, other: 'QSurfaceFormat.FormatOption') -> 'QSurfaceFormat.FormatOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSurfaceFormat.FormatOptions': ... # type: ignore[override, misc] + StereoBuffers = ... # type: QSurfaceFormat.FormatOption DebugContext = ... # type: QSurfaceFormat.FormatOption DeprecatedFunctions = ... # type: QSurfaceFormat.FormatOption @@ -8487,12 +8646,20 @@ class QSurfaceFormat(sip.simplewrapper): def __init__(self, f: typing.Union['QSurfaceFormat.FormatOptions', 'QSurfaceFormat.FormatOption']) -> None: ... @typing.overload def __init__(self, a0: 'QSurfaceFormat.FormatOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSurfaceFormat.FormatOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSurfaceFormat.FormatOptions', 'QSurfaceFormat.FormatOption', int]) -> 'QSurfaceFormat.FormatOptions': ... + def __and__(self, other: typing.Union['QSurfaceFormat.FormatOptions', 'QSurfaceFormat.FormatOption', int]) -> 'QSurfaceFormat.FormatOptions': ... + def __xor__(self, other: typing.Union['QSurfaceFormat.FormatOptions', 'QSurfaceFormat.FormatOption', int]) -> 'QSurfaceFormat.FormatOptions': ... + def __ror__ (self, other: 'QSurfaceFormat.FormatOption') -> 'QSurfaceFormat.FormatOptions': ... + def __rand__(self, other: 'QSurfaceFormat.FormatOption') -> 'QSurfaceFormat.FormatOptions': ... + def __rxor__(self, other: 'QSurfaceFormat.FormatOption') -> 'QSurfaceFormat.FormatOptions': ... @typing.overload def __init__(self) -> None: ... @@ -8781,6 +8948,9 @@ class QTextDocument(QtCore.QObject): UserResource = ... # type: QTextDocument.ResourceType class FindFlag(int): + def __or__ (self, other: 'QTextDocument.FindFlag') -> 'QTextDocument.FindFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTextDocument.FindFlags': ... # type: ignore[override, misc] + FindBackward = ... # type: QTextDocument.FindFlag FindCaseSensitively = ... # type: QTextDocument.FindFlag FindWholeWords = ... # type: QTextDocument.FindFlag @@ -8804,12 +8974,20 @@ class QTextDocument(QtCore.QObject): def __init__(self, f: typing.Union['QTextDocument.FindFlags', 'QTextDocument.FindFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QTextDocument.FindFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTextDocument.FindFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTextDocument.FindFlags', 'QTextDocument.FindFlag', int]) -> 'QTextDocument.FindFlags': ... + def __and__(self, other: typing.Union['QTextDocument.FindFlags', 'QTextDocument.FindFlag', int]) -> 'QTextDocument.FindFlags': ... + def __xor__(self, other: typing.Union['QTextDocument.FindFlags', 'QTextDocument.FindFlag', int]) -> 'QTextDocument.FindFlags': ... + def __ror__ (self, other: 'QTextDocument.FindFlag') -> 'QTextDocument.FindFlags': ... + def __rand__(self, other: 'QTextDocument.FindFlag') -> 'QTextDocument.FindFlags': ... + def __rxor__(self, other: 'QTextDocument.FindFlag') -> 'QTextDocument.FindFlags': ... class MarkdownFeatures(sip.simplewrapper): @@ -8819,12 +8997,20 @@ class QTextDocument(QtCore.QObject): def __init__(self, f: typing.Union['QTextDocument.MarkdownFeatures', 'QTextDocument.MarkdownFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QTextDocument.MarkdownFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTextDocument.MarkdownFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTextDocument.MarkdownFeatures', 'QTextDocument.MarkdownFeature', int]) -> 'QTextDocument.MarkdownFeatures': ... + def __and__(self, other: typing.Union['QTextDocument.MarkdownFeatures', 'QTextDocument.MarkdownFeature', int]) -> 'QTextDocument.MarkdownFeatures': ... + def __xor__(self, other: typing.Union['QTextDocument.MarkdownFeatures', 'QTextDocument.MarkdownFeature', int]) -> 'QTextDocument.MarkdownFeatures': ... + def __ror__ (self, other: 'QTextDocument.MarkdownFeature') -> 'QTextDocument.MarkdownFeatures': ... + def __rand__(self, other: 'QTextDocument.MarkdownFeature') -> 'QTextDocument.MarkdownFeatures': ... + def __rxor__(self, other: 'QTextDocument.MarkdownFeature') -> 'QTextDocument.MarkdownFeatures': ... @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -8834,7 +9020,7 @@ class QTextDocument(QtCore.QObject): def setMarkdown(self, markdown: str, features: typing.Union['QTextDocument.MarkdownFeatures', 'QTextDocument.MarkdownFeature'] = ...) -> None: ... def toMarkdown(self, features: typing.Union['QTextDocument.MarkdownFeatures', 'QTextDocument.MarkdownFeature'] = ...) -> str: ... def toRawText(self) -> str: ... - def baseUrlChanged(self, url: QtCore.QUrl) -> None: ... + baseUrlChanged: typing.ClassVar[QtCore.pyqtSignal] def setBaseUrl(self, url: QtCore.QUrl) -> None: ... def baseUrl(self) -> QtCore.QUrl: ... def setDefaultCursorMoveStyle(self, style: QtCore.Qt.CursorMoveStyle) -> None: ... @@ -8847,8 +9033,8 @@ class QTextDocument(QtCore.QObject): def setDocumentMargin(self, margin: float) -> None: ... def documentMargin(self) -> float: ... def characterAt(self, pos: int) -> str: ... - def documentLayoutChanged(self) -> None: ... - def undoCommandAdded(self) -> None: ... + documentLayoutChanged: typing.ClassVar[QtCore.pyqtSignal] + undoCommandAdded: typing.ClassVar[QtCore.pyqtSignal] def setIndentWidth(self, width: float) -> None: ... def indentWidth(self) -> float: ... def lastBlock(self) -> 'QTextBlock': ... @@ -8880,13 +9066,13 @@ class QTextDocument(QtCore.QObject): def undo(self) -> None: ... @typing.overload def undo(self, cursor: QTextCursor) -> None: ... - def undoAvailable(self, a0: bool) -> None: ... - def redoAvailable(self, a0: bool) -> None: ... - def modificationChanged(self, m: bool) -> None: ... - def cursorPositionChanged(self, cursor: QTextCursor) -> None: ... - def contentsChanged(self) -> None: ... - def contentsChange(self, from_: int, charsRemoves: int, charsAdded: int) -> None: ... - def blockCountChanged(self, newBlockCount: int) -> None: ... + undoAvailable: typing.ClassVar[QtCore.pyqtSignal] + redoAvailable: typing.ClassVar[QtCore.pyqtSignal] + modificationChanged: typing.ClassVar[QtCore.pyqtSignal] + cursorPositionChanged: typing.ClassVar[QtCore.pyqtSignal] + contentsChanged: typing.ClassVar[QtCore.pyqtSignal] + contentsChange: typing.ClassVar[QtCore.pyqtSignal] + blockCountChanged: typing.ClassVar[QtCore.pyqtSignal] def useDesignMetrics(self) -> bool: ... def setUseDesignMetrics(self, b: bool) -> None: ... def markContentsDirty(self, from_: int, length: int) -> None: ... @@ -9226,6 +9412,9 @@ class QTextFormat(sip.simplewrapper): UserProperty = ... # type: QTextFormat.Property class PageBreakFlag(int): + def __or__ (self, other: 'QTextFormat.PageBreakFlag') -> 'QTextFormat.PageBreakFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTextFormat.PageBreakFlags': ... # type: ignore[override, misc] + PageBreak_Auto = ... # type: QTextFormat.PageBreakFlag PageBreak_AlwaysBefore = ... # type: QTextFormat.PageBreakFlag PageBreak_AlwaysAfter = ... # type: QTextFormat.PageBreakFlag @@ -9272,12 +9461,20 @@ class QTextFormat(sip.simplewrapper): def __init__(self, f: typing.Union['QTextFormat.PageBreakFlags', 'QTextFormat.PageBreakFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QTextFormat.PageBreakFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTextFormat.PageBreakFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTextFormat.PageBreakFlags', 'QTextFormat.PageBreakFlag', int]) -> 'QTextFormat.PageBreakFlags': ... + def __and__(self, other: typing.Union['QTextFormat.PageBreakFlags', 'QTextFormat.PageBreakFlag', int]) -> 'QTextFormat.PageBreakFlags': ... + def __xor__(self, other: typing.Union['QTextFormat.PageBreakFlags', 'QTextFormat.PageBreakFlag', int]) -> 'QTextFormat.PageBreakFlags': ... + def __ror__ (self, other: 'QTextFormat.PageBreakFlag') -> 'QTextFormat.PageBreakFlags': ... + def __rand__(self, other: 'QTextFormat.PageBreakFlag') -> 'QTextFormat.PageBreakFlags': ... + def __rxor__(self, other: 'QTextFormat.PageBreakFlag') -> 'QTextFormat.PageBreakFlags': ... @typing.overload def __init__(self) -> None: ... @@ -10019,6 +10216,9 @@ class QTextOption(sip.simplewrapper): DelimiterTab = ... # type: QTextOption.TabType class Flag(int): + def __or__ (self, other: 'QTextOption.Flag') -> 'QTextOption.Flags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTextOption.Flags': ... # type: ignore[override, misc] + IncludeTrailingSpaces = ... # type: QTextOption.Flag ShowTabsAndSpaces = ... # type: QTextOption.Flag ShowLineAndParagraphSeparators = ... # type: QTextOption.Flag @@ -10054,12 +10254,20 @@ class QTextOption(sip.simplewrapper): def __init__(self, f: typing.Union['QTextOption.Flags', 'QTextOption.Flag']) -> None: ... @typing.overload def __init__(self, a0: 'QTextOption.Flags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTextOption.Flags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTextOption.Flags', 'QTextOption.Flag', int]) -> 'QTextOption.Flags': ... + def __and__(self, other: typing.Union['QTextOption.Flags', 'QTextOption.Flag', int]) -> 'QTextOption.Flags': ... + def __xor__(self, other: typing.Union['QTextOption.Flags', 'QTextOption.Flag', int]) -> 'QTextOption.Flags': ... + def __ror__ (self, other: 'QTextOption.Flag') -> 'QTextOption.Flags': ... + def __rand__(self, other: 'QTextOption.Flag') -> 'QTextOption.Flags': ... + def __rxor__(self, other: 'QTextOption.Flag') -> 'QTextOption.Flags': ... class Tab(sip.simplewrapper): @@ -10153,6 +10361,9 @@ class QTextTable(QTextFrame): class QTouchDevice(sip.simplewrapper): class CapabilityFlag(int): + def __or__ (self, other: 'QTouchDevice.CapabilityFlag') -> 'QTouchDevice.Capabilities': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTouchDevice.Capabilities': ... # type: ignore[override, misc] + Position = ... # type: QTouchDevice.CapabilityFlag Area = ... # type: QTouchDevice.CapabilityFlag Pressure = ... # type: QTouchDevice.CapabilityFlag @@ -10184,12 +10395,20 @@ class QTouchDevice(sip.simplewrapper): def __init__(self, f: typing.Union['QTouchDevice.Capabilities', 'QTouchDevice.CapabilityFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QTouchDevice.Capabilities') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTouchDevice.Capabilities': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTouchDevice.Capabilities', 'QTouchDevice.CapabilityFlag', int]) -> 'QTouchDevice.Capabilities': ... + def __and__(self, other: typing.Union['QTouchDevice.Capabilities', 'QTouchDevice.CapabilityFlag', int]) -> 'QTouchDevice.Capabilities': ... + def __xor__(self, other: typing.Union['QTouchDevice.Capabilities', 'QTouchDevice.CapabilityFlag', int]) -> 'QTouchDevice.Capabilities': ... + def __ror__ (self, other: 'QTouchDevice.CapabilityFlag') -> 'QTouchDevice.Capabilities': ... + def __rand__(self, other: 'QTouchDevice.CapabilityFlag') -> 'QTouchDevice.Capabilities': ... + def __rxor__(self, other: 'QTouchDevice.CapabilityFlag') -> 'QTouchDevice.Capabilities': ... @typing.overload def __init__(self) -> None: ... @@ -10314,7 +10533,7 @@ class QValidator(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def changed(self) -> None: ... + changed: typing.ClassVar[QtCore.pyqtSignal] def locale(self) -> QtCore.QLocale: ... def setLocale(self, locale: QtCore.QLocale) -> None: ... def fixup(self, a0: str) -> str: ... diff --git a/PyQt5-stubs/QtHelp.pyi b/PyQt5-stubs/QtHelp.pyi index 0b87c478..d9cd7be8 100644 --- a/PyQt5-stubs/QtHelp.pyi +++ b/PyQt5-stubs/QtHelp.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtHelp module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -69,8 +69,8 @@ class QHelpContentItem(sip.simplewrapper): class QHelpContentModel(QtCore.QAbstractItemModel): - def contentsCreated(self) -> None: ... - def contentsCreationStarted(self) -> None: ... + contentsCreated: typing.ClassVar[QtCore.pyqtSignal] + contentsCreationStarted: typing.ClassVar[QtCore.pyqtSignal] def isCreatingContents(self) -> bool: ... def columnCount(self, parent: QtCore.QModelIndex = ...) -> int: ... def rowCount(self, parent: QtCore.QModelIndex = ...) -> int: ... @@ -83,7 +83,7 @@ class QHelpContentModel(QtCore.QAbstractItemModel): class QHelpContentWidget(QtWidgets.QTreeView): - def linkActivated(self, link: QtCore.QUrl) -> None: ... + linkActivated: typing.ClassVar[QtCore.pyqtSignal] def indexOf(self, link: QtCore.QUrl) -> QtCore.QModelIndex: ... @@ -102,11 +102,11 @@ class QHelpEngineCore(QtCore.QObject): def usesFilterEngine(self) -> bool: ... def setUsesFilterEngine(self, uses: bool) -> None: ... def filterEngine(self) -> 'QHelpFilterEngine': ... - def readersAboutToBeInvalidated(self) -> None: ... - def warning(self, msg: str) -> None: ... - def currentFilterChanged(self, newFilter: str) -> None: ... - def setupFinished(self) -> None: ... - def setupStarted(self) -> None: ... + readersAboutToBeInvalidated: typing.ClassVar[QtCore.pyqtSignal] + warning: typing.ClassVar[QtCore.pyqtSignal] + currentFilterChanged: typing.ClassVar[QtCore.pyqtSignal] + setupFinished: typing.ClassVar[QtCore.pyqtSignal] + setupStarted: typing.ClassVar[QtCore.pyqtSignal] def setAutoSaveFilter(self, save: bool) -> None: ... def autoSaveFilter(self) -> bool: ... def error(self) -> str: ... @@ -177,7 +177,7 @@ class QHelpFilterEngine(QtCore.QObject): @typing.overload def indices(self, filterName: str) -> typing.List[str]: ... def availableVersions(self) -> typing.List[QtCore.QVersionNumber]: ... - def filterActivated(self, newFilter: str) -> None: ... + filterActivated: typing.ClassVar[QtCore.pyqtSignal] def namespacesForFilter(self, filterName: str) -> typing.List[str]: ... def removeFilter(self, filterName: str) -> bool: ... def setFilterData(self, filterName: str, filterData: QHelpFilterData) -> bool: ... @@ -202,8 +202,8 @@ class QHelpFilterSettingsWidget(QtWidgets.QWidget): class QHelpIndexModel(QtCore.QStringListModel): - def indexCreated(self) -> None: ... - def indexCreationStarted(self) -> None: ... + indexCreated: typing.ClassVar[QtCore.pyqtSignal] + indexCreationStarted: typing.ClassVar[QtCore.pyqtSignal] def isCreatingIndex(self) -> bool: ... def linksForKeyword(self, keyword: str) -> typing.Dict[str, QtCore.QUrl]: ... def filter(self, filter: str, wildcard: str = ...) -> QtCore.QModelIndex: ... @@ -213,12 +213,12 @@ class QHelpIndexModel(QtCore.QStringListModel): class QHelpIndexWidget(QtWidgets.QListView): - def documentsActivated(self, documents: typing.Iterable['QHelpLink'], keyword: str) -> None: ... - def documentActivated(self, document: 'QHelpLink', keyword: str) -> None: ... + documentsActivated: typing.ClassVar[QtCore.pyqtSignal] + documentActivated: typing.ClassVar[QtCore.pyqtSignal] def activateCurrentItem(self) -> None: ... def filterIndices(self, filter: str, wildcard: str = ...) -> None: ... - def linksActivated(self, links: typing.Dict[str, QtCore.QUrl], keyword: str) -> None: ... - def linkActivated(self, link: QtCore.QUrl, keyword: str) -> None: ... + linksActivated: typing.ClassVar[QtCore.pyqtSignal] + linkActivated: typing.ClassVar[QtCore.pyqtSignal] class QHelpLink(sip.simplewrapper): @@ -264,10 +264,10 @@ class QHelpSearchEngine(QtCore.QObject): def searchInput(self) -> str: ... def searchResults(self, start: int, end: int) -> typing.List['QHelpSearchResult']: ... def searchResultCount(self) -> int: ... - def searchingFinished(self, hits: int) -> None: ... - def searchingStarted(self) -> None: ... - def indexingFinished(self) -> None: ... - def indexingStarted(self) -> None: ... + searchingFinished: typing.ClassVar[QtCore.pyqtSignal] + searchingStarted: typing.ClassVar[QtCore.pyqtSignal] + indexingFinished: typing.ClassVar[QtCore.pyqtSignal] + indexingStarted: typing.ClassVar[QtCore.pyqtSignal] def cancelSearching(self) -> None: ... @typing.overload def search(self, queryList: typing.Iterable[QHelpSearchQuery]) -> None: ... @@ -304,7 +304,7 @@ class QHelpSearchQueryWidget(QtWidgets.QWidget): def searchInput(self) -> str: ... def setCompactMode(self, on: bool) -> None: ... def isCompactMode(self) -> bool: ... - def search(self) -> None: ... + search: typing.ClassVar[QtCore.pyqtSignal] def collapseExtendedSearch(self) -> None: ... def expandExtendedSearch(self) -> None: ... def setQuery(self, queryList: typing.Iterable[QHelpSearchQuery]) -> None: ... @@ -313,5 +313,5 @@ class QHelpSearchQueryWidget(QtWidgets.QWidget): class QHelpSearchResultWidget(QtWidgets.QWidget): - def requestShowLink(self, url: QtCore.QUrl) -> None: ... + requestShowLink: typing.ClassVar[QtCore.pyqtSignal] def linkAt(self, point: QtCore.QPoint) -> QtCore.QUrl: ... diff --git a/PyQt5-stubs/QtLocation.pyi b/PyQt5-stubs/QtLocation.pyi index 3926f660..45041fd9 100644 --- a/PyQt5-stubs/QtLocation.pyi +++ b/PyQt5-stubs/QtLocation.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtLocation module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -64,25 +64,22 @@ class QGeoCodeReply(QtCore.QObject): def setViewport(self, viewport: QtPositioning.QGeoShape) -> None: ... def setFinished(self, finished: bool) -> None: ... def setError(self, error: 'QGeoCodeReply.Error', errorString: str) -> None: ... - def finished(self) -> None: ... - def aborted(self) -> None: ... + finished: typing.ClassVar[QtCore.pyqtSignal] + aborted: typing.ClassVar[QtCore.pyqtSignal] def abort(self) -> None: ... def offset(self) -> int: ... def limit(self) -> int: ... def locations(self) -> typing.List[QtPositioning.QGeoLocation]: ... def viewport(self) -> QtPositioning.QGeoShape: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QGeoCodeReply.Error': ... - @typing.overload - def error(self, error: 'QGeoCodeReply.Error', errorString: str = ...) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def isFinished(self) -> bool: ... class QGeoCodingManager(QtCore.QObject): - def error(self, reply: QGeoCodeReply, error: QGeoCodeReply.Error, errorString: str = ...) -> None: ... - def finished(self, reply: QGeoCodeReply) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def locale(self) -> QtCore.QLocale: ... def setLocale(self, locale: QtCore.QLocale) -> None: ... def reverseGeocode(self, coordinate: QtPositioning.QGeoCoordinate, bounds: QtPositioning.QGeoShape = ...) -> QGeoCodeReply: ... @@ -98,8 +95,8 @@ class QGeoCodingManagerEngine(QtCore.QObject): def __init__(self, parameters: typing.Dict[str, typing.Any], parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def error(self, reply: QGeoCodeReply, error: QGeoCodeReply.Error, errorString: str = ...) -> None: ... - def finished(self, reply: QGeoCodeReply) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def locale(self) -> QtCore.QLocale: ... def setLocale(self, locale: QtCore.QLocale) -> None: ... def reverseGeocode(self, coordinate: QtPositioning.QGeoCoordinate, bounds: QtPositioning.QGeoShape) -> QGeoCodeReply: ... @@ -230,22 +227,22 @@ class QGeoRouteReply(QtCore.QObject): def setRoutes(self, routes: typing.Iterable[QGeoRoute]) -> None: ... def setFinished(self, finished: bool) -> None: ... def setError(self, error: 'QGeoRouteReply.Error', errorString: str) -> None: ... - def finished(self) -> None: ... - def aborted(self) -> None: ... + finished: typing.ClassVar[QtCore.pyqtSignal] + aborted: typing.ClassVar[QtCore.pyqtSignal] def abort(self) -> None: ... def routes(self) -> typing.List[QGeoRoute]: ... def request(self) -> 'QGeoRouteRequest': ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QGeoRouteReply.Error': ... - @typing.overload - def error(self, error: 'QGeoRouteReply.Error', errorString: str = ...) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def isFinished(self) -> bool: ... class QGeoRouteRequest(sip.simplewrapper): class ManeuverDetail(int): + def __or__ (self, other: 'QGeoRouteRequest.ManeuverDetail') -> 'QGeoRouteRequest.ManeuverDetails': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoRouteRequest.ManeuverDetails': ... # type: ignore[override, misc] + NoManeuvers = ... # type: QGeoRouteRequest.ManeuverDetail BasicManeuvers = ... # type: QGeoRouteRequest.ManeuverDetail @@ -253,6 +250,9 @@ class QGeoRouteRequest(sip.simplewrapper): BasicManeuvers = ... # type: QGeoRouteRequest.ManeuverDetail class SegmentDetail(int): + def __or__ (self, other: 'QGeoRouteRequest.SegmentDetail') -> 'QGeoRouteRequest.SegmentDetails': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoRouteRequest.SegmentDetails': ... # type: ignore[override, misc] + NoSegmentData = ... # type: QGeoRouteRequest.SegmentDetail BasicSegmentData = ... # type: QGeoRouteRequest.SegmentDetail @@ -260,6 +260,9 @@ class QGeoRouteRequest(sip.simplewrapper): BasicSegmentData = ... # type: QGeoRouteRequest.SegmentDetail class RouteOptimization(int): + def __or__ (self, other: 'QGeoRouteRequest.RouteOptimization') -> 'QGeoRouteRequest.RouteOptimizations': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoRouteRequest.RouteOptimizations': ... # type: ignore[override, misc] + ShortestRoute = ... # type: QGeoRouteRequest.RouteOptimization FastestRoute = ... # type: QGeoRouteRequest.RouteOptimization MostEconomicRoute = ... # type: QGeoRouteRequest.RouteOptimization @@ -271,6 +274,9 @@ class QGeoRouteRequest(sip.simplewrapper): MostScenicRoute = ... # type: QGeoRouteRequest.RouteOptimization class FeatureWeight(int): + def __or__ (self, other: 'QGeoRouteRequest.FeatureWeight') -> 'QGeoRouteRequest.FeatureWeights': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoRouteRequest.FeatureWeights': ... # type: ignore[override, misc] + NeutralFeatureWeight = ... # type: QGeoRouteRequest.FeatureWeight PreferFeatureWeight = ... # type: QGeoRouteRequest.FeatureWeight RequireFeatureWeight = ... # type: QGeoRouteRequest.FeatureWeight @@ -284,6 +290,9 @@ class QGeoRouteRequest(sip.simplewrapper): DisallowFeatureWeight = ... # type: QGeoRouteRequest.FeatureWeight class FeatureType(int): + def __or__ (self, other: 'QGeoRouteRequest.FeatureType') -> 'QGeoRouteRequest.FeatureTypes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoRouteRequest.FeatureTypes': ... # type: ignore[override, misc] + NoFeature = ... # type: QGeoRouteRequest.FeatureType TollFeature = ... # type: QGeoRouteRequest.FeatureType HighwayFeature = ... # type: QGeoRouteRequest.FeatureType @@ -307,6 +316,9 @@ class QGeoRouteRequest(sip.simplewrapper): TrafficFeature = ... # type: QGeoRouteRequest.FeatureType class TravelMode(int): + def __or__ (self, other: 'QGeoRouteRequest.TravelMode') -> 'QGeoRouteRequest.TravelModes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoRouteRequest.TravelModes': ... # type: ignore[override, misc] + CarTravel = ... # type: QGeoRouteRequest.TravelMode PedestrianTravel = ... # type: QGeoRouteRequest.TravelMode BicycleTravel = ... # type: QGeoRouteRequest.TravelMode @@ -327,12 +339,20 @@ class QGeoRouteRequest(sip.simplewrapper): def __init__(self, f: typing.Union['QGeoRouteRequest.TravelModes', 'QGeoRouteRequest.TravelMode']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoRouteRequest.TravelModes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoRouteRequest.TravelModes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoRouteRequest.TravelModes', 'QGeoRouteRequest.TravelMode', int]) -> 'QGeoRouteRequest.TravelModes': ... + def __and__(self, other: typing.Union['QGeoRouteRequest.TravelModes', 'QGeoRouteRequest.TravelMode', int]) -> 'QGeoRouteRequest.TravelModes': ... + def __xor__(self, other: typing.Union['QGeoRouteRequest.TravelModes', 'QGeoRouteRequest.TravelMode', int]) -> 'QGeoRouteRequest.TravelModes': ... + def __ror__ (self, other: 'QGeoRouteRequest.TravelMode') -> 'QGeoRouteRequest.TravelModes': ... + def __rand__(self, other: 'QGeoRouteRequest.TravelMode') -> 'QGeoRouteRequest.TravelModes': ... + def __rxor__(self, other: 'QGeoRouteRequest.TravelMode') -> 'QGeoRouteRequest.TravelModes': ... class FeatureTypes(sip.simplewrapper): @@ -342,12 +362,20 @@ class QGeoRouteRequest(sip.simplewrapper): def __init__(self, f: typing.Union['QGeoRouteRequest.FeatureTypes', 'QGeoRouteRequest.FeatureType']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoRouteRequest.FeatureTypes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoRouteRequest.FeatureTypes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoRouteRequest.FeatureTypes', 'QGeoRouteRequest.FeatureType', int]) -> 'QGeoRouteRequest.FeatureTypes': ... + def __and__(self, other: typing.Union['QGeoRouteRequest.FeatureTypes', 'QGeoRouteRequest.FeatureType', int]) -> 'QGeoRouteRequest.FeatureTypes': ... + def __xor__(self, other: typing.Union['QGeoRouteRequest.FeatureTypes', 'QGeoRouteRequest.FeatureType', int]) -> 'QGeoRouteRequest.FeatureTypes': ... + def __ror__ (self, other: 'QGeoRouteRequest.FeatureType') -> 'QGeoRouteRequest.FeatureTypes': ... + def __rand__(self, other: 'QGeoRouteRequest.FeatureType') -> 'QGeoRouteRequest.FeatureTypes': ... + def __rxor__(self, other: 'QGeoRouteRequest.FeatureType') -> 'QGeoRouteRequest.FeatureTypes': ... class FeatureWeights(sip.simplewrapper): @@ -357,12 +385,20 @@ class QGeoRouteRequest(sip.simplewrapper): def __init__(self, f: typing.Union['QGeoRouteRequest.FeatureWeights', 'QGeoRouteRequest.FeatureWeight']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoRouteRequest.FeatureWeights') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoRouteRequest.FeatureWeights': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoRouteRequest.FeatureWeights', 'QGeoRouteRequest.FeatureWeight', int]) -> 'QGeoRouteRequest.FeatureWeights': ... + def __and__(self, other: typing.Union['QGeoRouteRequest.FeatureWeights', 'QGeoRouteRequest.FeatureWeight', int]) -> 'QGeoRouteRequest.FeatureWeights': ... + def __xor__(self, other: typing.Union['QGeoRouteRequest.FeatureWeights', 'QGeoRouteRequest.FeatureWeight', int]) -> 'QGeoRouteRequest.FeatureWeights': ... + def __ror__ (self, other: 'QGeoRouteRequest.FeatureWeight') -> 'QGeoRouteRequest.FeatureWeights': ... + def __rand__(self, other: 'QGeoRouteRequest.FeatureWeight') -> 'QGeoRouteRequest.FeatureWeights': ... + def __rxor__(self, other: 'QGeoRouteRequest.FeatureWeight') -> 'QGeoRouteRequest.FeatureWeights': ... class RouteOptimizations(sip.simplewrapper): @@ -372,12 +408,20 @@ class QGeoRouteRequest(sip.simplewrapper): def __init__(self, f: typing.Union['QGeoRouteRequest.RouteOptimizations', 'QGeoRouteRequest.RouteOptimization']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoRouteRequest.RouteOptimizations') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoRouteRequest.RouteOptimizations': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoRouteRequest.RouteOptimizations', 'QGeoRouteRequest.RouteOptimization', int]) -> 'QGeoRouteRequest.RouteOptimizations': ... + def __and__(self, other: typing.Union['QGeoRouteRequest.RouteOptimizations', 'QGeoRouteRequest.RouteOptimization', int]) -> 'QGeoRouteRequest.RouteOptimizations': ... + def __xor__(self, other: typing.Union['QGeoRouteRequest.RouteOptimizations', 'QGeoRouteRequest.RouteOptimization', int]) -> 'QGeoRouteRequest.RouteOptimizations': ... + def __ror__ (self, other: 'QGeoRouteRequest.RouteOptimization') -> 'QGeoRouteRequest.RouteOptimizations': ... + def __rand__(self, other: 'QGeoRouteRequest.RouteOptimization') -> 'QGeoRouteRequest.RouteOptimizations': ... + def __rxor__(self, other: 'QGeoRouteRequest.RouteOptimization') -> 'QGeoRouteRequest.RouteOptimizations': ... class SegmentDetails(sip.simplewrapper): @@ -387,12 +431,20 @@ class QGeoRouteRequest(sip.simplewrapper): def __init__(self, f: typing.Union['QGeoRouteRequest.SegmentDetails', 'QGeoRouteRequest.SegmentDetail']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoRouteRequest.SegmentDetails') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoRouteRequest.SegmentDetails': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoRouteRequest.SegmentDetails', 'QGeoRouteRequest.SegmentDetail', int]) -> 'QGeoRouteRequest.SegmentDetails': ... + def __and__(self, other: typing.Union['QGeoRouteRequest.SegmentDetails', 'QGeoRouteRequest.SegmentDetail', int]) -> 'QGeoRouteRequest.SegmentDetails': ... + def __xor__(self, other: typing.Union['QGeoRouteRequest.SegmentDetails', 'QGeoRouteRequest.SegmentDetail', int]) -> 'QGeoRouteRequest.SegmentDetails': ... + def __ror__ (self, other: 'QGeoRouteRequest.SegmentDetail') -> 'QGeoRouteRequest.SegmentDetails': ... + def __rand__(self, other: 'QGeoRouteRequest.SegmentDetail') -> 'QGeoRouteRequest.SegmentDetails': ... + def __rxor__(self, other: 'QGeoRouteRequest.SegmentDetail') -> 'QGeoRouteRequest.SegmentDetails': ... class ManeuverDetails(sip.simplewrapper): @@ -402,12 +454,20 @@ class QGeoRouteRequest(sip.simplewrapper): def __init__(self, f: typing.Union['QGeoRouteRequest.ManeuverDetails', 'QGeoRouteRequest.ManeuverDetail']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoRouteRequest.ManeuverDetails') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoRouteRequest.ManeuverDetails': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoRouteRequest.ManeuverDetails', 'QGeoRouteRequest.ManeuverDetail', int]) -> 'QGeoRouteRequest.ManeuverDetails': ... + def __and__(self, other: typing.Union['QGeoRouteRequest.ManeuverDetails', 'QGeoRouteRequest.ManeuverDetail', int]) -> 'QGeoRouteRequest.ManeuverDetails': ... + def __xor__(self, other: typing.Union['QGeoRouteRequest.ManeuverDetails', 'QGeoRouteRequest.ManeuverDetail', int]) -> 'QGeoRouteRequest.ManeuverDetails': ... + def __ror__ (self, other: 'QGeoRouteRequest.ManeuverDetail') -> 'QGeoRouteRequest.ManeuverDetails': ... + def __rand__(self, other: 'QGeoRouteRequest.ManeuverDetail') -> 'QGeoRouteRequest.ManeuverDetails': ... + def __rxor__(self, other: 'QGeoRouteRequest.ManeuverDetail') -> 'QGeoRouteRequest.ManeuverDetails': ... @typing.overload def __init__(self, waypoints: typing.Iterable[QtPositioning.QGeoCoordinate] = ...) -> None: ... @@ -464,8 +524,8 @@ class QGeoRouteSegment(sip.simplewrapper): class QGeoRoutingManager(QtCore.QObject): - def error(self, reply: QGeoRouteReply, error: QGeoRouteReply.Error, errorString: str = ...) -> None: ... - def finished(self, reply: QGeoRouteReply) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def measurementSystem(self) -> QtCore.QLocale.MeasurementSystem: ... def setMeasurementSystem(self, system: QtCore.QLocale.MeasurementSystem) -> None: ... def locale(self) -> QtCore.QLocale: ... @@ -492,8 +552,8 @@ class QGeoRoutingManagerEngine(QtCore.QObject): def setSupportedFeatureWeights(self, featureWeights: typing.Union[QGeoRouteRequest.FeatureWeights, QGeoRouteRequest.FeatureWeight]) -> None: ... def setSupportedFeatureTypes(self, featureTypes: typing.Union[QGeoRouteRequest.FeatureTypes, QGeoRouteRequest.FeatureType]) -> None: ... def setSupportedTravelModes(self, travelModes: typing.Union[QGeoRouteRequest.TravelModes, QGeoRouteRequest.TravelMode]) -> None: ... - def error(self, reply: QGeoRouteReply, error: QGeoRouteReply.Error, errorString: str = ...) -> None: ... - def finished(self, reply: QGeoRouteReply) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def measurementSystem(self) -> QtCore.QLocale.MeasurementSystem: ... def setMeasurementSystem(self, system: QtCore.QLocale.MeasurementSystem) -> None: ... def locale(self) -> QtCore.QLocale: ... @@ -516,6 +576,9 @@ class QNavigationManager(sip.simplewrapper): ... class QGeoServiceProvider(QtCore.QObject): class NavigationFeature(int): + def __or__ (self, other: 'QGeoServiceProvider.NavigationFeature') -> 'QGeoServiceProvider.NavigationFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoServiceProvider.NavigationFeatures': ... # type: ignore[override, misc] + NoNavigationFeatures = ... # type: QGeoServiceProvider.NavigationFeature OnlineNavigationFeature = ... # type: QGeoServiceProvider.NavigationFeature OfflineNavigationFeature = ... # type: QGeoServiceProvider.NavigationFeature @@ -527,6 +590,9 @@ class QGeoServiceProvider(QtCore.QObject): AnyNavigationFeatures = ... # type: QGeoServiceProvider.NavigationFeature class PlacesFeature(int): + def __or__ (self, other: 'QGeoServiceProvider.PlacesFeature') -> 'QGeoServiceProvider.PlacesFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoServiceProvider.PlacesFeatures': ... # type: ignore[override, misc] + NoPlacesFeatures = ... # type: QGeoServiceProvider.PlacesFeature OnlinePlacesFeature = ... # type: QGeoServiceProvider.PlacesFeature OfflinePlacesFeature = ... # type: QGeoServiceProvider.PlacesFeature @@ -556,6 +622,9 @@ class QGeoServiceProvider(QtCore.QObject): AnyPlacesFeatures = ... # type: QGeoServiceProvider.PlacesFeature class MappingFeature(int): + def __or__ (self, other: 'QGeoServiceProvider.MappingFeature') -> 'QGeoServiceProvider.MappingFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoServiceProvider.MappingFeatures': ... # type: ignore[override, misc] + NoMappingFeatures = ... # type: QGeoServiceProvider.MappingFeature OnlineMappingFeature = ... # type: QGeoServiceProvider.MappingFeature OfflineMappingFeature = ... # type: QGeoServiceProvider.MappingFeature @@ -569,6 +638,9 @@ class QGeoServiceProvider(QtCore.QObject): AnyMappingFeatures = ... # type: QGeoServiceProvider.MappingFeature class GeocodingFeature(int): + def __or__ (self, other: 'QGeoServiceProvider.GeocodingFeature') -> 'QGeoServiceProvider.GeocodingFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoServiceProvider.GeocodingFeatures': ... # type: ignore[override, misc] + NoGeocodingFeatures = ... # type: QGeoServiceProvider.GeocodingFeature OnlineGeocodingFeature = ... # type: QGeoServiceProvider.GeocodingFeature OfflineGeocodingFeature = ... # type: QGeoServiceProvider.GeocodingFeature @@ -584,6 +656,9 @@ class QGeoServiceProvider(QtCore.QObject): AnyGeocodingFeatures = ... # type: QGeoServiceProvider.GeocodingFeature class RoutingFeature(int): + def __or__ (self, other: 'QGeoServiceProvider.RoutingFeature') -> 'QGeoServiceProvider.RoutingFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoServiceProvider.RoutingFeatures': ... # type: ignore[override, misc] + NoRoutingFeatures = ... # type: QGeoServiceProvider.RoutingFeature OnlineRoutingFeature = ... # type: QGeoServiceProvider.RoutingFeature OfflineRoutingFeature = ... # type: QGeoServiceProvider.RoutingFeature @@ -625,12 +700,20 @@ class QGeoServiceProvider(QtCore.QObject): def __init__(self, f: typing.Union['QGeoServiceProvider.RoutingFeatures', 'QGeoServiceProvider.RoutingFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoServiceProvider.RoutingFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoServiceProvider.RoutingFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoServiceProvider.RoutingFeatures', 'QGeoServiceProvider.RoutingFeature', int]) -> 'QGeoServiceProvider.RoutingFeatures': ... + def __and__(self, other: typing.Union['QGeoServiceProvider.RoutingFeatures', 'QGeoServiceProvider.RoutingFeature', int]) -> 'QGeoServiceProvider.RoutingFeatures': ... + def __xor__(self, other: typing.Union['QGeoServiceProvider.RoutingFeatures', 'QGeoServiceProvider.RoutingFeature', int]) -> 'QGeoServiceProvider.RoutingFeatures': ... + def __ror__ (self, other: 'QGeoServiceProvider.RoutingFeature') -> 'QGeoServiceProvider.RoutingFeatures': ... + def __rand__(self, other: 'QGeoServiceProvider.RoutingFeature') -> 'QGeoServiceProvider.RoutingFeatures': ... + def __rxor__(self, other: 'QGeoServiceProvider.RoutingFeature') -> 'QGeoServiceProvider.RoutingFeatures': ... class GeocodingFeatures(sip.simplewrapper): @@ -640,12 +723,20 @@ class QGeoServiceProvider(QtCore.QObject): def __init__(self, f: typing.Union['QGeoServiceProvider.GeocodingFeatures', 'QGeoServiceProvider.GeocodingFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoServiceProvider.GeocodingFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoServiceProvider.GeocodingFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoServiceProvider.GeocodingFeatures', 'QGeoServiceProvider.GeocodingFeature', int]) -> 'QGeoServiceProvider.GeocodingFeatures': ... + def __and__(self, other: typing.Union['QGeoServiceProvider.GeocodingFeatures', 'QGeoServiceProvider.GeocodingFeature', int]) -> 'QGeoServiceProvider.GeocodingFeatures': ... + def __xor__(self, other: typing.Union['QGeoServiceProvider.GeocodingFeatures', 'QGeoServiceProvider.GeocodingFeature', int]) -> 'QGeoServiceProvider.GeocodingFeatures': ... + def __ror__ (self, other: 'QGeoServiceProvider.GeocodingFeature') -> 'QGeoServiceProvider.GeocodingFeatures': ... + def __rand__(self, other: 'QGeoServiceProvider.GeocodingFeature') -> 'QGeoServiceProvider.GeocodingFeatures': ... + def __rxor__(self, other: 'QGeoServiceProvider.GeocodingFeature') -> 'QGeoServiceProvider.GeocodingFeatures': ... class MappingFeatures(sip.simplewrapper): @@ -655,12 +746,20 @@ class QGeoServiceProvider(QtCore.QObject): def __init__(self, f: typing.Union['QGeoServiceProvider.MappingFeatures', 'QGeoServiceProvider.MappingFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoServiceProvider.MappingFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoServiceProvider.MappingFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoServiceProvider.MappingFeatures', 'QGeoServiceProvider.MappingFeature', int]) -> 'QGeoServiceProvider.MappingFeatures': ... + def __and__(self, other: typing.Union['QGeoServiceProvider.MappingFeatures', 'QGeoServiceProvider.MappingFeature', int]) -> 'QGeoServiceProvider.MappingFeatures': ... + def __xor__(self, other: typing.Union['QGeoServiceProvider.MappingFeatures', 'QGeoServiceProvider.MappingFeature', int]) -> 'QGeoServiceProvider.MappingFeatures': ... + def __ror__ (self, other: 'QGeoServiceProvider.MappingFeature') -> 'QGeoServiceProvider.MappingFeatures': ... + def __rand__(self, other: 'QGeoServiceProvider.MappingFeature') -> 'QGeoServiceProvider.MappingFeatures': ... + def __rxor__(self, other: 'QGeoServiceProvider.MappingFeature') -> 'QGeoServiceProvider.MappingFeatures': ... class PlacesFeatures(sip.simplewrapper): @@ -670,12 +769,20 @@ class QGeoServiceProvider(QtCore.QObject): def __init__(self, f: typing.Union['QGeoServiceProvider.PlacesFeatures', 'QGeoServiceProvider.PlacesFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoServiceProvider.PlacesFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoServiceProvider.PlacesFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoServiceProvider.PlacesFeatures', 'QGeoServiceProvider.PlacesFeature', int]) -> 'QGeoServiceProvider.PlacesFeatures': ... + def __and__(self, other: typing.Union['QGeoServiceProvider.PlacesFeatures', 'QGeoServiceProvider.PlacesFeature', int]) -> 'QGeoServiceProvider.PlacesFeatures': ... + def __xor__(self, other: typing.Union['QGeoServiceProvider.PlacesFeatures', 'QGeoServiceProvider.PlacesFeature', int]) -> 'QGeoServiceProvider.PlacesFeatures': ... + def __ror__ (self, other: 'QGeoServiceProvider.PlacesFeature') -> 'QGeoServiceProvider.PlacesFeatures': ... + def __rand__(self, other: 'QGeoServiceProvider.PlacesFeature') -> 'QGeoServiceProvider.PlacesFeatures': ... + def __rxor__(self, other: 'QGeoServiceProvider.PlacesFeature') -> 'QGeoServiceProvider.PlacesFeatures': ... class NavigationFeatures(sip.simplewrapper): @@ -685,12 +792,20 @@ class QGeoServiceProvider(QtCore.QObject): def __init__(self, f: typing.Union['QGeoServiceProvider.NavigationFeatures', 'QGeoServiceProvider.NavigationFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoServiceProvider.NavigationFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoServiceProvider.NavigationFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoServiceProvider.NavigationFeatures', 'QGeoServiceProvider.NavigationFeature', int]) -> 'QGeoServiceProvider.NavigationFeatures': ... + def __and__(self, other: typing.Union['QGeoServiceProvider.NavigationFeatures', 'QGeoServiceProvider.NavigationFeature', int]) -> 'QGeoServiceProvider.NavigationFeatures': ... + def __xor__(self, other: typing.Union['QGeoServiceProvider.NavigationFeatures', 'QGeoServiceProvider.NavigationFeature', int]) -> 'QGeoServiceProvider.NavigationFeatures': ... + def __ror__ (self, other: 'QGeoServiceProvider.NavigationFeature') -> 'QGeoServiceProvider.NavigationFeatures': ... + def __rand__(self, other: 'QGeoServiceProvider.NavigationFeature') -> 'QGeoServiceProvider.NavigationFeatures': ... + def __rxor__(self, other: 'QGeoServiceProvider.NavigationFeature') -> 'QGeoServiceProvider.NavigationFeatures': ... def __init__(self, providerName: str, parameters: typing.Dict[str, typing.Any] = ..., allowExperimental: bool = ...) -> None: ... @@ -725,6 +840,9 @@ class QGeoServiceProvider(QtCore.QObject): class QLocation(sip.simplewrapper): class Visibility(int): + def __or__ (self, other: 'QLocation.Visibility') -> 'QLocation.VisibilityScope': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QLocation.VisibilityScope': ... # type: ignore[override, misc] + UnspecifiedVisibility = ... # type: QLocation.Visibility DeviceVisibility = ... # type: QLocation.Visibility PrivateVisibility = ... # type: QLocation.Visibility @@ -743,12 +861,20 @@ class QLocation(sip.simplewrapper): def __init__(self, f: typing.Union['QLocation.VisibilityScope', 'QLocation.Visibility']) -> None: ... @typing.overload def __init__(self, a0: 'QLocation.VisibilityScope') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QLocation.VisibilityScope': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QLocation.VisibilityScope', 'QLocation.Visibility', int]) -> 'QLocation.VisibilityScope': ... + def __and__(self, other: typing.Union['QLocation.VisibilityScope', 'QLocation.Visibility', int]) -> 'QLocation.VisibilityScope': ... + def __xor__(self, other: typing.Union['QLocation.VisibilityScope', 'QLocation.Visibility', int]) -> 'QLocation.VisibilityScope': ... + def __ror__ (self, other: 'QLocation.Visibility') -> 'QLocation.VisibilityScope': ... + def __rand__(self, other: 'QLocation.Visibility') -> 'QLocation.VisibilityScope': ... + def __rxor__(self, other: 'QLocation.Visibility') -> 'QLocation.VisibilityScope': ... class QPlace(sip.simplewrapper): @@ -930,14 +1056,11 @@ class QPlaceReply(QtCore.QObject): def setError(self, error: 'QPlaceReply.Error', errorString: str) -> None: ... def setFinished(self, finished: bool) -> None: ... - def contentUpdated(self) -> None: ... - def finished(self) -> None: ... - def aborted(self) -> None: ... + contentUpdated: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] + aborted: typing.ClassVar[QtCore.pyqtSignal] def abort(self) -> None: ... - @typing.overload - def error(self) -> 'QPlaceReply.Error': ... - @typing.overload - def error(self, error: 'QPlaceReply.Error', errorString: str = ...) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def errorString(self) -> str: ... def type(self) -> 'QPlaceReply.Type': ... def isFinished(self) -> bool: ... @@ -1061,15 +1184,15 @@ class QPlaceImage(QPlaceContent): class QPlaceManager(QtCore.QObject): - def dataChanged(self) -> None: ... - def categoryRemoved(self, categoryId: str, parentId: str) -> None: ... - def categoryUpdated(self, category: QPlaceCategory, parentId: str) -> None: ... - def categoryAdded(self, category: QPlaceCategory, parentId: str) -> None: ... - def placeRemoved(self, placeId: str) -> None: ... - def placeUpdated(self, placeId: str) -> None: ... - def placeAdded(self, placeId: str) -> None: ... - def error(self, a0: QPlaceReply, error: QPlaceReply.Error, errorString: str = ...) -> None: ... - def finished(self, reply: QPlaceReply) -> None: ... + dataChanged: typing.ClassVar[QtCore.pyqtSignal] + categoryRemoved: typing.ClassVar[QtCore.pyqtSignal] + categoryUpdated: typing.ClassVar[QtCore.pyqtSignal] + categoryAdded: typing.ClassVar[QtCore.pyqtSignal] + placeRemoved: typing.ClassVar[QtCore.pyqtSignal] + placeUpdated: typing.ClassVar[QtCore.pyqtSignal] + placeAdded: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def matchingPlaces(self, request: 'QPlaceMatchRequest') -> 'QPlaceMatchReply': ... def compatiblePlace(self, place: QPlace) -> QPlace: ... def setLocales(self, locale: typing.Iterable[QtCore.QLocale]) -> None: ... @@ -1097,15 +1220,15 @@ class QPlaceManagerEngine(QtCore.QObject): def __init__(self, parameters: typing.Dict[str, typing.Any], parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def manager(self) -> QPlaceManager: ... - def dataChanged(self) -> None: ... - def categoryRemoved(self, categoryId: str, parentCategoryId: str) -> None: ... - def categoryUpdated(self, category: QPlaceCategory, parentCategoryId: str) -> None: ... - def categoryAdded(self, category: QPlaceCategory, parentCategoryId: str) -> None: ... - def placeRemoved(self, placeId: str) -> None: ... - def placeUpdated(self, placeId: str) -> None: ... - def placeAdded(self, placeId: str) -> None: ... - def error(self, a0: QPlaceReply, error: QPlaceReply.Error, errorString: str = ...) -> None: ... - def finished(self, reply: QPlaceReply) -> None: ... + dataChanged: typing.ClassVar[QtCore.pyqtSignal] + categoryRemoved: typing.ClassVar[QtCore.pyqtSignal] + categoryUpdated: typing.ClassVar[QtCore.pyqtSignal] + categoryAdded: typing.ClassVar[QtCore.pyqtSignal] + placeRemoved: typing.ClassVar[QtCore.pyqtSignal] + placeUpdated: typing.ClassVar[QtCore.pyqtSignal] + placeAdded: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def matchingPlaces(self, request: 'QPlaceMatchRequest') -> 'QPlaceMatchReply': ... def compatiblePlace(self, original: QPlace) -> QPlace: ... def constructIconUrl(self, icon: QPlaceIcon, size: QtCore.QSize) -> QtCore.QUrl: ... diff --git a/PyQt5-stubs/QtMultimedia.pyi b/PyQt5-stubs/QtMultimedia.pyi index e574b8cd..66b8b3f3 100644 --- a/PyQt5-stubs/QtMultimedia.pyi +++ b/PyQt5-stubs/QtMultimedia.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtMultimedia module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -84,6 +84,9 @@ class QAbstractVideoBuffer(sip.simplewrapper): class QVideoFilterRunnable(sip.simplewrapper): class RunFlag(int): + def __or__ (self, other: 'QVideoFilterRunnable.RunFlag') -> 'QVideoFilterRunnable.RunFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QVideoFilterRunnable.RunFlags': ... # type: ignore[override, misc] + LastInChain = ... # type: QVideoFilterRunnable.RunFlag LastInChain = ... # type: QVideoFilterRunnable.RunFlag @@ -96,12 +99,20 @@ class QVideoFilterRunnable(sip.simplewrapper): def __init__(self, f: typing.Union['QVideoFilterRunnable.RunFlags', 'QVideoFilterRunnable.RunFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QVideoFilterRunnable.RunFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QVideoFilterRunnable.RunFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QVideoFilterRunnable.RunFlags', 'QVideoFilterRunnable.RunFlag', int]) -> 'QVideoFilterRunnable.RunFlags': ... + def __and__(self, other: typing.Union['QVideoFilterRunnable.RunFlags', 'QVideoFilterRunnable.RunFlag', int]) -> 'QVideoFilterRunnable.RunFlags': ... + def __xor__(self, other: typing.Union['QVideoFilterRunnable.RunFlags', 'QVideoFilterRunnable.RunFlag', int]) -> 'QVideoFilterRunnable.RunFlags': ... + def __ror__ (self, other: 'QVideoFilterRunnable.RunFlag') -> 'QVideoFilterRunnable.RunFlags': ... + def __rand__(self, other: 'QVideoFilterRunnable.RunFlag') -> 'QVideoFilterRunnable.RunFlags': ... + def __rxor__(self, other: 'QVideoFilterRunnable.RunFlag') -> 'QVideoFilterRunnable.RunFlags': ... @typing.overload def __init__(self) -> None: ... @@ -115,7 +126,7 @@ class QAbstractVideoFilter(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def activeChanged(self) -> None: ... + activeChanged: typing.ClassVar[QtCore.pyqtSignal] def createFilterRunnable(self) -> QVideoFilterRunnable: ... def isActive(self) -> bool: ... @@ -137,13 +148,13 @@ class QAbstractVideoSurface(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def nativeResolutionChanged(self, a0: QtCore.QSize) -> None: ... + nativeResolutionChanged: typing.ClassVar[QtCore.pyqtSignal] def setNativeResolution(self, resolution: QtCore.QSize) -> None: ... def nativeResolution(self) -> QtCore.QSize: ... def setError(self, error: 'QAbstractVideoSurface.Error') -> None: ... - def supportedFormatsChanged(self) -> None: ... - def surfaceFormatChanged(self, format: 'QVideoSurfaceFormat') -> None: ... - def activeChanged(self, active: bool) -> None: ... + supportedFormatsChanged: typing.ClassVar[QtCore.pyqtSignal] + surfaceFormatChanged: typing.ClassVar[QtCore.pyqtSignal] + activeChanged: typing.ClassVar[QtCore.pyqtSignal] def error(self) -> 'QAbstractVideoSurface.Error': ... def present(self, frame: 'QVideoFrame') -> bool: ... def isActive(self) -> bool: ... @@ -257,16 +268,10 @@ class QMediaObject(QtCore.QObject): def removePropertyWatch(self, name: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... def addPropertyWatch(self, name: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - @typing.overload - def availabilityChanged(self, availability: 'QMultimedia.AvailabilityStatus') -> None: ... - @typing.overload - def availabilityChanged(self, available: bool) -> None: ... - @typing.overload - def metaDataChanged(self) -> None: ... - @typing.overload - def metaDataChanged(self, key: str, value: typing.Any) -> None: ... - def metaDataAvailableChanged(self, available: bool) -> None: ... - def notifyIntervalChanged(self, milliSeconds: int) -> None: ... + availabilityChanged: typing.ClassVar[QtCore.pyqtSignal] + metaDataChanged: typing.ClassVar[QtCore.pyqtSignal] + metaDataAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] + notifyIntervalChanged: typing.ClassVar[QtCore.pyqtSignal] def availableMetaData(self) -> typing.List[str]: ... def metaData(self, key: str) -> typing.Any: ... def isMetaDataAvailable(self) -> bool: ... @@ -305,14 +310,14 @@ class QAudioDecoder(QMediaObject): def unbind(self, a0: QtCore.QObject) -> None: ... def bind(self, a0: QtCore.QObject) -> bool: ... - def durationChanged(self, duration: int) -> None: ... - def positionChanged(self, position: int) -> None: ... - def sourceChanged(self) -> None: ... - def formatChanged(self, format: 'QAudioFormat') -> None: ... - def stateChanged(self, newState: 'QAudioDecoder.State') -> None: ... - def finished(self) -> None: ... - def bufferReady(self) -> None: ... - def bufferAvailableChanged(self, a0: bool) -> None: ... + durationChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] + formatChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] + bufferReady: typing.ClassVar[QtCore.pyqtSignal] + bufferAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] def stop(self) -> None: ... def start(self) -> None: ... def duration(self) -> int: ... @@ -320,10 +325,7 @@ class QAudioDecoder(QMediaObject): def bufferAvailable(self) -> bool: ... def read(self) -> QAudioBuffer: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QAudioDecoder.Error': ... - @typing.overload - def error(self, error: 'QAudioDecoder.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def setAudioFormat(self, format: 'QAudioFormat') -> None: ... def audioFormat(self) -> 'QAudioFormat': ... def setSourceDevice(self, device: QtCore.QIODevice) -> None: ... @@ -344,15 +346,15 @@ class QAudioDecoderControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def durationChanged(self, duration: int) -> None: ... - def positionChanged(self, position: int) -> None: ... - def finished(self) -> None: ... - def bufferAvailableChanged(self, available: bool) -> None: ... - def bufferReady(self) -> None: ... - def error(self, error: int, errorString: str) -> None: ... - def sourceChanged(self) -> None: ... - def formatChanged(self, format: 'QAudioFormat') -> None: ... - def stateChanged(self, newState: QAudioDecoder.State) -> None: ... + durationChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] + bufferAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] + bufferReady: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] + formatChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def duration(self) -> int: ... def position(self) -> int: ... def bufferAvailable(self) -> bool: ... @@ -462,8 +464,8 @@ class QAudioInput(QtCore.QObject): def volume(self) -> float: ... def setVolume(self, volume: float) -> None: ... - def notify(self) -> None: ... - def stateChanged(self, a0: QAudio.State) -> None: ... + notify: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def state(self) -> QAudio.State: ... def error(self) -> QAudio.Error: ... def elapsedUSecs(self) -> int: ... @@ -489,8 +491,8 @@ class QAudioInputSelectorControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def availableInputsChanged(self) -> None: ... - def activeInputChanged(self, name: str) -> None: ... + availableInputsChanged: typing.ClassVar[QtCore.pyqtSignal] + activeInputChanged: typing.ClassVar[QtCore.pyqtSignal] def setActiveInput(self, name: str) -> None: ... def activeInput(self) -> str: ... def defaultInput(self) -> str: ... @@ -509,8 +511,8 @@ class QAudioOutput(QtCore.QObject): def category(self) -> str: ... def volume(self) -> float: ... def setVolume(self, a0: float) -> None: ... - def notify(self) -> None: ... - def stateChanged(self, a0: QAudio.State) -> None: ... + notify: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def state(self) -> QAudio.State: ... def error(self) -> QAudio.Error: ... def elapsedUSecs(self) -> int: ... @@ -536,8 +538,8 @@ class QAudioOutputSelectorControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def availableOutputsChanged(self) -> None: ... - def activeOutputChanged(self, name: str) -> None: ... + availableOutputsChanged: typing.ClassVar[QtCore.pyqtSignal] + activeOutputChanged: typing.ClassVar[QtCore.pyqtSignal] def setActiveOutput(self, name: str) -> None: ... def activeOutput(self) -> str: ... def defaultOutput(self) -> str: ... @@ -549,8 +551,8 @@ class QAudioProbe(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def flush(self) -> None: ... - def audioBufferProbed(self, audioBuffer: QAudioBuffer) -> None: ... + flush: typing.ClassVar[QtCore.pyqtSignal] + audioBufferProbed: typing.ClassVar[QtCore.pyqtSignal] def isActive(self) -> bool: ... @typing.overload def setSource(self, source: QMediaObject) -> bool: ... @@ -613,22 +615,16 @@ class QMediaRecorder(QtCore.QObject, QMediaBindableInterface): def __init__(self, mediaObject: QMediaObject, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def setMediaObject(self, object: QMediaObject) -> bool: ... - @typing.overload - def availabilityChanged(self, availability: 'QMultimedia.AvailabilityStatus') -> None: ... - @typing.overload - def availabilityChanged(self, available: bool) -> None: ... - @typing.overload - def metaDataChanged(self, key: str, value: typing.Any) -> None: ... - @typing.overload - def metaDataChanged(self) -> None: ... - def metaDataWritableChanged(self, writable: bool) -> None: ... - def metaDataAvailableChanged(self, available: bool) -> None: ... - def actualLocationChanged(self, location: QtCore.QUrl) -> None: ... - def volumeChanged(self, volume: float) -> None: ... - def mutedChanged(self, muted: bool) -> None: ... - def durationChanged(self, duration: int) -> None: ... - def statusChanged(self, status: 'QMediaRecorder.Status') -> None: ... - def stateChanged(self, state: 'QMediaRecorder.State') -> None: ... + availabilityChanged: typing.ClassVar[QtCore.pyqtSignal] + metaDataChanged: typing.ClassVar[QtCore.pyqtSignal] + metaDataWritableChanged: typing.ClassVar[QtCore.pyqtSignal] + metaDataAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] + actualLocationChanged: typing.ClassVar[QtCore.pyqtSignal] + volumeChanged: typing.ClassVar[QtCore.pyqtSignal] + mutedChanged: typing.ClassVar[QtCore.pyqtSignal] + durationChanged: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def setVolume(self, volume: float) -> None: ... def setMuted(self, muted: bool) -> None: ... def stop(self) -> None: ... @@ -659,10 +655,7 @@ class QMediaRecorder(QtCore.QObject, QMediaBindableInterface): def isMuted(self) -> bool: ... def duration(self) -> int: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QMediaRecorder.Error': ... - @typing.overload - def error(self, error: 'QMediaRecorder.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def status(self) -> 'QMediaRecorder.Status': ... def state(self) -> 'QMediaRecorder.State': ... def actualLocation(self) -> QtCore.QUrl: ... @@ -677,8 +670,8 @@ class QAudioRecorder(QMediaRecorder): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def availableAudioInputsChanged(self) -> None: ... - def audioInputChanged(self, name: str) -> None: ... + availableAudioInputsChanged: typing.ClassVar[QtCore.pyqtSignal] + audioInputChanged: typing.ClassVar[QtCore.pyqtSignal] def setAudioInput(self, name: str) -> None: ... def audioInput(self) -> str: ... def audioInputDescription(self, name: str) -> str: ... @@ -690,7 +683,7 @@ class QAudioRoleControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def audioRoleChanged(self, role: QAudio.Role) -> None: ... + audioRoleChanged: typing.ClassVar[QtCore.pyqtSignal] def supportedAudioRoles(self) -> typing.List[QAudio.Role]: ... def setAudioRole(self, role: QAudio.Role) -> None: ... def audioRole(self) -> QAudio.Role: ... @@ -708,6 +701,9 @@ class QCamera(QMediaObject): FrontFace = ... # type: QCamera.Position class LockType(int): + def __or__ (self, other: 'QCamera.LockType') -> 'QCamera.LockTypes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QCamera.LockTypes': ... # type: ignore[override, misc] + NoLock = ... # type: QCamera.LockType LockExposure = ... # type: QCamera.LockType LockWhiteBalance = ... # type: QCamera.LockType @@ -800,12 +796,20 @@ class QCamera(QMediaObject): def __init__(self, f: typing.Union['QCamera.CaptureModes', 'QCamera.CaptureMode']) -> None: ... @typing.overload def __init__(self, a0: 'QCamera.CaptureModes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QCamera.CaptureModes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QCamera.CaptureModes', 'QCamera.CaptureMode', int]) -> 'QCamera.CaptureModes': ... + def __and__(self, other: typing.Union['QCamera.CaptureModes', 'QCamera.CaptureMode', int]) -> 'QCamera.CaptureModes': ... + def __xor__(self, other: typing.Union['QCamera.CaptureModes', 'QCamera.CaptureMode', int]) -> 'QCamera.CaptureModes': ... + def __ror__ (self, other: 'QCamera.CaptureMode') -> 'QCamera.CaptureModes': ... + def __rand__(self, other: 'QCamera.CaptureMode') -> 'QCamera.CaptureModes': ... + def __rxor__(self, other: 'QCamera.CaptureMode') -> 'QCamera.CaptureModes': ... class LockTypes(sip.simplewrapper): @@ -815,12 +819,20 @@ class QCamera(QMediaObject): def __init__(self, f: typing.Union['QCamera.LockTypes', 'QCamera.LockType']) -> None: ... @typing.overload def __init__(self, a0: 'QCamera.LockTypes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QCamera.LockTypes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QCamera.LockTypes', 'QCamera.LockType', int]) -> 'QCamera.LockTypes': ... + def __and__(self, other: typing.Union['QCamera.LockTypes', 'QCamera.LockType', int]) -> 'QCamera.LockTypes': ... + def __xor__(self, other: typing.Union['QCamera.LockTypes', 'QCamera.LockType', int]) -> 'QCamera.LockTypes': ... + def __ror__ (self, other: 'QCamera.LockType') -> 'QCamera.LockTypes': ... + def __rand__(self, other: 'QCamera.LockType') -> 'QCamera.LockTypes': ... + def __rxor__(self, other: 'QCamera.LockType') -> 'QCamera.LockTypes': ... class FrameRateRange(sip.simplewrapper): @@ -849,16 +861,13 @@ class QCamera(QMediaObject): def supportedViewfinderSettings(self, settings: 'QCameraViewfinderSettings' = ...) -> typing.List['QCameraViewfinderSettings']: ... def setViewfinderSettings(self, settings: 'QCameraViewfinderSettings') -> None: ... def viewfinderSettings(self) -> 'QCameraViewfinderSettings': ... - def errorOccurred(self, a0: 'QCamera.Error') -> None: ... - @typing.overload - def lockStatusChanged(self, a0: 'QCamera.LockStatus', a1: 'QCamera.LockChangeReason') -> None: ... - @typing.overload - def lockStatusChanged(self, a0: 'QCamera.LockType', a1: 'QCamera.LockStatus', a2: 'QCamera.LockChangeReason') -> None: ... - def lockFailed(self) -> None: ... - def locked(self) -> None: ... - def statusChanged(self, a0: 'QCamera.Status') -> None: ... - def captureModeChanged(self, a0: typing.Union['QCamera.CaptureModes', 'QCamera.CaptureMode']) -> None: ... - def stateChanged(self, a0: 'QCamera.State') -> None: ... + errorOccurred: typing.ClassVar[QtCore.pyqtSignal] + lockStatusChanged: typing.ClassVar[QtCore.pyqtSignal] + lockFailed: typing.ClassVar[QtCore.pyqtSignal] + locked: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + captureModeChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def unlock(self) -> None: ... @typing.overload @@ -879,10 +888,7 @@ class QCamera(QMediaObject): def requestedLocks(self) -> 'QCamera.LockTypes': ... def supportedLocks(self) -> 'QCamera.LockTypes': ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QCamera.Error': ... - @typing.overload - def error(self, a0: 'QCamera.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def setViewfinder(self, viewfinder: QtMultimediaWidgets.QVideoWidget) -> None: ... @typing.overload @@ -907,7 +913,7 @@ class QCameraCaptureBufferFormatControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def bufferFormatChanged(self, format: 'QVideoFrame.PixelFormat') -> None: ... + bufferFormatChanged: typing.ClassVar[QtCore.pyqtSignal] def setBufferFormat(self, format: 'QVideoFrame.PixelFormat') -> None: ... def bufferFormat(self) -> 'QVideoFrame.PixelFormat': ... def supportedBufferFormats(self) -> typing.List['QVideoFrame.PixelFormat']: ... @@ -917,7 +923,7 @@ class QCameraCaptureDestinationControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def captureDestinationChanged(self, destination: typing.Union['QCameraImageCapture.CaptureDestinations', 'QCameraImageCapture.CaptureDestination']) -> None: ... + captureDestinationChanged: typing.ClassVar[QtCore.pyqtSignal] def setCaptureDestination(self, destination: typing.Union['QCameraImageCapture.CaptureDestinations', 'QCameraImageCapture.CaptureDestination']) -> None: ... def captureDestination(self) -> 'QCameraImageCapture.CaptureDestinations': ... def isCaptureDestinationSupported(self, destination: typing.Union['QCameraImageCapture.CaptureDestinations', 'QCameraImageCapture.CaptureDestination']) -> bool: ... @@ -940,10 +946,10 @@ class QCameraControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def captureModeChanged(self, mode: typing.Union[QCamera.CaptureModes, QCamera.CaptureMode]) -> None: ... - def error(self, error: int, errorString: str) -> None: ... - def statusChanged(self, a0: QCamera.Status) -> None: ... - def stateChanged(self, a0: QCamera.State) -> None: ... + captureModeChanged: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def canChangeProperty(self, changeType: 'QCameraControl.PropertyChangeType', status: QCamera.Status) -> bool: ... def isCaptureModeSupported(self, mode: typing.Union[QCamera.CaptureModes, QCamera.CaptureMode]) -> bool: ... def setCaptureMode(self, a0: typing.Union[QCamera.CaptureModes, QCamera.CaptureMode]) -> None: ... @@ -1012,6 +1018,9 @@ class QCameraExposure(QtCore.QObject): ExposureModeVendor = ... # type: QCameraExposure.ExposureMode class FlashMode(int): + def __or__ (self, other: 'QCameraExposure.FlashMode') -> 'QCameraExposure.FlashModes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QCameraExposure.FlashModes': ... # type: ignore[override, misc] + FlashAuto = ... # type: QCameraExposure.FlashMode FlashOff = ... # type: QCameraExposure.FlashMode FlashOn = ... # type: QCameraExposure.FlashMode @@ -1042,20 +1051,28 @@ class QCameraExposure(QtCore.QObject): def __init__(self, f: typing.Union['QCameraExposure.FlashModes', 'QCameraExposure.FlashMode']) -> None: ... @typing.overload def __init__(self, a0: 'QCameraExposure.FlashModes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QCameraExposure.FlashModes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... - - def exposureCompensationChanged(self, a0: float) -> None: ... - def isoSensitivityChanged(self, a0: int) -> None: ... - def shutterSpeedRangeChanged(self) -> None: ... - def shutterSpeedChanged(self, a0: float) -> None: ... - def apertureRangeChanged(self) -> None: ... - def apertureChanged(self, a0: float) -> None: ... - def flashReady(self, a0: bool) -> None: ... + def __or__ (self, other: typing.Union['QCameraExposure.FlashModes', 'QCameraExposure.FlashMode', int]) -> 'QCameraExposure.FlashModes': ... + def __and__(self, other: typing.Union['QCameraExposure.FlashModes', 'QCameraExposure.FlashMode', int]) -> 'QCameraExposure.FlashModes': ... + def __xor__(self, other: typing.Union['QCameraExposure.FlashModes', 'QCameraExposure.FlashMode', int]) -> 'QCameraExposure.FlashModes': ... + def __ror__ (self, other: 'QCameraExposure.FlashMode') -> 'QCameraExposure.FlashModes': ... + def __rand__(self, other: 'QCameraExposure.FlashMode') -> 'QCameraExposure.FlashModes': ... + def __rxor__(self, other: 'QCameraExposure.FlashMode') -> 'QCameraExposure.FlashModes': ... + + exposureCompensationChanged: typing.ClassVar[QtCore.pyqtSignal] + isoSensitivityChanged: typing.ClassVar[QtCore.pyqtSignal] + shutterSpeedRangeChanged: typing.ClassVar[QtCore.pyqtSignal] + shutterSpeedChanged: typing.ClassVar[QtCore.pyqtSignal] + apertureRangeChanged: typing.ClassVar[QtCore.pyqtSignal] + apertureChanged: typing.ClassVar[QtCore.pyqtSignal] + flashReady: typing.ClassVar[QtCore.pyqtSignal] def setAutoShutterSpeed(self) -> None: ... def setManualShutterSpeed(self, seconds: float) -> None: ... def setAutoAperture(self) -> None: ... @@ -1117,9 +1134,9 @@ class QCameraExposureControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def parameterRangeChanged(self, parameter: int) -> None: ... - def actualValueChanged(self, parameter: int) -> None: ... - def requestedValueChanged(self, parameter: int) -> None: ... + parameterRangeChanged: typing.ClassVar[QtCore.pyqtSignal] + actualValueChanged: typing.ClassVar[QtCore.pyqtSignal] + requestedValueChanged: typing.ClassVar[QtCore.pyqtSignal] def setValue(self, parameter: 'QCameraExposureControl.ExposureParameter', value: typing.Any) -> bool: ... def actualValue(self, parameter: 'QCameraExposureControl.ExposureParameter') -> typing.Any: ... def requestedValue(self, parameter: 'QCameraExposureControl.ExposureParameter') -> typing.Any: ... @@ -1167,7 +1184,7 @@ class QCameraFlashControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def flashReady(self, a0: bool) -> None: ... + flashReady: typing.ClassVar[QtCore.pyqtSignal] def isFlashReady(self) -> bool: ... def isFlashModeSupported(self, mode: typing.Union[QCameraExposure.FlashModes, QCameraExposure.FlashMode]) -> bool: ... def setFlashMode(self, mode: typing.Union[QCameraExposure.FlashModes, QCameraExposure.FlashMode]) -> None: ... @@ -1208,6 +1225,9 @@ class QCameraFocus(QtCore.QObject): FocusPointCustom = ... # type: QCameraFocus.FocusPointMode class FocusMode(int): + def __or__ (self, other: 'QCameraFocus.FocusMode') -> 'QCameraFocus.FocusModes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QCameraFocus.FocusModes': ... # type: ignore[override, misc] + ManualFocus = ... # type: QCameraFocus.FocusMode HyperfocalFocus = ... # type: QCameraFocus.FocusMode InfinityFocus = ... # type: QCameraFocus.FocusMode @@ -1230,18 +1250,26 @@ class QCameraFocus(QtCore.QObject): def __init__(self, f: typing.Union['QCameraFocus.FocusModes', 'QCameraFocus.FocusMode']) -> None: ... @typing.overload def __init__(self, a0: 'QCameraFocus.FocusModes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QCameraFocus.FocusModes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... - - def maximumDigitalZoomChanged(self, a0: float) -> None: ... - def maximumOpticalZoomChanged(self, a0: float) -> None: ... - def focusZonesChanged(self) -> None: ... - def digitalZoomChanged(self, a0: float) -> None: ... - def opticalZoomChanged(self, a0: float) -> None: ... + def __or__ (self, other: typing.Union['QCameraFocus.FocusModes', 'QCameraFocus.FocusMode', int]) -> 'QCameraFocus.FocusModes': ... + def __and__(self, other: typing.Union['QCameraFocus.FocusModes', 'QCameraFocus.FocusMode', int]) -> 'QCameraFocus.FocusModes': ... + def __xor__(self, other: typing.Union['QCameraFocus.FocusModes', 'QCameraFocus.FocusMode', int]) -> 'QCameraFocus.FocusModes': ... + def __ror__ (self, other: 'QCameraFocus.FocusMode') -> 'QCameraFocus.FocusModes': ... + def __rand__(self, other: 'QCameraFocus.FocusMode') -> 'QCameraFocus.FocusModes': ... + def __rxor__(self, other: 'QCameraFocus.FocusMode') -> 'QCameraFocus.FocusModes': ... + + maximumDigitalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] + maximumOpticalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] + focusZonesChanged: typing.ClassVar[QtCore.pyqtSignal] + digitalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] + opticalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] def zoomTo(self, opticalZoom: float, digitalZoom: float) -> None: ... def digitalZoom(self) -> float: ... def opticalZoom(self) -> float: ... @@ -1263,10 +1291,10 @@ class QCameraFocusControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def focusZonesChanged(self) -> None: ... - def customFocusPointChanged(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... - def focusPointModeChanged(self, mode: QCameraFocus.FocusPointMode) -> None: ... - def focusModeChanged(self, mode: typing.Union[QCameraFocus.FocusModes, QCameraFocus.FocusMode]) -> None: ... + focusZonesChanged: typing.ClassVar[QtCore.pyqtSignal] + customFocusPointChanged: typing.ClassVar[QtCore.pyqtSignal] + focusPointModeChanged: typing.ClassVar[QtCore.pyqtSignal] + focusModeChanged: typing.ClassVar[QtCore.pyqtSignal] def focusZones(self) -> typing.List[QCameraFocusZone]: ... def setCustomFocusPoint(self, point: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... def customFocusPoint(self) -> QtCore.QPointF: ... @@ -1281,6 +1309,9 @@ class QCameraFocusControl(QMediaControl): class QCameraImageCapture(QtCore.QObject, QMediaBindableInterface): class CaptureDestination(int): + def __or__ (self, other: 'QCameraImageCapture.CaptureDestination') -> 'QCameraImageCapture.CaptureDestinations': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QCameraImageCapture.CaptureDestinations': ... # type: ignore[override, misc] + CaptureToFile = ... # type: QCameraImageCapture.CaptureDestination CaptureToBuffer = ... # type: QCameraImageCapture.CaptureDestination @@ -1315,24 +1346,32 @@ class QCameraImageCapture(QtCore.QObject, QMediaBindableInterface): def __init__(self, f: typing.Union['QCameraImageCapture.CaptureDestinations', 'QCameraImageCapture.CaptureDestination']) -> None: ... @typing.overload def __init__(self, a0: 'QCameraImageCapture.CaptureDestinations') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QCameraImageCapture.CaptureDestinations': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QCameraImageCapture.CaptureDestinations', 'QCameraImageCapture.CaptureDestination', int]) -> 'QCameraImageCapture.CaptureDestinations': ... + def __and__(self, other: typing.Union['QCameraImageCapture.CaptureDestinations', 'QCameraImageCapture.CaptureDestination', int]) -> 'QCameraImageCapture.CaptureDestinations': ... + def __xor__(self, other: typing.Union['QCameraImageCapture.CaptureDestinations', 'QCameraImageCapture.CaptureDestination', int]) -> 'QCameraImageCapture.CaptureDestinations': ... + def __ror__ (self, other: 'QCameraImageCapture.CaptureDestination') -> 'QCameraImageCapture.CaptureDestinations': ... + def __rand__(self, other: 'QCameraImageCapture.CaptureDestination') -> 'QCameraImageCapture.CaptureDestinations': ... + def __rxor__(self, other: 'QCameraImageCapture.CaptureDestination') -> 'QCameraImageCapture.CaptureDestinations': ... def __init__(self, mediaObject: QMediaObject, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def setMediaObject(self, a0: QMediaObject) -> bool: ... - def imageSaved(self, id: int, fileName: str) -> None: ... - def imageAvailable(self, id: int, image: 'QVideoFrame') -> None: ... - def imageMetadataAvailable(self, id: int, key: str, value: typing.Any) -> None: ... - def imageCaptured(self, id: int, preview: QtGui.QImage) -> None: ... - def imageExposed(self, id: int) -> None: ... - def captureDestinationChanged(self, a0: typing.Union['QCameraImageCapture.CaptureDestinations', 'QCameraImageCapture.CaptureDestination']) -> None: ... - def bufferFormatChanged(self, a0: 'QVideoFrame.PixelFormat') -> None: ... - def readyForCaptureChanged(self, a0: bool) -> None: ... + imageSaved: typing.ClassVar[QtCore.pyqtSignal] + imageAvailable: typing.ClassVar[QtCore.pyqtSignal] + imageMetadataAvailable: typing.ClassVar[QtCore.pyqtSignal] + imageCaptured: typing.ClassVar[QtCore.pyqtSignal] + imageExposed: typing.ClassVar[QtCore.pyqtSignal] + captureDestinationChanged: typing.ClassVar[QtCore.pyqtSignal] + bufferFormatChanged: typing.ClassVar[QtCore.pyqtSignal] + readyForCaptureChanged: typing.ClassVar[QtCore.pyqtSignal] def cancelCapture(self) -> None: ... def capture(self, file: str = ...) -> int: ... def setCaptureDestination(self, destination: typing.Union['QCameraImageCapture.CaptureDestinations', 'QCameraImageCapture.CaptureDestination']) -> None: ... @@ -1348,10 +1387,7 @@ class QCameraImageCapture(QtCore.QObject, QMediaBindableInterface): def supportedImageCodecs(self) -> typing.List[str]: ... def isReadyForCapture(self) -> bool: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QCameraImageCapture.Error': ... - @typing.overload - def error(self, id: int, error: 'QCameraImageCapture.Error', errorString: str) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def mediaObject(self) -> QMediaObject: ... def availability(self) -> 'QMultimedia.AvailabilityStatus': ... def isAvailable(self) -> bool: ... @@ -1361,13 +1397,13 @@ class QCameraImageCaptureControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def error(self, id: int, error: int, errorString: str) -> None: ... - def imageSaved(self, requestId: int, fileName: str) -> None: ... - def imageAvailable(self, requestId: int, buffer: 'QVideoFrame') -> None: ... - def imageMetadataAvailable(self, id: int, key: str, value: typing.Any) -> None: ... - def imageCaptured(self, requestId: int, preview: QtGui.QImage) -> None: ... - def imageExposed(self, requestId: int) -> None: ... - def readyForCaptureChanged(self, ready: bool) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] + imageSaved: typing.ClassVar[QtCore.pyqtSignal] + imageAvailable: typing.ClassVar[QtCore.pyqtSignal] + imageMetadataAvailable: typing.ClassVar[QtCore.pyqtSignal] + imageCaptured: typing.ClassVar[QtCore.pyqtSignal] + imageExposed: typing.ClassVar[QtCore.pyqtSignal] + readyForCaptureChanged: typing.ClassVar[QtCore.pyqtSignal] def cancelCapture(self) -> None: ... def capture(self, fileName: str) -> int: ... def setDriveMode(self, mode: QCameraImageCapture.DriveMode) -> None: ... @@ -1517,7 +1553,7 @@ class QCameraLocksControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def lockStatusChanged(self, type: QCamera.LockType, status: QCamera.LockStatus, reason: QCamera.LockChangeReason) -> None: ... + lockStatusChanged: typing.ClassVar[QtCore.pyqtSignal] def unlock(self, locks: typing.Union[QCamera.LockTypes, QCamera.LockType]) -> None: ... def searchAndLock(self, locks: typing.Union[QCamera.LockTypes, QCamera.LockType]) -> None: ... def lockStatus(self, lock: QCamera.LockType) -> QCamera.LockStatus: ... @@ -1588,12 +1624,12 @@ class QCameraZoomControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def currentDigitalZoomChanged(self, digitalZoom: float) -> None: ... - def currentOpticalZoomChanged(self, opticalZoom: float) -> None: ... - def requestedDigitalZoomChanged(self, digitalZoom: float) -> None: ... - def requestedOpticalZoomChanged(self, opticalZoom: float) -> None: ... - def maximumDigitalZoomChanged(self, a0: float) -> None: ... - def maximumOpticalZoomChanged(self, a0: float) -> None: ... + currentDigitalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] + currentOpticalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] + requestedDigitalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] + requestedOpticalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] + maximumDigitalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] + maximumOpticalZoomChanged: typing.ClassVar[QtCore.pyqtSignal] def zoomTo(self, optical: float, digital: float) -> None: ... def currentDigitalZoom(self) -> float: ... def currentOpticalZoom(self) -> float: ... @@ -1607,7 +1643,7 @@ class QCustomAudioRoleControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def customAudioRoleChanged(self, role: str) -> None: ... + customAudioRoleChanged: typing.ClassVar[QtCore.pyqtSignal] def supportedCustomAudioRoles(self) -> typing.List[str]: ... def setCustomAudioRole(self, role: str) -> None: ... def customAudioRole(self) -> str: ... @@ -1628,15 +1664,15 @@ class QMediaAudioProbeControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def flush(self) -> None: ... - def audioBufferProbed(self, buffer: QAudioBuffer) -> None: ... + flush: typing.ClassVar[QtCore.pyqtSignal] + audioBufferProbed: typing.ClassVar[QtCore.pyqtSignal] class QMediaAvailabilityControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def availabilityChanged(self, availability: 'QMultimedia.AvailabilityStatus') -> None: ... + availabilityChanged: typing.ClassVar[QtCore.pyqtSignal] def availability(self) -> 'QMultimedia.AvailabilityStatus': ... @@ -1758,9 +1794,9 @@ class QMediaGaplessPlaybackControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def advancedToNextMedia(self) -> None: ... - def nextMediaChanged(self, media: QMediaContent) -> None: ... - def crossfadeTimeChanged(self, crossfadeTime: float) -> None: ... + advancedToNextMedia: typing.ClassVar[QtCore.pyqtSignal] + nextMediaChanged: typing.ClassVar[QtCore.pyqtSignal] + crossfadeTimeChanged: typing.ClassVar[QtCore.pyqtSignal] def setCrossfadeTime(self, crossfadeTime: float) -> None: ... def crossfadeTime(self) -> float: ... def isCrossfadeSupported(self) -> bool: ... @@ -1867,7 +1903,7 @@ class QMediaNetworkAccessControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def configurationChanged(self, configuration: QtNetwork.QNetworkConfiguration) -> None: ... + configurationChanged: typing.ClassVar[QtCore.pyqtSignal] def currentConfiguration(self) -> QtNetwork.QNetworkConfiguration: ... def setConfigurations(self, configuration: typing.Iterable[QtNetwork.QNetworkConfiguration]) -> None: ... @@ -1936,39 +1972,47 @@ class QMediaPlayer(QMediaObject): def __init__(self, f: typing.Union['QMediaPlayer.Flags', 'QMediaPlayer.Flag']) -> None: ... @typing.overload def __init__(self, a0: 'QMediaPlayer.Flags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QMediaPlayer.Flags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QMediaPlayer.Flags', 'QMediaPlayer.Flag', int]) -> 'QMediaPlayer.Flags': ... + def __and__(self, other: typing.Union['QMediaPlayer.Flags', 'QMediaPlayer.Flag', int]) -> 'QMediaPlayer.Flags': ... + def __xor__(self, other: typing.Union['QMediaPlayer.Flags', 'QMediaPlayer.Flag', int]) -> 'QMediaPlayer.Flags': ... + def __ror__ (self, other: 'QMediaPlayer.Flag') -> 'QMediaPlayer.Flags': ... + def __rand__(self, other: 'QMediaPlayer.Flag') -> 'QMediaPlayer.Flags': ... + def __rxor__(self, other: 'QMediaPlayer.Flag') -> 'QMediaPlayer.Flags': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ..., flags: typing.Union['QMediaPlayer.Flags', 'QMediaPlayer.Flag'] = ...) -> None: ... - def customAudioRoleChanged(self, role: str) -> None: ... + customAudioRoleChanged: typing.ClassVar[QtCore.pyqtSignal] def supportedCustomAudioRoles(self) -> typing.List[str]: ... def setCustomAudioRole(self, audioRole: str) -> None: ... def customAudioRole(self) -> str: ... - def audioRoleChanged(self, role: QAudio.Role) -> None: ... + audioRoleChanged: typing.ClassVar[QtCore.pyqtSignal] def supportedAudioRoles(self) -> typing.List[QAudio.Role]: ... def setAudioRole(self, audioRole: QAudio.Role) -> None: ... def audioRole(self) -> QAudio.Role: ... def unbind(self, a0: QtCore.QObject) -> None: ... def bind(self, a0: QtCore.QObject) -> bool: ... - def networkConfigurationChanged(self, configuration: QtNetwork.QNetworkConfiguration) -> None: ... - def playbackRateChanged(self, rate: float) -> None: ... - def seekableChanged(self, seekable: bool) -> None: ... - def bufferStatusChanged(self, percentFilled: int) -> None: ... - def videoAvailableChanged(self, videoAvailable: bool) -> None: ... - def audioAvailableChanged(self, available: bool) -> None: ... - def mutedChanged(self, muted: bool) -> None: ... - def volumeChanged(self, volume: int) -> None: ... - def positionChanged(self, position: int) -> None: ... - def durationChanged(self, duration: int) -> None: ... - def mediaStatusChanged(self, status: 'QMediaPlayer.MediaStatus') -> None: ... - def stateChanged(self, newState: 'QMediaPlayer.State') -> None: ... - def currentMediaChanged(self, media: QMediaContent) -> None: ... - def mediaChanged(self, media: QMediaContent) -> None: ... + networkConfigurationChanged: typing.ClassVar[QtCore.pyqtSignal] + playbackRateChanged: typing.ClassVar[QtCore.pyqtSignal] + seekableChanged: typing.ClassVar[QtCore.pyqtSignal] + bufferStatusChanged: typing.ClassVar[QtCore.pyqtSignal] + videoAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] + audioAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] + mutedChanged: typing.ClassVar[QtCore.pyqtSignal] + volumeChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + durationChanged: typing.ClassVar[QtCore.pyqtSignal] + mediaStatusChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + currentMediaChanged: typing.ClassVar[QtCore.pyqtSignal] + mediaChanged: typing.ClassVar[QtCore.pyqtSignal] def setNetworkConfigurations(self, configurations: typing.Iterable[QtNetwork.QNetworkConfiguration]) -> None: ... def setPlaylist(self, playlist: 'QMediaPlaylist') -> None: ... def setMedia(self, media: QMediaContent, stream: typing.Optional[QtCore.QIODevice] = ...) -> None: ... @@ -1982,10 +2026,7 @@ class QMediaPlayer(QMediaObject): def availability(self) -> 'QMultimedia.AvailabilityStatus': ... def currentNetworkConfiguration(self) -> QtNetwork.QNetworkConfiguration: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QMediaPlayer.Error': ... - @typing.overload - def error(self, error: 'QMediaPlayer.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def playbackRate(self) -> float: ... def isSeekable(self) -> bool: ... def bufferStatus(self) -> int: ... @@ -2019,20 +2060,20 @@ class QMediaPlayerControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def error(self, error: int, errorString: str) -> None: ... - def playbackRateChanged(self, rate: float) -> None: ... - def availablePlaybackRangesChanged(self, ranges: 'QMediaTimeRange') -> None: ... - def seekableChanged(self, seekable: bool) -> None: ... - def bufferStatusChanged(self, percentFilled: int) -> None: ... - def videoAvailableChanged(self, videoAvailable: bool) -> None: ... - def audioAvailableChanged(self, audioAvailable: bool) -> None: ... - def mutedChanged(self, mute: bool) -> None: ... - def volumeChanged(self, volume: int) -> None: ... - def mediaStatusChanged(self, status: QMediaPlayer.MediaStatus) -> None: ... - def stateChanged(self, newState: QMediaPlayer.State) -> None: ... - def positionChanged(self, position: int) -> None: ... - def durationChanged(self, duration: int) -> None: ... - def mediaChanged(self, content: QMediaContent) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] + playbackRateChanged: typing.ClassVar[QtCore.pyqtSignal] + availablePlaybackRangesChanged: typing.ClassVar[QtCore.pyqtSignal] + seekableChanged: typing.ClassVar[QtCore.pyqtSignal] + bufferStatusChanged: typing.ClassVar[QtCore.pyqtSignal] + videoAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] + audioAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] + mutedChanged: typing.ClassVar[QtCore.pyqtSignal] + volumeChanged: typing.ClassVar[QtCore.pyqtSignal] + mediaStatusChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + positionChanged: typing.ClassVar[QtCore.pyqtSignal] + durationChanged: typing.ClassVar[QtCore.pyqtSignal] + mediaChanged: typing.ClassVar[QtCore.pyqtSignal] def stop(self) -> None: ... def pause(self) -> None: ... def play(self) -> None: ... @@ -2088,16 +2129,16 @@ class QMediaPlaylist(QtCore.QObject, QMediaBindableInterface): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def setMediaObject(self, object: QMediaObject) -> bool: ... - def loadFailed(self) -> None: ... - def loaded(self) -> None: ... - def mediaChanged(self, start: int, end: int) -> None: ... - def mediaRemoved(self, start: int, end: int) -> None: ... - def mediaAboutToBeRemoved(self, start: int, end: int) -> None: ... - def mediaInserted(self, start: int, end: int) -> None: ... - def mediaAboutToBeInserted(self, start: int, end: int) -> None: ... - def currentMediaChanged(self, a0: QMediaContent) -> None: ... - def playbackModeChanged(self, mode: 'QMediaPlaylist.PlaybackMode') -> None: ... - def currentIndexChanged(self, index: int) -> None: ... + loadFailed: typing.ClassVar[QtCore.pyqtSignal] + loaded: typing.ClassVar[QtCore.pyqtSignal] + mediaChanged: typing.ClassVar[QtCore.pyqtSignal] + mediaRemoved: typing.ClassVar[QtCore.pyqtSignal] + mediaAboutToBeRemoved: typing.ClassVar[QtCore.pyqtSignal] + mediaInserted: typing.ClassVar[QtCore.pyqtSignal] + mediaAboutToBeInserted: typing.ClassVar[QtCore.pyqtSignal] + currentMediaChanged: typing.ClassVar[QtCore.pyqtSignal] + playbackModeChanged: typing.ClassVar[QtCore.pyqtSignal] + currentIndexChanged: typing.ClassVar[QtCore.pyqtSignal] def setCurrentIndex(self, index: int) -> None: ... def previous(self) -> None: ... def next(self) -> None: ... @@ -2148,13 +2189,13 @@ class QMediaRecorderControl(QMediaControl): def setVolume(self, volume: float) -> None: ... def setMuted(self, muted: bool) -> None: ... def setState(self, state: QMediaRecorder.State) -> None: ... - def error(self, error: int, errorString: str) -> None: ... - def actualLocationChanged(self, location: QtCore.QUrl) -> None: ... - def volumeChanged(self, volume: float) -> None: ... - def mutedChanged(self, muted: bool) -> None: ... - def durationChanged(self, position: int) -> None: ... - def statusChanged(self, status: QMediaRecorder.Status) -> None: ... - def stateChanged(self, state: QMediaRecorder.State) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] + actualLocationChanged: typing.ClassVar[QtCore.pyqtSignal] + volumeChanged: typing.ClassVar[QtCore.pyqtSignal] + mutedChanged: typing.ClassVar[QtCore.pyqtSignal] + durationChanged: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def applySettings(self) -> None: ... def volume(self) -> float: ... def isMuted(self) -> bool: ... @@ -2228,8 +2269,8 @@ class QMediaStreamsControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def activeStreamsChanged(self) -> None: ... - def streamsChanged(self) -> None: ... + activeStreamsChanged: typing.ClassVar[QtCore.pyqtSignal] + streamsChanged: typing.ClassVar[QtCore.pyqtSignal] def setActive(self, streamNumber: int, state: bool) -> None: ... def isActive(self, streamNumber: int) -> bool: ... def metaData(self, streamNumber: int, key: str) -> typing.Any: ... @@ -2288,19 +2329,16 @@ class QMediaVideoProbeControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def flush(self) -> None: ... - def videoFrameProbed(self, frame: 'QVideoFrame') -> None: ... + flush: typing.ClassVar[QtCore.pyqtSignal] + videoFrameProbed: typing.ClassVar[QtCore.pyqtSignal] class QMetaDataReaderControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def metaDataAvailableChanged(self, available: bool) -> None: ... - @typing.overload - def metaDataChanged(self) -> None: ... - @typing.overload - def metaDataChanged(self, key: str, value: typing.Any) -> None: ... + metaDataAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] + metaDataChanged: typing.ClassVar[QtCore.pyqtSignal] def availableMetaData(self) -> typing.List[str]: ... def metaData(self, key: str) -> typing.Any: ... def isMetaDataAvailable(self) -> bool: ... @@ -2310,12 +2348,9 @@ class QMetaDataWriterControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def metaDataAvailableChanged(self, available: bool) -> None: ... - def writableChanged(self, writable: bool) -> None: ... - @typing.overload - def metaDataChanged(self) -> None: ... - @typing.overload - def metaDataChanged(self, key: str, value: typing.Any) -> None: ... + metaDataAvailableChanged: typing.ClassVar[QtCore.pyqtSignal] + writableChanged: typing.ClassVar[QtCore.pyqtSignal] + metaDataChanged: typing.ClassVar[QtCore.pyqtSignal] def availableMetaData(self) -> typing.List[str]: ... def setMetaData(self, key: str, value: typing.Any) -> None: ... def metaData(self, key: str) -> typing.Any: ... @@ -2487,18 +2522,15 @@ class QRadioData(QtCore.QObject, QMediaBindableInterface): def __init__(self, mediaObject: QMediaObject, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def setMediaObject(self, a0: QMediaObject) -> bool: ... - def alternativeFrequenciesEnabledChanged(self, enabled: bool) -> None: ... - def radioTextChanged(self, radioText: str) -> None: ... - def stationNameChanged(self, stationName: str) -> None: ... - def programTypeNameChanged(self, programTypeName: str) -> None: ... - def programTypeChanged(self, programType: 'QRadioData.ProgramType') -> None: ... - def stationIdChanged(self, stationId: str) -> None: ... + alternativeFrequenciesEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + radioTextChanged: typing.ClassVar[QtCore.pyqtSignal] + stationNameChanged: typing.ClassVar[QtCore.pyqtSignal] + programTypeNameChanged: typing.ClassVar[QtCore.pyqtSignal] + programTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + stationIdChanged: typing.ClassVar[QtCore.pyqtSignal] def setAlternativeFrequenciesEnabled(self, enabled: bool) -> None: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QRadioData.Error': ... - @typing.overload - def error(self, error: 'QRadioData.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def isAlternativeFrequenciesEnabled(self) -> bool: ... def radioText(self) -> str: ... def stationName(self) -> str: ... @@ -2513,17 +2545,14 @@ class QRadioDataControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def alternativeFrequenciesEnabledChanged(self, enabled: bool) -> None: ... - def radioTextChanged(self, radioText: str) -> None: ... - def stationNameChanged(self, stationName: str) -> None: ... - def programTypeNameChanged(self, programTypeName: str) -> None: ... - def programTypeChanged(self, programType: QRadioData.ProgramType) -> None: ... - def stationIdChanged(self, stationId: str) -> None: ... + alternativeFrequenciesEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + radioTextChanged: typing.ClassVar[QtCore.pyqtSignal] + stationNameChanged: typing.ClassVar[QtCore.pyqtSignal] + programTypeNameChanged: typing.ClassVar[QtCore.pyqtSignal] + programTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + stationIdChanged: typing.ClassVar[QtCore.pyqtSignal] def errorString(self) -> str: ... - @typing.overload - def error(self) -> QRadioData.Error: ... - @typing.overload - def error(self, err: QRadioData.Error) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def isAlternativeFrequenciesEnabled(self) -> bool: ... def setAlternativeFrequenciesEnabled(self, enabled: bool) -> None: ... def radioText(self) -> str: ... @@ -2584,16 +2613,16 @@ class QRadioTuner(QMediaObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def antennaConnectedChanged(self, connectionStatus: bool) -> None: ... - def stationFound(self, frequency: int, stationId: str) -> None: ... - def mutedChanged(self, muted: bool) -> None: ... - def volumeChanged(self, volume: int) -> None: ... - def signalStrengthChanged(self, signalStrength: int) -> None: ... - def searchingChanged(self, searching: bool) -> None: ... - def stereoStatusChanged(self, stereo: bool) -> None: ... - def frequencyChanged(self, frequency: int) -> None: ... - def bandChanged(self, band: 'QRadioTuner.Band') -> None: ... - def stateChanged(self, state: 'QRadioTuner.State') -> None: ... + antennaConnectedChanged: typing.ClassVar[QtCore.pyqtSignal] + stationFound: typing.ClassVar[QtCore.pyqtSignal] + mutedChanged: typing.ClassVar[QtCore.pyqtSignal] + volumeChanged: typing.ClassVar[QtCore.pyqtSignal] + signalStrengthChanged: typing.ClassVar[QtCore.pyqtSignal] + searchingChanged: typing.ClassVar[QtCore.pyqtSignal] + stereoStatusChanged: typing.ClassVar[QtCore.pyqtSignal] + frequencyChanged: typing.ClassVar[QtCore.pyqtSignal] + bandChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def stop(self) -> None: ... def start(self) -> None: ... def setMuted(self, muted: bool) -> None: ... @@ -2606,10 +2635,7 @@ class QRadioTuner(QMediaObject): def searchForward(self) -> None: ... def radioData(self) -> QRadioData: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QRadioTuner.Error': ... - @typing.overload - def error(self, error: 'QRadioTuner.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def isAntennaConnected(self) -> bool: ... def isSearching(self) -> bool: ... def isMuted(self) -> bool: ... @@ -2631,21 +2657,18 @@ class QRadioTunerControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def antennaConnectedChanged(self, connectionStatus: bool) -> None: ... - def stationFound(self, frequency: int, stationId: str) -> None: ... - def mutedChanged(self, muted: bool) -> None: ... - def volumeChanged(self, volume: int) -> None: ... - def signalStrengthChanged(self, signalStrength: int) -> None: ... - def searchingChanged(self, searching: bool) -> None: ... - def stereoStatusChanged(self, stereo: bool) -> None: ... - def frequencyChanged(self, frequency: int) -> None: ... - def bandChanged(self, band: QRadioTuner.Band) -> None: ... - def stateChanged(self, state: QRadioTuner.State) -> None: ... + antennaConnectedChanged: typing.ClassVar[QtCore.pyqtSignal] + stationFound: typing.ClassVar[QtCore.pyqtSignal] + mutedChanged: typing.ClassVar[QtCore.pyqtSignal] + volumeChanged: typing.ClassVar[QtCore.pyqtSignal] + signalStrengthChanged: typing.ClassVar[QtCore.pyqtSignal] + searchingChanged: typing.ClassVar[QtCore.pyqtSignal] + stereoStatusChanged: typing.ClassVar[QtCore.pyqtSignal] + frequencyChanged: typing.ClassVar[QtCore.pyqtSignal] + bandChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def errorString(self) -> str: ... - @typing.overload - def error(self) -> QRadioTuner.Error: ... - @typing.overload - def error(self, err: QRadioTuner.Error) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def stop(self) -> None: ... def start(self) -> None: ... def cancelSearch(self) -> None: ... @@ -2719,15 +2742,15 @@ class QSoundEffect(QtCore.QObject): def stop(self) -> None: ... def play(self) -> None: ... - def categoryChanged(self) -> None: ... - def statusChanged(self) -> None: ... - def playingChanged(self) -> None: ... - def loadedChanged(self) -> None: ... - def mutedChanged(self) -> None: ... - def volumeChanged(self) -> None: ... - def loopsRemainingChanged(self) -> None: ... - def loopCountChanged(self) -> None: ... - def sourceChanged(self) -> None: ... + categoryChanged: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + playingChanged: typing.ClassVar[QtCore.pyqtSignal] + loadedChanged: typing.ClassVar[QtCore.pyqtSignal] + mutedChanged: typing.ClassVar[QtCore.pyqtSignal] + volumeChanged: typing.ClassVar[QtCore.pyqtSignal] + loopsRemainingChanged: typing.ClassVar[QtCore.pyqtSignal] + loopCountChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceChanged: typing.ClassVar[QtCore.pyqtSignal] def setCategory(self, category: str) -> None: ... def category(self) -> str: ... def status(self) -> 'QSoundEffect.Status': ... @@ -2750,11 +2773,8 @@ class QVideoDeviceSelectorControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def devicesChanged(self) -> None: ... - @typing.overload - def selectedDeviceChanged(self, index: int) -> None: ... - @typing.overload - def selectedDeviceChanged(self, name: str) -> None: ... + devicesChanged: typing.ClassVar[QtCore.pyqtSignal] + selectedDeviceChanged: typing.ClassVar[QtCore.pyqtSignal] def setSelectedDevice(self, index: int) -> None: ... def selectedDevice(self) -> int: ... def defaultDevice(self) -> int: ... @@ -2918,8 +2938,8 @@ class QVideoProbe(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def flush(self) -> None: ... - def videoFrameProbed(self, videoFrame: QVideoFrame) -> None: ... + flush: typing.ClassVar[QtCore.pyqtSignal] + videoFrameProbed: typing.ClassVar[QtCore.pyqtSignal] def isActive(self) -> bool: ... @typing.overload def setSource(self, source: QMediaObject) -> bool: ... @@ -3001,12 +3021,12 @@ class QVideoWindowControl(QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def nativeSizeChanged(self) -> None: ... - def saturationChanged(self, saturation: int) -> None: ... - def hueChanged(self, hue: int) -> None: ... - def contrastChanged(self, contrast: int) -> None: ... - def brightnessChanged(self, brightness: int) -> None: ... - def fullScreenChanged(self, fullScreen: bool) -> None: ... + nativeSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + saturationChanged: typing.ClassVar[QtCore.pyqtSignal] + hueChanged: typing.ClassVar[QtCore.pyqtSignal] + contrastChanged: typing.ClassVar[QtCore.pyqtSignal] + brightnessChanged: typing.ClassVar[QtCore.pyqtSignal] + fullScreenChanged: typing.ClassVar[QtCore.pyqtSignal] def setSaturation(self, saturation: int) -> None: ... def saturation(self) -> int: ... def setHue(self, hue: int) -> None: ... diff --git a/PyQt5-stubs/QtMultimediaWidgets.pyi b/PyQt5-stubs/QtMultimediaWidgets.pyi index c7a0cc68..07c2dfe2 100644 --- a/PyQt5-stubs/QtMultimediaWidgets.pyi +++ b/PyQt5-stubs/QtMultimediaWidgets.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtMultimediaWidgets module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -53,11 +53,11 @@ class QVideoWidget(QtWidgets.QWidget, QtMultimedia.QMediaBindableInterface): def hideEvent(self, event: QtGui.QHideEvent) -> None: ... def showEvent(self, event: QtGui.QShowEvent) -> None: ... def event(self, event: QtCore.QEvent) -> bool: ... - def saturationChanged(self, saturation: int) -> None: ... - def hueChanged(self, hue: int) -> None: ... - def contrastChanged(self, contrast: int) -> None: ... - def brightnessChanged(self, brightness: int) -> None: ... - def fullScreenChanged(self, fullScreen: bool) -> None: ... + saturationChanged: typing.ClassVar[QtCore.pyqtSignal] + hueChanged: typing.ClassVar[QtCore.pyqtSignal] + contrastChanged: typing.ClassVar[QtCore.pyqtSignal] + brightnessChanged: typing.ClassVar[QtCore.pyqtSignal] + fullScreenChanged: typing.ClassVar[QtCore.pyqtSignal] def setSaturation(self, saturation: int) -> None: ... def setHue(self, hue: int) -> None: ... def setContrast(self, contrast: int) -> None: ... @@ -89,7 +89,7 @@ class QGraphicsVideoItem(QtWidgets.QGraphicsObject, QtMultimedia.QMediaBindableI def setMediaObject(self, object: QtMultimedia.QMediaObject) -> bool: ... def itemChange(self, change: QtWidgets.QGraphicsItem.GraphicsItemChange, value: typing.Any) -> typing.Any: ... def timerEvent(self, event: QtCore.QTimerEvent) -> None: ... - def nativeSizeChanged(self, size: QtCore.QSizeF) -> None: ... + nativeSizeChanged: typing.ClassVar[QtCore.pyqtSignal] def paint(self, painter: QtGui.QPainter, option: QtWidgets.QStyleOptionGraphicsItem, widget: typing.Optional[QtWidgets.QWidget] = ...) -> None: ... def boundingRect(self) -> QtCore.QRectF: ... def nativeSize(self) -> QtCore.QSizeF: ... @@ -106,11 +106,11 @@ class QVideoWidgetControl(QtMultimedia.QMediaControl): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def saturationChanged(self, saturation: int) -> None: ... - def hueChanged(self, hue: int) -> None: ... - def contrastChanged(self, contrast: int) -> None: ... - def brightnessChanged(self, brightness: int) -> None: ... - def fullScreenChanged(self, fullScreen: bool) -> None: ... + saturationChanged: typing.ClassVar[QtCore.pyqtSignal] + hueChanged: typing.ClassVar[QtCore.pyqtSignal] + contrastChanged: typing.ClassVar[QtCore.pyqtSignal] + brightnessChanged: typing.ClassVar[QtCore.pyqtSignal] + fullScreenChanged: typing.ClassVar[QtCore.pyqtSignal] def setSaturation(self, saturation: int) -> None: ... def saturation(self) -> int: ... def setHue(self, hue: int) -> None: ... diff --git a/PyQt5-stubs/QtNetwork.pyi b/PyQt5-stubs/QtNetwork.pyi index 4acd10cb..096f0489 100644 --- a/PyQt5-stubs/QtNetwork.pyi +++ b/PyQt5-stubs/QtNetwork.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtNetwork module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -91,6 +91,9 @@ class QAbstractNetworkCache(QtCore.QObject): class QAbstractSocket(QtCore.QIODevice): class PauseMode(int): + def __or__ (self, other: 'QAbstractSocket.PauseMode') -> 'QAbstractSocket.PauseModes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QAbstractSocket.PauseModes': ... # type: ignore[override, misc] + PauseNever = ... # type: QAbstractSocket.PauseMode PauseOnSslErrors = ... # type: QAbstractSocket.PauseMode @@ -98,6 +101,9 @@ class QAbstractSocket(QtCore.QIODevice): PauseOnSslErrors = ... # type: QAbstractSocket.PauseMode class BindFlag(int): + def __or__ (self, other: 'QAbstractSocket.BindFlag') -> 'QAbstractSocket.BindMode': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QAbstractSocket.BindMode': ... # type: ignore[override, misc] + DefaultForPlatform = ... # type: QAbstractSocket.BindFlag ShareAddress = ... # type: QAbstractSocket.BindFlag DontShareAddress = ... # type: QAbstractSocket.BindFlag @@ -225,12 +231,20 @@ class QAbstractSocket(QtCore.QIODevice): def __init__(self, f: typing.Union['QAbstractSocket.BindMode', 'QAbstractSocket.BindFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QAbstractSocket.BindMode') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QAbstractSocket.BindMode': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QAbstractSocket.BindMode', 'QAbstractSocket.BindFlag', int]) -> 'QAbstractSocket.BindMode': ... + def __and__(self, other: typing.Union['QAbstractSocket.BindMode', 'QAbstractSocket.BindFlag', int]) -> 'QAbstractSocket.BindMode': ... + def __xor__(self, other: typing.Union['QAbstractSocket.BindMode', 'QAbstractSocket.BindFlag', int]) -> 'QAbstractSocket.BindMode': ... + def __ror__ (self, other: 'QAbstractSocket.BindFlag') -> 'QAbstractSocket.BindMode': ... + def __rand__(self, other: 'QAbstractSocket.BindFlag') -> 'QAbstractSocket.BindMode': ... + def __rxor__(self, other: 'QAbstractSocket.BindFlag') -> 'QAbstractSocket.BindMode': ... class PauseModes(sip.simplewrapper): @@ -240,12 +254,20 @@ class QAbstractSocket(QtCore.QIODevice): def __init__(self, f: typing.Union['QAbstractSocket.PauseModes', 'QAbstractSocket.PauseMode']) -> None: ... @typing.overload def __init__(self, a0: 'QAbstractSocket.PauseModes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QAbstractSocket.PauseModes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QAbstractSocket.PauseModes', 'QAbstractSocket.PauseMode', int]) -> 'QAbstractSocket.PauseModes': ... + def __and__(self, other: typing.Union['QAbstractSocket.PauseModes', 'QAbstractSocket.PauseMode', int]) -> 'QAbstractSocket.PauseModes': ... + def __xor__(self, other: typing.Union['QAbstractSocket.PauseModes', 'QAbstractSocket.PauseMode', int]) -> 'QAbstractSocket.PauseModes': ... + def __ror__ (self, other: 'QAbstractSocket.PauseMode') -> 'QAbstractSocket.PauseModes': ... + def __rand__(self, other: 'QAbstractSocket.PauseMode') -> 'QAbstractSocket.PauseModes': ... + def __rxor__(self, other: 'QAbstractSocket.PauseMode') -> 'QAbstractSocket.PauseModes': ... def __init__(self, socketType: 'QAbstractSocket.SocketType', parent: QtCore.QObject) -> None: ... @@ -270,12 +292,12 @@ class QAbstractSocket(QtCore.QIODevice): def writeData(self, data: bytes) -> int: ... def readLineData(self, maxlen: int) -> bytes: ... def readData(self, maxlen: int) -> bytes: ... - def proxyAuthenticationRequired(self, proxy: 'QNetworkProxy', authenticator: 'QAuthenticator') -> None: ... - def errorOccurred(self, a0: 'QAbstractSocket.SocketError') -> None: ... - def stateChanged(self, a0: 'QAbstractSocket.SocketState') -> None: ... - def disconnected(self) -> None: ... - def connected(self) -> None: ... - def hostFound(self) -> None: ... + proxyAuthenticationRequired: typing.ClassVar[QtCore.pyqtSignal] + errorOccurred: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + disconnected: typing.ClassVar[QtCore.pyqtSignal] + connected: typing.ClassVar[QtCore.pyqtSignal] + hostFound: typing.ClassVar[QtCore.pyqtSignal] def proxy(self) -> 'QNetworkProxy': ... def setProxy(self, networkProxy: 'QNetworkProxy') -> None: ... def waitForDisconnected(self, msecs: int = ...) -> bool: ... @@ -286,10 +308,7 @@ class QAbstractSocket(QtCore.QIODevice): def atEnd(self) -> bool: ... def isSequential(self) -> bool: ... def close(self) -> None: ... - @typing.overload - def error(self) -> 'QAbstractSocket.SocketError': ... - @typing.overload - def error(self, a0: 'QAbstractSocket.SocketError') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def state(self) -> 'QAbstractSocket.SocketState': ... def socketType(self) -> 'QAbstractSocket.SocketType': ... def socketDescriptor(self) -> sip.voidptr: ... @@ -449,12 +468,12 @@ class QDnsLookup(QtCore.QObject): @typing.overload def __init__(self, type: 'QDnsLookup.Type', name: str, nameserver: typing.Union['QHostAddress', 'QHostAddress.SpecialAddress'], parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def nameserverChanged(self, nameserver: typing.Union['QHostAddress', 'QHostAddress.SpecialAddress']) -> None: ... + nameserverChanged: typing.ClassVar[QtCore.pyqtSignal] def setNameserver(self, nameserver: typing.Union['QHostAddress', 'QHostAddress.SpecialAddress']) -> None: ... def nameserver(self) -> 'QHostAddress': ... - def typeChanged(self, type: 'QDnsLookup.Type') -> None: ... - def nameChanged(self, name: str) -> None: ... - def finished(self) -> None: ... + typeChanged: typing.ClassVar[QtCore.pyqtSignal] + nameChanged: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def lookup(self) -> None: ... def abort(self) -> None: ... def textRecords(self) -> typing.List[QDnsTextRecord]: ... @@ -476,6 +495,9 @@ class QDnsLookup(QtCore.QObject): class QHostAddress(sip.simplewrapper): class ConversionModeFlag(int): + def __or__ (self, other: 'QHostAddress.ConversionModeFlag') -> 'QHostAddress.ConversionMode': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QHostAddress.ConversionMode': ... # type: ignore[override, misc] + ConvertV4MappedToIPv4 = ... # type: QHostAddress.ConversionModeFlag ConvertV4CompatToIPv4 = ... # type: QHostAddress.ConversionModeFlag ConvertUnspecifiedAddress = ... # type: QHostAddress.ConversionModeFlag @@ -515,12 +537,20 @@ class QHostAddress(sip.simplewrapper): def __init__(self, f: typing.Union['QHostAddress.ConversionMode', 'QHostAddress.ConversionModeFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QHostAddress.ConversionMode') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QHostAddress.ConversionMode': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QHostAddress.ConversionMode', 'QHostAddress.ConversionModeFlag', int]) -> 'QHostAddress.ConversionMode': ... + def __and__(self, other: typing.Union['QHostAddress.ConversionMode', 'QHostAddress.ConversionModeFlag', int]) -> 'QHostAddress.ConversionMode': ... + def __xor__(self, other: typing.Union['QHostAddress.ConversionMode', 'QHostAddress.ConversionModeFlag', int]) -> 'QHostAddress.ConversionMode': ... + def __ror__ (self, other: 'QHostAddress.ConversionModeFlag') -> 'QHostAddress.ConversionMode': ... + def __rand__(self, other: 'QHostAddress.ConversionModeFlag') -> 'QHostAddress.ConversionMode': ... + def __rxor__(self, other: 'QHostAddress.ConversionModeFlag') -> 'QHostAddress.ConversionMode': ... @typing.overload def __init__(self) -> None: ... @@ -611,6 +641,9 @@ class QHostInfo(sip.simplewrapper): class QHstsPolicy(sip.simplewrapper): class PolicyFlag(int): + def __or__ (self, other: 'QHstsPolicy.PolicyFlag') -> 'QHstsPolicy.PolicyFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QHstsPolicy.PolicyFlags': ... # type: ignore[override, misc] + IncludeSubDomains = ... # type: QHstsPolicy.PolicyFlag IncludeSubDomains = ... # type: QHstsPolicy.PolicyFlag @@ -623,12 +656,20 @@ class QHstsPolicy(sip.simplewrapper): def __init__(self, f: typing.Union['QHstsPolicy.PolicyFlags', 'QHstsPolicy.PolicyFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QHstsPolicy.PolicyFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QHstsPolicy.PolicyFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QHstsPolicy.PolicyFlags', 'QHstsPolicy.PolicyFlag', int]) -> 'QHstsPolicy.PolicyFlags': ... + def __and__(self, other: typing.Union['QHstsPolicy.PolicyFlags', 'QHstsPolicy.PolicyFlag', int]) -> 'QHstsPolicy.PolicyFlags': ... + def __xor__(self, other: typing.Union['QHstsPolicy.PolicyFlags', 'QHstsPolicy.PolicyFlag', int]) -> 'QHstsPolicy.PolicyFlags': ... + def __ror__ (self, other: 'QHstsPolicy.PolicyFlag') -> 'QHstsPolicy.PolicyFlags': ... + def __rand__(self, other: 'QHstsPolicy.PolicyFlag') -> 'QHstsPolicy.PolicyFlags': ... + def __rxor__(self, other: 'QHstsPolicy.PolicyFlag') -> 'QHstsPolicy.PolicyFlags': ... @typing.overload def __init__(self) -> None: ... @@ -708,6 +749,9 @@ class QHttpMultiPart(QtCore.QObject): class QLocalServer(QtCore.QObject): class SocketOption(int): + def __or__ (self, other: 'QLocalServer.SocketOption') -> 'QLocalServer.SocketOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QLocalServer.SocketOptions': ... # type: ignore[override, misc] + UserAccessOption = ... # type: QLocalServer.SocketOption GroupAccessOption = ... # type: QLocalServer.SocketOption OtherAccessOption = ... # type: QLocalServer.SocketOption @@ -726,12 +770,20 @@ class QLocalServer(QtCore.QObject): def __init__(self, f: typing.Union['QLocalServer.SocketOptions', 'QLocalServer.SocketOption']) -> None: ... @typing.overload def __init__(self, a0: 'QLocalServer.SocketOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QLocalServer.SocketOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QLocalServer.SocketOptions', 'QLocalServer.SocketOption', int]) -> 'QLocalServer.SocketOptions': ... + def __and__(self, other: typing.Union['QLocalServer.SocketOptions', 'QLocalServer.SocketOption', int]) -> 'QLocalServer.SocketOptions': ... + def __xor__(self, other: typing.Union['QLocalServer.SocketOptions', 'QLocalServer.SocketOption', int]) -> 'QLocalServer.SocketOptions': ... + def __ror__ (self, other: 'QLocalServer.SocketOption') -> 'QLocalServer.SocketOptions': ... + def __rand__(self, other: 'QLocalServer.SocketOption') -> 'QLocalServer.SocketOptions': ... + def __rxor__(self, other: 'QLocalServer.SocketOption') -> 'QLocalServer.SocketOptions': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -739,7 +791,7 @@ class QLocalServer(QtCore.QObject): def socketOptions(self) -> 'QLocalServer.SocketOptions': ... def setSocketOptions(self, options: typing.Union['QLocalServer.SocketOptions', 'QLocalServer.SocketOption']) -> None: ... def incomingConnection(self, socketDescriptor: sip.voidptr) -> None: ... - def newConnection(self) -> None: ... + newConnection: typing.ClassVar[QtCore.pyqtSignal] @staticmethod def removeServer(name: str) -> bool: ... def waitForNewConnection(self, msecs: int = ...) -> typing.Tuple[bool, bool]: ... @@ -801,10 +853,10 @@ class QLocalSocket(QtCore.QIODevice): def writeData(self, a0: bytes) -> int: ... def readData(self, maxlen: int) -> bytes: ... - def stateChanged(self, socketState: 'QLocalSocket.LocalSocketState') -> None: ... - def errorOccurred(self, socketError: 'QLocalSocket.LocalSocketError') -> None: ... - def disconnected(self) -> None: ... - def connected(self) -> None: ... + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + errorOccurred: typing.ClassVar[QtCore.pyqtSignal] + disconnected: typing.ClassVar[QtCore.pyqtSignal] + connected: typing.ClassVar[QtCore.pyqtSignal] def waitForReadyRead(self, msecs: int = ...) -> bool: ... def waitForDisconnected(self, msecs: int = ...) -> bool: ... def waitForConnected(self, msecs: int = ...) -> bool: ... @@ -816,10 +868,7 @@ class QLocalSocket(QtCore.QIODevice): def readBufferSize(self) -> int: ... def isValid(self) -> bool: ... def flush(self) -> bool: ... - @typing.overload - def error(self) -> 'QLocalSocket.LocalSocketError': ... - @typing.overload - def error(self, socketError: 'QLocalSocket.LocalSocketError') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def close(self) -> None: ... def canReadLine(self) -> bool: ... def bytesToWrite(self) -> int: ... @@ -933,6 +982,9 @@ class QNetworkAccessManager(QtCore.QObject): class QNetworkConfigurationManager(QtCore.QObject): class Capability(int): + def __or__ (self, other: typing.Union[int, 'QNetworkConfigurationManager.Capability']) -> 'QNetworkConfigurationManager.Capabilities': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QNetworkConfigurationManager.Capabilities': ... # type: ignore[override, misc] + CanStartAndStopInterfaces = ... # type: QNetworkConfigurationManager.Capability DirectConnectionRouting = ... # type: QNetworkConfigurationManager.Capability SystemSessionSupport = ... # type: QNetworkConfigurationManager.Capability @@ -957,20 +1009,28 @@ class QNetworkConfigurationManager(QtCore.QObject): def __init__(self, f: typing.Union['QNetworkConfigurationManager.Capabilities', 'QNetworkConfigurationManager.Capability']) -> None: ... @typing.overload def __init__(self, a0: 'QNetworkConfigurationManager.Capabilities') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QNetworkConfigurationManager.Capabilities': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QNetworkConfigurationManager.Capabilities', 'QNetworkConfigurationManager.Capability', int]) -> 'QNetworkConfigurationManager.Capabilities': ... + def __and__(self, other: typing.Union['QNetworkConfigurationManager.Capabilities', 'QNetworkConfigurationManager.Capability', int]) -> 'QNetworkConfigurationManager.Capabilities': ... + def __xor__(self, other: typing.Union['QNetworkConfigurationManager.Capabilities', 'QNetworkConfigurationManager.Capability', int]) -> 'QNetworkConfigurationManager.Capabilities': ... + def __ror__ (self, other: 'QNetworkConfigurationManager.Capability') -> 'QNetworkConfigurationManager.Capabilities': ... + def __rand__(self, other: 'QNetworkConfigurationManager.Capability') -> 'QNetworkConfigurationManager.Capabilities': ... + def __rxor__(self, other: 'QNetworkConfigurationManager.Capability') -> 'QNetworkConfigurationManager.Capabilities': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def updateCompleted(self) -> None: ... - def onlineStateChanged(self, isOnline: bool) -> None: ... - def configurationChanged(self, config: 'QNetworkConfiguration') -> None: ... - def configurationRemoved(self, config: 'QNetworkConfiguration') -> None: ... - def configurationAdded(self, config: 'QNetworkConfiguration') -> None: ... + updateCompleted: typing.ClassVar[QtCore.pyqtSignal] + onlineStateChanged: typing.ClassVar[QtCore.pyqtSignal] + configurationChanged: typing.ClassVar[QtCore.pyqtSignal] + configurationRemoved: typing.ClassVar[QtCore.pyqtSignal] + configurationAdded: typing.ClassVar[QtCore.pyqtSignal] def isOnline(self) -> bool: ... def updateConfigurations(self) -> None: ... def configurationFromIdentifier(self, identifier: str) -> 'QNetworkConfiguration': ... @@ -1051,12 +1111,20 @@ class QNetworkConfiguration(sip.simplewrapper): def __init__(self, f: typing.Union['QNetworkConfiguration.StateFlags', 'QNetworkConfiguration.StateFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QNetworkConfiguration.StateFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QNetworkConfiguration.StateFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QNetworkConfiguration.StateFlags', 'QNetworkConfiguration.StateFlag', int]) -> 'QNetworkConfiguration.StateFlags': ... + def __and__(self, other: typing.Union['QNetworkConfiguration.StateFlags', 'QNetworkConfiguration.StateFlag', int]) -> 'QNetworkConfiguration.StateFlags': ... + def __xor__(self, other: typing.Union['QNetworkConfiguration.StateFlags', 'QNetworkConfiguration.StateFlag', int]) -> 'QNetworkConfiguration.StateFlags': ... + def __ror__ (self, other: 'QNetworkConfiguration.StateFlag') -> 'QNetworkConfiguration.StateFlags': ... + def __rand__(self, other: 'QNetworkConfiguration.StateFlag') -> 'QNetworkConfiguration.StateFlags': ... + def __rxor__(self, other: 'QNetworkConfiguration.StateFlag') -> 'QNetworkConfiguration.StateFlags': ... @typing.overload def __init__(self) -> None: ... @@ -1250,6 +1318,9 @@ class QNetworkInterface(sip.simplewrapper): Ieee1394 = ... # type: QNetworkInterface.InterfaceType class InterfaceFlag(int): + def __or__ (self, other: 'QNetworkInterface.InterfaceFlag') -> 'QNetworkInterface.InterfaceFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QNetworkInterface.InterfaceFlags': ... # type: ignore[override, misc] + IsUp = ... # type: QNetworkInterface.InterfaceFlag IsRunning = ... # type: QNetworkInterface.InterfaceFlag CanBroadcast = ... # type: QNetworkInterface.InterfaceFlag @@ -1272,12 +1343,20 @@ class QNetworkInterface(sip.simplewrapper): def __init__(self, f: typing.Union['QNetworkInterface.InterfaceFlags', 'QNetworkInterface.InterfaceFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QNetworkInterface.InterfaceFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QNetworkInterface.InterfaceFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QNetworkInterface.InterfaceFlags', 'QNetworkInterface.InterfaceFlag', int]) -> 'QNetworkInterface.InterfaceFlags': ... + def __and__(self, other: typing.Union['QNetworkInterface.InterfaceFlags', 'QNetworkInterface.InterfaceFlag', int]) -> 'QNetworkInterface.InterfaceFlags': ... + def __xor__(self, other: typing.Union['QNetworkInterface.InterfaceFlags', 'QNetworkInterface.InterfaceFlag', int]) -> 'QNetworkInterface.InterfaceFlags': ... + def __ror__ (self, other: 'QNetworkInterface.InterfaceFlag') -> 'QNetworkInterface.InterfaceFlags': ... + def __rand__(self, other: 'QNetworkInterface.InterfaceFlag') -> 'QNetworkInterface.InterfaceFlags': ... + def __rxor__(self, other: 'QNetworkInterface.InterfaceFlag') -> 'QNetworkInterface.InterfaceFlags': ... @typing.overload def __init__(self) -> None: ... @@ -1350,12 +1429,20 @@ class QNetworkProxy(sip.simplewrapper): def __init__(self, f: typing.Union['QNetworkProxy.Capabilities', 'QNetworkProxy.Capability']) -> None: ... @typing.overload def __init__(self, a0: 'QNetworkProxy.Capabilities') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QNetworkProxy.Capabilities': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QNetworkProxy.Capabilities', 'QNetworkProxy.Capability', int]) -> 'QNetworkProxy.Capabilities': ... + def __and__(self, other: typing.Union['QNetworkProxy.Capabilities', 'QNetworkProxy.Capability', int]) -> 'QNetworkProxy.Capabilities': ... + def __xor__(self, other: typing.Union['QNetworkProxy.Capabilities', 'QNetworkProxy.Capability', int]) -> 'QNetworkProxy.Capabilities': ... + def __ror__ (self, other: 'QNetworkProxy.Capability') -> 'QNetworkProxy.Capabilities': ... + def __rand__(self, other: 'QNetworkProxy.Capability') -> 'QNetworkProxy.Capabilities': ... + def __rxor__(self, other: 'QNetworkProxy.Capability') -> 'QNetworkProxy.Capabilities': ... @typing.overload def __init__(self) -> None: ... @@ -1552,16 +1639,16 @@ class QNetworkReply(QtCore.QIODevice): def setRequest(self, request: 'QNetworkRequest') -> None: ... def setOperation(self, operation: QNetworkAccessManager.Operation) -> None: ... def writeData(self, data: bytes) -> int: ... - def redirectAllowed(self) -> None: ... - def redirected(self, url: QtCore.QUrl) -> None: ... - def preSharedKeyAuthenticationRequired(self, authenticator: 'QSslPreSharedKeyAuthenticator') -> None: ... - def downloadProgress(self, bytesReceived: int, bytesTotal: int) -> None: ... - def uploadProgress(self, bytesSent: int, bytesTotal: int) -> None: ... - def sslErrors(self, errors: typing.Iterable['QSslError']) -> None: ... - def errorOccurred(self, a0: 'QNetworkReply.NetworkError') -> None: ... - def encrypted(self) -> None: ... - def finished(self) -> None: ... - def metaDataChanged(self) -> None: ... + redirectAllowed: typing.ClassVar[QtCore.pyqtSignal] + redirected: typing.ClassVar[QtCore.pyqtSignal] + preSharedKeyAuthenticationRequired: typing.ClassVar[QtCore.pyqtSignal] + downloadProgress: typing.ClassVar[QtCore.pyqtSignal] + uploadProgress: typing.ClassVar[QtCore.pyqtSignal] + sslErrors: typing.ClassVar[QtCore.pyqtSignal] + errorOccurred: typing.ClassVar[QtCore.pyqtSignal] + encrypted: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] + metaDataChanged: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def ignoreSslErrors(self) -> None: ... @typing.overload @@ -1574,10 +1661,7 @@ class QNetworkReply(QtCore.QIODevice): def hasRawHeader(self, headerName: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> bool: ... def header(self, header: 'QNetworkRequest.KnownHeaders') -> typing.Any: ... def url(self) -> QtCore.QUrl: ... - @typing.overload - def error(self) -> 'QNetworkReply.NetworkError': ... - @typing.overload - def error(self, a0: 'QNetworkReply.NetworkError') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def request(self) -> 'QNetworkRequest': ... def operation(self) -> QNetworkAccessManager.Operation: ... def manager(self) -> QNetworkAccessManager: ... @@ -1802,24 +1886,32 @@ class QNetworkSession(QtCore.QObject): def __init__(self, f: typing.Union['QNetworkSession.UsagePolicies', 'QNetworkSession.UsagePolicy']) -> None: ... @typing.overload def __init__(self, a0: 'QNetworkSession.UsagePolicies') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QNetworkSession.UsagePolicies': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QNetworkSession.UsagePolicies', 'QNetworkSession.UsagePolicy', int]) -> 'QNetworkSession.UsagePolicies': ... + def __and__(self, other: typing.Union['QNetworkSession.UsagePolicies', 'QNetworkSession.UsagePolicy', int]) -> 'QNetworkSession.UsagePolicies': ... + def __xor__(self, other: typing.Union['QNetworkSession.UsagePolicies', 'QNetworkSession.UsagePolicy', int]) -> 'QNetworkSession.UsagePolicies': ... + def __ror__ (self, other: 'QNetworkSession.UsagePolicy') -> 'QNetworkSession.UsagePolicies': ... + def __rand__(self, other: 'QNetworkSession.UsagePolicy') -> 'QNetworkSession.UsagePolicies': ... + def __rxor__(self, other: 'QNetworkSession.UsagePolicy') -> 'QNetworkSession.UsagePolicies': ... def __init__(self, connConfig: QNetworkConfiguration, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def usagePoliciesChanged(self, usagePolicies: typing.Union['QNetworkSession.UsagePolicies', 'QNetworkSession.UsagePolicy']) -> None: ... + usagePoliciesChanged: typing.ClassVar[QtCore.pyqtSignal] def usagePolicies(self) -> 'QNetworkSession.UsagePolicies': ... def disconnectNotify(self, signal: QtCore.QMetaMethod) -> None: ... def connectNotify(self, signal: QtCore.QMetaMethod) -> None: ... - def newConfigurationActivated(self) -> None: ... - def preferredConfigurationChanged(self, config: QNetworkConfiguration, isSeamless: bool) -> None: ... - def closed(self) -> None: ... - def opened(self) -> None: ... - def stateChanged(self, a0: 'QNetworkSession.State') -> None: ... + newConfigurationActivated: typing.ClassVar[QtCore.pyqtSignal] + preferredConfigurationChanged: typing.ClassVar[QtCore.pyqtSignal] + closed: typing.ClassVar[QtCore.pyqtSignal] + opened: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] def reject(self) -> None: ... def accept(self) -> None: ... def ignore(self) -> None: ... @@ -1834,10 +1926,7 @@ class QNetworkSession(QtCore.QObject): def setSessionProperty(self, key: str, value: typing.Any) -> None: ... def sessionProperty(self, key: str) -> typing.Any: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> 'QNetworkSession.SessionError': ... - @typing.overload - def error(self, a0: 'QNetworkSession.SessionError') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def state(self) -> 'QNetworkSession.State': ... def interface(self) -> QNetworkInterface: ... def configuration(self) -> QNetworkConfiguration: ... @@ -1868,6 +1957,9 @@ class QPasswordDigestor(sip.simplewrapper): class QSsl(sip.simplewrapper): class SslOption(int): + def __or__ (self, other: 'QSsl.SslOption') -> 'QSsl.SslOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSsl.SslOptions': ... # type: ignore[override, misc] + SslOptionDisableEmptyFragments = ... # type: QSsl.SslOption SslOptionDisableSessionTickets = ... # type: QSsl.SslOption SslOptionDisableCompression = ... # type: QSsl.SslOption @@ -1969,12 +2061,20 @@ class QSsl(sip.simplewrapper): def __init__(self, f: typing.Union['QSsl.SslOptions', 'QSsl.SslOption']) -> None: ... @typing.overload def __init__(self, a0: 'QSsl.SslOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSsl.SslOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSsl.SslOptions', 'QSsl.SslOption', int]) -> 'QSsl.SslOptions': ... + def __and__(self, other: typing.Union['QSsl.SslOptions', 'QSsl.SslOption', int]) -> 'QSsl.SslOptions': ... + def __xor__(self, other: typing.Union['QSsl.SslOptions', 'QSsl.SslOption', int]) -> 'QSsl.SslOptions': ... + def __ror__ (self, other: 'QSsl.SslOption') -> 'QSsl.SslOptions': ... + def __rand__(self, other: 'QSsl.SslOption') -> 'QSsl.SslOptions': ... + def __rxor__(self, other: 'QSsl.SslOption') -> 'QSsl.SslOptions': ... class QSslCertificate(sip.simplewrapper): @@ -2392,7 +2492,7 @@ class QSslSocket(QTcpSocket): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def newSessionTicketReceived(self) -> None: ... + newSessionTicketReceived: typing.ClassVar[QtCore.pyqtSignal] def sslHandshakeErrors(self) -> typing.List[QSslError]: ... def ocspResponses(self) -> typing.List[QOcspResponse]: ... @staticmethod @@ -2413,8 +2513,8 @@ class QSslSocket(QTcpSocket): def peerVerifyName(self) -> str: ... def socketOption(self, option: QAbstractSocket.SocketOption) -> typing.Any: ... def setSocketOption(self, option: QAbstractSocket.SocketOption, value: typing.Any) -> None: ... - def encryptedBytesWritten(self, totalBytes: int) -> None: ... - def peerVerifyError(self, error: QSslError) -> None: ... + encryptedBytesWritten: typing.ClassVar[QtCore.pyqtSignal] + peerVerifyError: typing.ClassVar[QtCore.pyqtSignal] def setSslConfiguration(self, config: QSslConfiguration) -> None: ... def sslConfiguration(self) -> QSslConfiguration: ... def encryptedBytesToWrite(self) -> int: ... @@ -2426,9 +2526,9 @@ class QSslSocket(QTcpSocket): def peerVerifyMode(self) -> 'QSslSocket.PeerVerifyMode': ... def writeData(self, data: bytes) -> int: ... def readData(self, maxlen: int) -> bytes: ... - def preSharedKeyAuthenticationRequired(self, authenticator: QSslPreSharedKeyAuthenticator) -> None: ... - def modeChanged(self, newMode: 'QSslSocket.SslMode') -> None: ... - def encrypted(self) -> None: ... + preSharedKeyAuthenticationRequired: typing.ClassVar[QtCore.pyqtSignal] + modeChanged: typing.ClassVar[QtCore.pyqtSignal] + encrypted: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def ignoreSslErrors(self) -> None: ... @typing.overload @@ -2437,10 +2537,7 @@ class QSslSocket(QTcpSocket): def startClientEncryption(self) -> None: ... @staticmethod def supportsSsl() -> bool: ... - @typing.overload - def sslErrors(self) -> typing.List[QSslError]: ... - @typing.overload - def sslErrors(self, errors: typing.Iterable[QSslError]) -> None: ... + sslErrors: typing.ClassVar[QtCore.pyqtSignal] def waitForDisconnected(self, msecs: int = ...) -> bool: ... def waitForBytesWritten(self, msecs: int = ...) -> bool: ... def waitForReadyRead(self, msecs: int = ...) -> bool: ... @@ -2513,8 +2610,8 @@ class QTcpServer(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def acceptError(self, socketError: QAbstractSocket.SocketError) -> None: ... - def newConnection(self) -> None: ... + acceptError: typing.ClassVar[QtCore.pyqtSignal] + newConnection: typing.ClassVar[QtCore.pyqtSignal] def addPendingConnection(self, socket: QTcpSocket) -> None: ... def incomingConnection(self, handle: sip.voidptr) -> None: ... def resumeAccepting(self) -> None: ... diff --git a/PyQt5-stubs/QtNetworkAuth.pyi b/PyQt5-stubs/QtNetworkAuth.pyi index b9f650b4..92798201 100644 --- a/PyQt5-stubs/QtNetworkAuth.pyi +++ b/PyQt5-stubs/QtNetworkAuth.pyi @@ -1,10 +1,10 @@ # The PEP 484 type hints stub file for the QtNetworkAuth module. # -# Generated by SIP 5.4.0 +# Generated by SIP 6.4.0 # -# Copyright (c) 2020 Riverbank Computing Limited +# Copyright (c) 2021 Riverbank Computing Limited # -# This file is part of PyQt5. +# This file is part of PyQtNetworkAuth. # # This file may be used under the terms of the GNU General Public License # version 3.0 as published by the Free Software Foundation and appearing in @@ -36,45 +36,45 @@ PYQT_SLOT = typing.Union[typing.Callable[..., None], QtCore.pyqtBoundSignal] class QAbstractOAuth(QtCore.QObject): class ContentType(int): - WwwFormUrlEncoded = ... # type: 'QAbstractOAuth.ContentType' - Json = ... # type: 'QAbstractOAuth.ContentType' + WwwFormUrlEncoded = ... # type: QAbstractOAuth.ContentType + Json = ... # type: QAbstractOAuth.ContentType class Error(int): - NoError = ... # type: 'QAbstractOAuth.Error' - NetworkError = ... # type: 'QAbstractOAuth.Error' - ServerError = ... # type: 'QAbstractOAuth.Error' - OAuthTokenNotFoundError = ... # type: 'QAbstractOAuth.Error' - OAuthTokenSecretNotFoundError = ... # type: 'QAbstractOAuth.Error' - OAuthCallbackNotVerified = ... # type: 'QAbstractOAuth.Error' + NoError = ... # type: QAbstractOAuth.Error + NetworkError = ... # type: QAbstractOAuth.Error + ServerError = ... # type: QAbstractOAuth.Error + OAuthTokenNotFoundError = ... # type: QAbstractOAuth.Error + OAuthTokenSecretNotFoundError = ... # type: QAbstractOAuth.Error + OAuthCallbackNotVerified = ... # type: QAbstractOAuth.Error class Stage(int): - RequestingTemporaryCredentials = ... # type: 'QAbstractOAuth.Stage' - RequestingAuthorization = ... # type: 'QAbstractOAuth.Stage' - RequestingAccessToken = ... # type: 'QAbstractOAuth.Stage' - RefreshingAccessToken = ... # type: 'QAbstractOAuth.Stage' + RequestingTemporaryCredentials = ... # type: QAbstractOAuth.Stage + RequestingAuthorization = ... # type: QAbstractOAuth.Stage + RequestingAccessToken = ... # type: QAbstractOAuth.Stage + RefreshingAccessToken = ... # type: QAbstractOAuth.Stage class Status(int): - NotAuthenticated = ... # type: 'QAbstractOAuth.Status' - TemporaryCredentialsReceived = ... # type: 'QAbstractOAuth.Status' - Granted = ... # type: 'QAbstractOAuth.Status' - RefreshingToken = ... # type: 'QAbstractOAuth.Status' + NotAuthenticated = ... # type: QAbstractOAuth.Status + TemporaryCredentialsReceived = ... # type: QAbstractOAuth.Status + Granted = ... # type: QAbstractOAuth.Status + RefreshingToken = ... # type: QAbstractOAuth.Status @staticmethod def generateRandomString(length: int) -> QtCore.QByteArray: ... def resourceOwnerAuthorization(self, url: QtCore.QUrl, parameters: typing.Dict[str, typing.Any]) -> None: ... def callback(self) -> str: ... def setStatus(self, status: 'QAbstractOAuth.Status') -> None: ... - def replyDataReceived(self, data: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def finished(self, reply: QtNetwork.QNetworkReply) -> None: ... - def granted(self) -> None: ... - def authorizeWithBrowser(self, url: QtCore.QUrl) -> None: ... - def requestFailed(self, error: 'QAbstractOAuth.Error') -> None: ... - def contentTypeChanged(self, contentType: 'QAbstractOAuth.ContentType') -> None: ... - def extraTokensChanged(self, tokens: typing.Dict[str, typing.Any]) -> None: ... - def authorizationUrlChanged(self, url: QtCore.QUrl) -> None: ... - def statusChanged(self, status: 'QAbstractOAuth.Status') -> None: ... - def tokenChanged(self, token: str) -> None: ... - def clientIdentifierChanged(self, clientIdentifier: str) -> None: ... + replyDataReceived: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] + granted: typing.ClassVar[QtCore.pyqtSignal] + authorizeWithBrowser: typing.ClassVar[QtCore.pyqtSignal] + requestFailed: typing.ClassVar[QtCore.pyqtSignal] + contentTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + extraTokensChanged: typing.ClassVar[QtCore.pyqtSignal] + authorizationUrlChanged: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] + tokenChanged: typing.ClassVar[QtCore.pyqtSignal] + clientIdentifierChanged: typing.ClassVar[QtCore.pyqtSignal] def grant(self) -> None: ... def prepareRequest(self, request: QtNetwork.QNetworkRequest, verb: typing.Union[QtCore.QByteArray, bytes, bytearray], body: typing.Union[QtCore.QByteArray, bytes, bytearray] = ...) -> None: ... def setContentType(self, contentType: 'QAbstractOAuth.ContentType') -> None: ... @@ -108,15 +108,15 @@ class QAbstractOAuth2(QAbstractOAuth): def __init__(self, manager: QtNetwork.QNetworkAccessManager, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def setResponseType(self, responseType: str) -> None: ... - def authorizationCallbackReceived(self, data: typing.Dict[str, typing.Any]) -> None: ... - def error(self, error: str, errorDescription: str, uri: QtCore.QUrl) -> None: ... - def expirationAtChanged(self, expiration: typing.Union[QtCore.QDateTime, datetime.datetime]) -> None: ... - def stateChanged(self, state: str) -> None: ... - def clientIdentifierSharedKeyChanged(self, clientIdentifierSharedKey: str) -> None: ... - def responseTypeChanged(self, responseType: str) -> None: ... - def refreshTokenChanged(self, refreshToken: str) -> None: ... - def userAgentChanged(self, userAgent: str) -> None: ... - def scopeChanged(self, scope: str) -> None: ... + authorizationCallbackReceived: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] + expirationAtChanged: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + clientIdentifierSharedKeyChanged: typing.ClassVar[QtCore.pyqtSignal] + responseTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + refreshTokenChanged: typing.ClassVar[QtCore.pyqtSignal] + userAgentChanged: typing.ClassVar[QtCore.pyqtSignal] + scopeChanged: typing.ClassVar[QtCore.pyqtSignal] def setRefreshToken(self, refreshToken: str) -> None: ... def refreshToken(self) -> str: ... def expirationAt(self) -> QtCore.QDateTime: ... @@ -151,10 +151,10 @@ class QAbstractOAuthReplyHandler(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def callbackDataReceived(self, data: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def replyDataReceived(self, data: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def tokensReceived(self, tokens: typing.Dict[str, typing.Any]) -> None: ... - def callbackReceived(self, values: typing.Dict[str, typing.Any]) -> None: ... + callbackDataReceived: typing.ClassVar[QtCore.pyqtSignal] + replyDataReceived: typing.ClassVar[QtCore.pyqtSignal] + tokensReceived: typing.ClassVar[QtCore.pyqtSignal] + callbackReceived: typing.ClassVar[QtCore.pyqtSignal] def networkReplyFinished(self, reply: QtNetwork.QNetworkReply) -> None: ... def callback(self) -> str: ... @@ -162,9 +162,9 @@ class QAbstractOAuthReplyHandler(QtCore.QObject): class QOAuth1(QAbstractOAuth): class SignatureMethod(int): - Hmac_Sha1 = ... # type: 'QOAuth1.SignatureMethod' - Rsa_Sha1 = ... # type: 'QOAuth1.SignatureMethod' - PlainText = ... # type: 'QOAuth1.SignatureMethod' + Hmac_Sha1 = ... # type: QOAuth1.SignatureMethod + Rsa_Sha1 = ... # type: QOAuth1.SignatureMethod + PlainText = ... # type: QOAuth1.SignatureMethod @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -183,11 +183,11 @@ class QOAuth1(QAbstractOAuth): def setup(self, request: QtNetwork.QNetworkRequest, signingParameters: typing.Dict[str, typing.Any], operationVerb: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... def requestTokenCredentials(self, operation: QtNetwork.QNetworkAccessManager.Operation, url: QtCore.QUrl, temporaryToken: typing.Tuple[str, str], parameters: typing.Dict[str, typing.Any] = ...) -> QtNetwork.QNetworkReply: ... def requestTemporaryCredentials(self, operation: QtNetwork.QNetworkAccessManager.Operation, url: QtCore.QUrl, parameters: typing.Dict[str, typing.Any] = ...) -> QtNetwork.QNetworkReply: ... - def tokenCredentialsUrlChanged(self, url: QtCore.QUrl) -> None: ... - def temporaryCredentialsUrlChanged(self, url: QtCore.QUrl) -> None: ... - def tokenSecretChanged(self, token: str) -> None: ... - def clientSharedSecretChanged(self, credential: str) -> None: ... - def signatureMethodChanged(self, method: 'QOAuth1.SignatureMethod') -> None: ... + tokenCredentialsUrlChanged: typing.ClassVar[QtCore.pyqtSignal] + temporaryCredentialsUrlChanged: typing.ClassVar[QtCore.pyqtSignal] + tokenSecretChanged: typing.ClassVar[QtCore.pyqtSignal] + clientSharedSecretChanged: typing.ClassVar[QtCore.pyqtSignal] + signatureMethodChanged: typing.ClassVar[QtCore.pyqtSignal] def continueGrantWithVerifier(self, verifier: str) -> None: ... def grant(self) -> None: ... def deleteResource(self, url: QtCore.QUrl, parameters: typing.Dict[str, typing.Any] = ...) -> QtNetwork.QNetworkReply: ... @@ -220,13 +220,13 @@ class QOAuth1(QAbstractOAuth): class QOAuth1Signature(sip.simplewrapper): class HttpRequestMethod(int): - Head = ... # type: 'QOAuth1Signature.HttpRequestMethod' - Get = ... # type: 'QOAuth1Signature.HttpRequestMethod' - Put = ... # type: 'QOAuth1Signature.HttpRequestMethod' - Post = ... # type: 'QOAuth1Signature.HttpRequestMethod' - Delete = ... # type: 'QOAuth1Signature.HttpRequestMethod' - Custom = ... # type: 'QOAuth1Signature.HttpRequestMethod' - Unknown = ... # type: 'QOAuth1Signature.HttpRequestMethod' + Head = ... # type: QOAuth1Signature.HttpRequestMethod + Get = ... # type: QOAuth1Signature.HttpRequestMethod + Put = ... # type: QOAuth1Signature.HttpRequestMethod + Post = ... # type: QOAuth1Signature.HttpRequestMethod + Delete = ... # type: QOAuth1Signature.HttpRequestMethod + Custom = ... # type: QOAuth1Signature.HttpRequestMethod + Unknown = ... # type: QOAuth1Signature.HttpRequestMethod @typing.overload def __init__(self, url: QtCore.QUrl = ..., method: 'QOAuth1Signature.HttpRequestMethod' = ..., parameters: typing.Dict[str, typing.Any] = ...) -> None: ... @@ -278,7 +278,7 @@ class QOAuth2AuthorizationCodeFlow(QAbstractOAuth2): def resourceOwnerAuthorization(self, url: QtCore.QUrl, parameters: typing.Dict[str, typing.Any] = ...) -> None: ... def requestAccessToken(self, code: str) -> None: ... def buildAuthenticateUrl(self, parameters: typing.Dict[str, typing.Any] = ...) -> QtCore.QUrl: ... - def accessTokenUrlChanged(self, accessTokenUrl: QtCore.QUrl) -> None: ... + accessTokenUrlChanged: typing.ClassVar[QtCore.pyqtSignal] def refreshAccessToken(self) -> None: ... def grant(self) -> None: ... def setAccessTokenUrl(self, accessTokenUrl: QtCore.QUrl) -> None: ... diff --git a/PyQt5-stubs/QtNfc.pyi b/PyQt5-stubs/QtNfc.pyi index 669afa27..2626497f 100644 --- a/PyQt5-stubs/QtNfc.pyi +++ b/PyQt5-stubs/QtNfc.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtNfc module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -247,6 +247,9 @@ class QNearFieldManager(QtCore.QObject): TurningOff = ... # type: QNearFieldManager.AdapterState class TargetAccessMode(int): + def __or__ (self, other: 'QNearFieldManager.TargetAccessMode') -> 'QNearFieldManager.TargetAccessModes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QNearFieldManager.TargetAccessModes': ... # type: ignore[override, misc] + NoTargetAccess = ... # type: QNearFieldManager.TargetAccessMode NdefReadTargetAccess = ... # type: QNearFieldManager.TargetAccessMode NdefWriteTargetAccess = ... # type: QNearFieldManager.TargetAccessMode @@ -265,19 +268,27 @@ class QNearFieldManager(QtCore.QObject): def __init__(self, f: typing.Union['QNearFieldManager.TargetAccessModes', 'QNearFieldManager.TargetAccessMode']) -> None: ... @typing.overload def __init__(self, a0: 'QNearFieldManager.TargetAccessModes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QNearFieldManager.TargetAccessModes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QNearFieldManager.TargetAccessModes', 'QNearFieldManager.TargetAccessMode', int]) -> 'QNearFieldManager.TargetAccessModes': ... + def __and__(self, other: typing.Union['QNearFieldManager.TargetAccessModes', 'QNearFieldManager.TargetAccessMode', int]) -> 'QNearFieldManager.TargetAccessModes': ... + def __xor__(self, other: typing.Union['QNearFieldManager.TargetAccessModes', 'QNearFieldManager.TargetAccessMode', int]) -> 'QNearFieldManager.TargetAccessModes': ... + def __ror__ (self, other: 'QNearFieldManager.TargetAccessMode') -> 'QNearFieldManager.TargetAccessModes': ... + def __rand__(self, other: 'QNearFieldManager.TargetAccessMode') -> 'QNearFieldManager.TargetAccessModes': ... + def __rxor__(self, other: 'QNearFieldManager.TargetAccessMode') -> 'QNearFieldManager.TargetAccessModes': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def adapterStateChanged(self, state: 'QNearFieldManager.AdapterState') -> None: ... + adapterStateChanged: typing.ClassVar[QtCore.pyqtSignal] def isSupported(self) -> bool: ... - def targetLost(self, target: 'QNearFieldTarget') -> None: ... - def targetDetected(self, target: 'QNearFieldTarget') -> None: ... + targetLost: typing.ClassVar[QtCore.pyqtSignal] + targetDetected: typing.ClassVar[QtCore.pyqtSignal] def unregisterNdefMessageHandler(self, handlerId: int) -> bool: ... @typing.overload def registerNdefMessageHandler(self, slot: PYQT_SLOT) -> int: ... @@ -295,6 +306,9 @@ class QNearFieldManager(QtCore.QObject): class QNearFieldShareManager(QtCore.QObject): class ShareMode(int): + def __or__ (self, other: 'QNearFieldShareManager.ShareMode') -> 'QNearFieldShareManager.ShareModes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QNearFieldShareManager.ShareModes': ... # type: ignore[override, misc] + NoShare = ... # type: QNearFieldShareManager.ShareMode NdefShare = ... # type: QNearFieldShareManager.ShareMode FileShare = ... # type: QNearFieldShareManager.ShareMode @@ -332,18 +346,26 @@ class QNearFieldShareManager(QtCore.QObject): def __init__(self, f: typing.Union['QNearFieldShareManager.ShareModes', 'QNearFieldShareManager.ShareMode']) -> None: ... @typing.overload def __init__(self, a0: 'QNearFieldShareManager.ShareModes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QNearFieldShareManager.ShareModes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QNearFieldShareManager.ShareModes', 'QNearFieldShareManager.ShareMode', int]) -> 'QNearFieldShareManager.ShareModes': ... + def __and__(self, other: typing.Union['QNearFieldShareManager.ShareModes', 'QNearFieldShareManager.ShareMode', int]) -> 'QNearFieldShareManager.ShareModes': ... + def __xor__(self, other: typing.Union['QNearFieldShareManager.ShareModes', 'QNearFieldShareManager.ShareMode', int]) -> 'QNearFieldShareManager.ShareModes': ... + def __ror__ (self, other: 'QNearFieldShareManager.ShareMode') -> 'QNearFieldShareManager.ShareModes': ... + def __rand__(self, other: 'QNearFieldShareManager.ShareMode') -> 'QNearFieldShareManager.ShareModes': ... + def __rxor__(self, other: 'QNearFieldShareManager.ShareMode') -> 'QNearFieldShareManager.ShareModes': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def error(self, error: 'QNearFieldShareManager.ShareError') -> None: ... - def shareModesChanged(self, modes: typing.Union['QNearFieldShareManager.ShareModes', 'QNearFieldShareManager.ShareMode']) -> None: ... - def targetDetected(self, shareTarget: 'QNearFieldShareTarget') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] + shareModesChanged: typing.ClassVar[QtCore.pyqtSignal] + targetDetected: typing.ClassVar[QtCore.pyqtSignal] def shareError(self) -> 'QNearFieldShareManager.ShareError': ... def shareModes(self) -> 'QNearFieldShareManager.ShareModes': ... def setShareModes(self, modes: typing.Union['QNearFieldShareManager.ShareModes', 'QNearFieldShareManager.ShareMode']) -> None: ... @@ -353,8 +375,8 @@ class QNearFieldShareManager(QtCore.QObject): class QNearFieldShareTarget(QtCore.QObject): - def shareFinished(self) -> None: ... - def error(self, error: QNearFieldShareManager.ShareError) -> None: ... + shareFinished: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] def shareError(self) -> QNearFieldShareManager.ShareError: ... def isShareInProgress(self) -> bool: ... def cancel(self) -> None: ... @@ -391,6 +413,9 @@ class QNearFieldTarget(QtCore.QObject): CommandError = ... # type: QNearFieldTarget.Error class AccessMethod(int): + def __or__ (self, other: 'QNearFieldTarget.AccessMethod') -> 'QNearFieldTarget.AccessMethods': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QNearFieldTarget.AccessMethods': ... # type: ignore[override, misc] + UnknownAccess = ... # type: QNearFieldTarget.AccessMethod NdefAccess = ... # type: QNearFieldTarget.AccessMethod TagTypeSpecificAccess = ... # type: QNearFieldTarget.AccessMethod @@ -424,12 +449,20 @@ class QNearFieldTarget(QtCore.QObject): def __init__(self, f: typing.Union['QNearFieldTarget.AccessMethods', 'QNearFieldTarget.AccessMethod']) -> None: ... @typing.overload def __init__(self, a0: 'QNearFieldTarget.AccessMethods') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QNearFieldTarget.AccessMethods': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QNearFieldTarget.AccessMethods', 'QNearFieldTarget.AccessMethod', int]) -> 'QNearFieldTarget.AccessMethods': ... + def __and__(self, other: typing.Union['QNearFieldTarget.AccessMethods', 'QNearFieldTarget.AccessMethod', int]) -> 'QNearFieldTarget.AccessMethods': ... + def __xor__(self, other: typing.Union['QNearFieldTarget.AccessMethods', 'QNearFieldTarget.AccessMethod', int]) -> 'QNearFieldTarget.AccessMethods': ... + def __ror__ (self, other: 'QNearFieldTarget.AccessMethod') -> 'QNearFieldTarget.AccessMethods': ... + def __rand__(self, other: 'QNearFieldTarget.AccessMethod') -> 'QNearFieldTarget.AccessMethods': ... + def __rxor__(self, other: 'QNearFieldTarget.AccessMethod') -> 'QNearFieldTarget.AccessMethods': ... class RequestId(sip.simplewrapper): @@ -447,11 +480,11 @@ class QNearFieldTarget(QtCore.QObject): def disconnect(self) -> bool: ... # type: ignore[override] def setKeepConnection(self, isPersistent: bool) -> bool: ... def keepConnection(self) -> bool: ... - def error(self, error: 'QNearFieldTarget.Error', id: 'QNearFieldTarget.RequestId') -> None: ... - def requestCompleted(self, id: 'QNearFieldTarget.RequestId') -> None: ... - def ndefMessagesWritten(self) -> None: ... - def ndefMessageRead(self, message: QNdefMessage) -> None: ... - def disconnected(self) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] + requestCompleted: typing.ClassVar[QtCore.pyqtSignal] + ndefMessagesWritten: typing.ClassVar[QtCore.pyqtSignal] + ndefMessageRead: typing.ClassVar[QtCore.pyqtSignal] + disconnected: typing.ClassVar[QtCore.pyqtSignal] def reportError(self, error: 'QNearFieldTarget.Error', id: 'QNearFieldTarget.RequestId') -> None: ... def handleResponse(self, id: 'QNearFieldTarget.RequestId', response: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> bool: ... def setResponseForRequest(self, id: 'QNearFieldTarget.RequestId', response: typing.Any, emitRequestCompleted: bool = ...) -> None: ... @@ -491,9 +524,9 @@ class QQmlNdefRecord(QtCore.QObject): @typing.overload def __init__(self, record: QNdefRecord, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def recordChanged(self) -> None: ... - def typeNameFormatChanged(self) -> None: ... - def typeChanged(self) -> None: ... + recordChanged: typing.ClassVar[QtCore.pyqtSignal] + typeNameFormatChanged: typing.ClassVar[QtCore.pyqtSignal] + typeChanged: typing.ClassVar[QtCore.pyqtSignal] def setRecord(self, record: QNdefRecord) -> None: ... def record(self) -> QNdefRecord: ... def typeNameFormat(self) -> 'QQmlNdefRecord.TypeNameFormat': ... diff --git a/PyQt5-stubs/QtOpenGL.pyi b/PyQt5-stubs/QtOpenGL.pyi index 71863f1a..f585dfa3 100644 --- a/PyQt5-stubs/QtOpenGL.pyi +++ b/PyQt5-stubs/QtOpenGL.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtOpenGL module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -44,6 +44,9 @@ PYQT_OPENGL_BOUND_ARRAY = typing.Union[typing.Sequence[int], class QGL(sip.simplewrapper): class FormatOption(int): + def __or__ (self, other: 'QGL.FormatOption') -> 'QGL.FormatOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGL.FormatOptions': ... # type: ignore[override, misc] + DoubleBuffer = ... # type: QGL.FormatOption DepthBuffer = ... # type: QGL.FormatOption Rgba = ... # type: QGL.FormatOption @@ -98,12 +101,20 @@ class QGL(sip.simplewrapper): def __init__(self, f: typing.Union['QGL.FormatOptions', 'QGL.FormatOption']) -> None: ... @typing.overload def __init__(self, a0: 'QGL.FormatOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGL.FormatOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGL.FormatOptions', 'QGL.FormatOption', int]) -> 'QGL.FormatOptions': ... + def __and__(self, other: typing.Union['QGL.FormatOptions', 'QGL.FormatOption', int]) -> 'QGL.FormatOptions': ... + def __xor__(self, other: typing.Union['QGL.FormatOptions', 'QGL.FormatOption', int]) -> 'QGL.FormatOptions': ... + def __ror__ (self, other: 'QGL.FormatOption') -> 'QGL.FormatOptions': ... + def __rand__(self, other: 'QGL.FormatOption') -> 'QGL.FormatOptions': ... + def __rxor__(self, other: 'QGL.FormatOption') -> 'QGL.FormatOptions': ... class QGLFormat(sip.simplewrapper): @@ -118,6 +129,9 @@ class QGLFormat(sip.simplewrapper): CompatibilityProfile = ... # type: QGLFormat.OpenGLContextProfile class OpenGLVersionFlag(int): + def __or__ (self, other: 'QGLFormat.OpenGLVersionFlag') -> 'QGLFormat.OpenGLVersionFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGLFormat.OpenGLVersionFlags': ... # type: ignore[override, misc] + OpenGL_Version_None = ... # type: QGLFormat.OpenGLVersionFlag OpenGL_Version_1_1 = ... # type: QGLFormat.OpenGLVersionFlag OpenGL_Version_1_2 = ... # type: QGLFormat.OpenGLVersionFlag @@ -170,12 +184,20 @@ class QGLFormat(sip.simplewrapper): def __init__(self, f: typing.Union['QGLFormat.OpenGLVersionFlags', 'QGLFormat.OpenGLVersionFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QGLFormat.OpenGLVersionFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGLFormat.OpenGLVersionFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGLFormat.OpenGLVersionFlags', 'QGLFormat.OpenGLVersionFlag', int]) -> 'QGLFormat.OpenGLVersionFlags': ... + def __and__(self, other: typing.Union['QGLFormat.OpenGLVersionFlags', 'QGLFormat.OpenGLVersionFlag', int]) -> 'QGLFormat.OpenGLVersionFlags': ... + def __xor__(self, other: typing.Union['QGLFormat.OpenGLVersionFlags', 'QGLFormat.OpenGLVersionFlag', int]) -> 'QGLFormat.OpenGLVersionFlags': ... + def __ror__ (self, other: 'QGLFormat.OpenGLVersionFlag') -> 'QGLFormat.OpenGLVersionFlags': ... + def __rand__(self, other: 'QGLFormat.OpenGLVersionFlag') -> 'QGLFormat.OpenGLVersionFlags': ... + def __rxor__(self, other: 'QGLFormat.OpenGLVersionFlag') -> 'QGLFormat.OpenGLVersionFlags': ... @typing.overload def __init__(self) -> None: ... @@ -250,6 +272,9 @@ class QGLFormat(sip.simplewrapper): class QGLContext(sip.wrapper): class BindOption(int): + def __or__ (self, other: 'QGLContext.BindOption') -> 'QGLContext.BindOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGLContext.BindOptions': ... # type: ignore[override, misc] + NoBindOption = ... # type: QGLContext.BindOption InvertedYBindOption = ... # type: QGLContext.BindOption MipmapBindOption = ... # type: QGLContext.BindOption @@ -272,12 +297,20 @@ class QGLContext(sip.wrapper): def __init__(self, f: typing.Union['QGLContext.BindOptions', 'QGLContext.BindOption']) -> None: ... @typing.overload def __init__(self, a0: 'QGLContext.BindOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGLContext.BindOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGLContext.BindOptions', 'QGLContext.BindOption', int]) -> 'QGLContext.BindOptions': ... + def __and__(self, other: typing.Union['QGLContext.BindOptions', 'QGLContext.BindOption', int]) -> 'QGLContext.BindOptions': ... + def __xor__(self, other: typing.Union['QGLContext.BindOptions', 'QGLContext.BindOption', int]) -> 'QGLContext.BindOptions': ... + def __ror__ (self, other: 'QGLContext.BindOption') -> 'QGLContext.BindOptions': ... + def __rand__(self, other: 'QGLContext.BindOption') -> 'QGLContext.BindOptions': ... + def __rxor__(self, other: 'QGLContext.BindOption') -> 'QGLContext.BindOptions': ... def __init__(self, format: QGLFormat) -> None: ... diff --git a/PyQt5-stubs/QtPositioning.pyi b/PyQt5-stubs/QtPositioning.pyi index de57e255..15e0d32c 100644 --- a/PyQt5-stubs/QtPositioning.pyi +++ b/PyQt5-stubs/QtPositioning.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtPositioning module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -111,18 +111,26 @@ class QGeoAreaMonitorSource(QtCore.QObject): def __init__(self, f: typing.Union['QGeoAreaMonitorSource.AreaMonitorFeatures', 'QGeoAreaMonitorSource.AreaMonitorFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoAreaMonitorSource.AreaMonitorFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoAreaMonitorSource.AreaMonitorFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoAreaMonitorSource.AreaMonitorFeatures', 'QGeoAreaMonitorSource.AreaMonitorFeature', int]) -> 'QGeoAreaMonitorSource.AreaMonitorFeatures': ... + def __and__(self, other: typing.Union['QGeoAreaMonitorSource.AreaMonitorFeatures', 'QGeoAreaMonitorSource.AreaMonitorFeature', int]) -> 'QGeoAreaMonitorSource.AreaMonitorFeatures': ... + def __xor__(self, other: typing.Union['QGeoAreaMonitorSource.AreaMonitorFeatures', 'QGeoAreaMonitorSource.AreaMonitorFeature', int]) -> 'QGeoAreaMonitorSource.AreaMonitorFeatures': ... + def __ror__ (self, other: 'QGeoAreaMonitorSource.AreaMonitorFeature') -> 'QGeoAreaMonitorSource.AreaMonitorFeatures': ... + def __rand__(self, other: 'QGeoAreaMonitorSource.AreaMonitorFeature') -> 'QGeoAreaMonitorSource.AreaMonitorFeatures': ... + def __rxor__(self, other: 'QGeoAreaMonitorSource.AreaMonitorFeature') -> 'QGeoAreaMonitorSource.AreaMonitorFeatures': ... def __init__(self, parent: QtCore.QObject) -> None: ... - def monitorExpired(self, monitor: QGeoAreaMonitorInfo) -> None: ... - def areaExited(self, monitor: QGeoAreaMonitorInfo, update: 'QGeoPositionInfo') -> None: ... - def areaEntered(self, monitor: QGeoAreaMonitorInfo, update: 'QGeoPositionInfo') -> None: ... + monitorExpired: typing.ClassVar[QtCore.pyqtSignal] + areaExited: typing.ClassVar[QtCore.pyqtSignal] + areaEntered: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def activeMonitors(self) -> typing.List[QGeoAreaMonitorInfo]: ... @typing.overload @@ -131,10 +139,7 @@ class QGeoAreaMonitorSource(QtCore.QObject): def stopMonitoring(self, monitor: QGeoAreaMonitorInfo) -> bool: ... def startMonitoring(self, monitor: QGeoAreaMonitorInfo) -> bool: ... def supportedAreaMonitorFeatures(self) -> 'QGeoAreaMonitorSource.AreaMonitorFeatures': ... - @typing.overload - def error(self) -> 'QGeoAreaMonitorSource.Error': ... - @typing.overload - def error(self, error: 'QGeoAreaMonitorSource.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def sourceName(self) -> str: ... def positionInfoSource(self) -> 'QGeoPositionInfoSource': ... def setPositionInfoSource(self, source: 'QGeoPositionInfoSource') -> None: ... @@ -374,6 +379,9 @@ class QGeoPositionInfo(sip.wrapper): class QGeoPositionInfoSource(QtCore.QObject): class PositioningMethod(int): + def __or__ (self, other: 'QGeoPositionInfoSource.PositioningMethod') -> 'QGeoPositionInfoSource.PositioningMethods': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGeoPositionInfoSource.PositioningMethods': ... # type: ignore[override, misc] + NoPositioningMethods = ... # type: QGeoPositionInfoSource.PositioningMethod SatellitePositioningMethods = ... # type: QGeoPositionInfoSource.PositioningMethod NonSatellitePositioningMethods = ... # type: QGeoPositionInfoSource.PositioningMethod @@ -403,20 +411,28 @@ class QGeoPositionInfoSource(QtCore.QObject): def __init__(self, f: typing.Union['QGeoPositionInfoSource.PositioningMethods', 'QGeoPositionInfoSource.PositioningMethod']) -> None: ... @typing.overload def __init__(self, a0: 'QGeoPositionInfoSource.PositioningMethods') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGeoPositionInfoSource.PositioningMethods': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGeoPositionInfoSource.PositioningMethods', 'QGeoPositionInfoSource.PositioningMethod', int]) -> 'QGeoPositionInfoSource.PositioningMethods': ... + def __and__(self, other: typing.Union['QGeoPositionInfoSource.PositioningMethods', 'QGeoPositionInfoSource.PositioningMethod', int]) -> 'QGeoPositionInfoSource.PositioningMethods': ... + def __xor__(self, other: typing.Union['QGeoPositionInfoSource.PositioningMethods', 'QGeoPositionInfoSource.PositioningMethod', int]) -> 'QGeoPositionInfoSource.PositioningMethods': ... + def __ror__ (self, other: 'QGeoPositionInfoSource.PositioningMethod') -> 'QGeoPositionInfoSource.PositioningMethods': ... + def __rand__(self, other: 'QGeoPositionInfoSource.PositioningMethod') -> 'QGeoPositionInfoSource.PositioningMethods': ... + def __rxor__(self, other: 'QGeoPositionInfoSource.PositioningMethod') -> 'QGeoPositionInfoSource.PositioningMethods': ... def __init__(self, parent: QtCore.QObject) -> None: ... def backendProperty(self, name: str) -> typing.Any: ... def setBackendProperty(self, name: str, value: typing.Any) -> bool: ... - def supportedPositioningMethodsChanged(self) -> None: ... - def updateTimeout(self) -> None: ... - def positionUpdated(self, update: QGeoPositionInfo) -> None: ... + supportedPositioningMethodsChanged: typing.ClassVar[QtCore.pyqtSignal] + updateTimeout: typing.ClassVar[QtCore.pyqtSignal] + positionUpdated: typing.ClassVar[QtCore.pyqtSignal] def requestUpdate(self, timeout: int = ...) -> None: ... def stopUpdates(self) -> None: ... def startUpdates(self) -> None: ... @@ -534,16 +550,13 @@ class QGeoSatelliteInfoSource(QtCore.QObject): def __init__(self, parent: QtCore.QObject) -> None: ... - def requestTimeout(self) -> None: ... - def satellitesInUseUpdated(self, satellites: typing.Iterable[QGeoSatelliteInfo]) -> None: ... - def satellitesInViewUpdated(self, satellites: typing.Iterable[QGeoSatelliteInfo]) -> None: ... + requestTimeout: typing.ClassVar[QtCore.pyqtSignal] + satellitesInUseUpdated: typing.ClassVar[QtCore.pyqtSignal] + satellitesInViewUpdated: typing.ClassVar[QtCore.pyqtSignal] def requestUpdate(self, timeout: int = ...) -> None: ... def stopUpdates(self) -> None: ... def startUpdates(self) -> None: ... - @typing.overload - def error(self) -> 'QGeoSatelliteInfoSource.Error': ... - @typing.overload - def error(self, a0: 'QGeoSatelliteInfoSource.Error') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def minimumUpdateInterval(self) -> int: ... def updateInterval(self) -> int: ... def setUpdateInterval(self, msec: int) -> None: ... diff --git a/PyQt5-stubs/QtPrintSupport.pyi b/PyQt5-stubs/QtPrintSupport.pyi index c49a0efa..6d97433f 100644 --- a/PyQt5-stubs/QtPrintSupport.pyi +++ b/PyQt5-stubs/QtPrintSupport.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtPrintSupport module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -44,6 +44,9 @@ PYQT_OPENGL_BOUND_ARRAY = typing.Union[typing.Sequence[int], class QAbstractPrintDialog(QtWidgets.QDialog): class PrintDialogOption(int): + def __or__ (self, other: 'QAbstractPrintDialog.PrintDialogOption') -> 'QAbstractPrintDialog.PrintDialogOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QAbstractPrintDialog.PrintDialogOptions': ... # type: ignore[override, misc] + None_ = ... # type: QAbstractPrintDialog.PrintDialogOption PrintToFile = ... # type: QAbstractPrintDialog.PrintDialogOption PrintSelection = ... # type: QAbstractPrintDialog.PrintDialogOption @@ -79,12 +82,20 @@ class QAbstractPrintDialog(QtWidgets.QDialog): def __init__(self, f: typing.Union['QAbstractPrintDialog.PrintDialogOptions', 'QAbstractPrintDialog.PrintDialogOption']) -> None: ... @typing.overload def __init__(self, a0: 'QAbstractPrintDialog.PrintDialogOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QAbstractPrintDialog.PrintDialogOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QAbstractPrintDialog.PrintDialogOptions', 'QAbstractPrintDialog.PrintDialogOption', int]) -> 'QAbstractPrintDialog.PrintDialogOptions': ... + def __and__(self, other: typing.Union['QAbstractPrintDialog.PrintDialogOptions', 'QAbstractPrintDialog.PrintDialogOption', int]) -> 'QAbstractPrintDialog.PrintDialogOptions': ... + def __xor__(self, other: typing.Union['QAbstractPrintDialog.PrintDialogOptions', 'QAbstractPrintDialog.PrintDialogOption', int]) -> 'QAbstractPrintDialog.PrintDialogOptions': ... + def __ror__ (self, other: 'QAbstractPrintDialog.PrintDialogOption') -> 'QAbstractPrintDialog.PrintDialogOptions': ... + def __rand__(self, other: 'QAbstractPrintDialog.PrintDialogOption') -> 'QAbstractPrintDialog.PrintDialogOptions': ... + def __rxor__(self, other: 'QAbstractPrintDialog.PrintDialogOption') -> 'QAbstractPrintDialog.PrintDialogOptions': ... def __init__(self, printer: 'QPrinter', parent: typing.Optional[QtWidgets.QWidget] = ...) -> None: ... @@ -129,10 +140,7 @@ class QPrintDialog(QAbstractPrintDialog): @typing.overload def __init__(self, parent: typing.Optional[QtWidgets.QWidget] = ...) -> None: ... - @typing.overload # type: ignore[override] - def accepted(self) -> None: ... - @typing.overload - def accepted(self, printer: 'QPrinter') -> None: ... + accepted: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def open(self) -> None: ... @typing.overload diff --git a/PyQt5-stubs/QtPurchasing.pyi b/PyQt5-stubs/QtPurchasing.pyi index 5dc2605a..9b02f226 100644 --- a/PyQt5-stubs/QtPurchasing.pyi +++ b/PyQt5-stubs/QtPurchasing.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtPurchasing module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -53,9 +53,9 @@ class QInAppStore(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def transactionReady(self, transaction: 'QInAppTransaction') -> None: ... - def productUnknown(self, productType: QInAppProduct.ProductType, identifier: str) -> None: ... - def productRegistered(self, product: QInAppProduct) -> None: ... + transactionReady: typing.ClassVar[QtCore.pyqtSignal] + productUnknown: typing.ClassVar[QtCore.pyqtSignal] + productRegistered: typing.ClassVar[QtCore.pyqtSignal] def setPlatformProperty(self, propertyName: str, value: str) -> None: ... def registeredProduct(self, identifier: str) -> QInAppProduct: ... def registerProduct(self, productType: QInAppProduct.ProductType, identifier: str) -> None: ... diff --git a/PyQt5-stubs/QtQml.pyi b/PyQt5-stubs/QtQml.pyi index 78e530bd..56b7f42a 100644 --- a/PyQt5-stubs/QtQml.pyi +++ b/PyQt5-stubs/QtQml.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtQml module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -36,6 +36,9 @@ PYQT_SLOT = typing.Union[typing.Callable[..., None], QtCore.pyqtBoundSignal] class QJSEngine(QtCore.QObject): class Extension(int): + def __or__ (self, other: 'QJSEngine.Extension') -> 'QJSEngine.Extensions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QJSEngine.Extensions': ... # type: ignore[override, misc] + TranslationExtension = ... # type: QJSEngine.Extension ConsoleExtension = ... # type: QJSEngine.Extension GarbageCollectionExtension = ... # type: QJSEngine.Extension @@ -54,19 +57,27 @@ class QJSEngine(QtCore.QObject): def __init__(self, f: typing.Union['QJSEngine.Extensions', 'QJSEngine.Extension']) -> None: ... @typing.overload def __init__(self, a0: 'QJSEngine.Extensions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QJSEngine.Extensions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QJSEngine.Extensions', 'QJSEngine.Extension', int]) -> 'QJSEngine.Extensions': ... + def __and__(self, other: typing.Union['QJSEngine.Extensions', 'QJSEngine.Extension', int]) -> 'QJSEngine.Extensions': ... + def __xor__(self, other: typing.Union['QJSEngine.Extensions', 'QJSEngine.Extension', int]) -> 'QJSEngine.Extensions': ... + def __ror__ (self, other: 'QJSEngine.Extension') -> 'QJSEngine.Extensions': ... + def __rand__(self, other: 'QJSEngine.Extension') -> 'QJSEngine.Extensions': ... + def __rxor__(self, other: 'QJSEngine.Extension') -> 'QJSEngine.Extensions': ... @typing.overload def __init__(self) -> None: ... @typing.overload def __init__(self, parent: QtCore.QObject) -> None: ... - def uiLanguageChanged(self) -> None: ... + uiLanguageChanged: typing.ClassVar[QtCore.pyqtSignal] def setUiLanguage(self, language: str) -> None: ... def uiLanguage(self) -> str: ... def isInterrupted(self) -> bool: ... @@ -299,8 +310,8 @@ class QQmlComponent(QtCore.QObject): def setInitialProperties(self, component: QtCore.QObject, properties: typing.Dict[str, typing.Any]) -> None: ... def engine(self) -> QQmlEngine: ... - def progressChanged(self, a0: float) -> None: ... - def statusChanged(self, a0: 'QQmlComponent.Status') -> None: ... + progressChanged: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] def setData(self, a0: typing.Union[QtCore.QByteArray, bytes, bytearray], baseUrl: QtCore.QUrl) -> None: ... @typing.overload def loadUrl(self, url: QtCore.QUrl) -> None: ... @@ -361,6 +372,9 @@ class QQmlContext(QtCore.QObject): class QQmlImageProviderBase(sip.wrapper): class Flag(int): + def __or__ (self, other: 'QQmlImageProviderBase.Flag') -> 'QQmlImageProviderBase.Flags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QQmlImageProviderBase.Flags': ... # type: ignore[override, misc] + ForceAsynchronousImageLoading = ... # type: QQmlImageProviderBase.Flag ForceAsynchronousImageLoading = ... # type: QQmlImageProviderBase.Flag @@ -384,12 +398,20 @@ class QQmlImageProviderBase(sip.wrapper): def __init__(self, f: typing.Union['QQmlImageProviderBase.Flags', 'QQmlImageProviderBase.Flag']) -> None: ... @typing.overload def __init__(self, a0: 'QQmlImageProviderBase.Flags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QQmlImageProviderBase.Flags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QQmlImageProviderBase.Flags', 'QQmlImageProviderBase.Flag', int]) -> 'QQmlImageProviderBase.Flags': ... + def __and__(self, other: typing.Union['QQmlImageProviderBase.Flags', 'QQmlImageProviderBase.Flag', int]) -> 'QQmlImageProviderBase.Flags': ... + def __xor__(self, other: typing.Union['QQmlImageProviderBase.Flags', 'QQmlImageProviderBase.Flag', int]) -> 'QQmlImageProviderBase.Flags': ... + def __ror__ (self, other: 'QQmlImageProviderBase.Flag') -> 'QQmlImageProviderBase.Flags': ... + def __rand__(self, other: 'QQmlImageProviderBase.Flag') -> 'QQmlImageProviderBase.Flags': ... + def __rxor__(self, other: 'QQmlImageProviderBase.Flag') -> 'QQmlImageProviderBase.Flags': ... def __init__(self, a0: 'QQmlImageProviderBase') -> None: ... @@ -429,7 +451,7 @@ class QQmlExpression(QtCore.QObject): @typing.overload def __init__(self, a0: 'QQmlScriptString', context: typing.Optional[QQmlContext] = ..., scope: typing.Optional[QtCore.QObject] = ..., parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def valueChanged(self) -> None: ... + valueChanged: typing.ClassVar[QtCore.pyqtSignal] def evaluate(self) -> typing.Tuple[typing.Any, bool]: ... def error(self) -> QQmlError: ... def clearError(self) -> None: ... @@ -663,7 +685,7 @@ class QQmlPropertyMap(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def updateValue(self, key: str, input: typing.Any) -> typing.Any: ... - def valueChanged(self, key: str, value: typing.Any) -> None: ... + valueChanged: typing.ClassVar[QtCore.pyqtSignal] def __getitem__(self, key: str) -> typing.Any: ... def contains(self, key: str) -> bool: ... def isEmpty(self) -> bool: ... diff --git a/PyQt5-stubs/QtQuick.pyi b/PyQt5-stubs/QtQuick.pyi index 0f9ea248..2b0f5285 100644 --- a/PyQt5-stubs/QtQuick.pyi +++ b/PyQt5-stubs/QtQuick.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtQuick module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -89,6 +89,9 @@ class QQuickItem(QtCore.QObject, QtQml.QQmlParserStatus): ItemEnabledHasChanged = ... # type: QQuickItem.ItemChange class Flag(int): + def __or__ (self, other: 'QQuickItem.Flag') -> 'QQuickItem.Flags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QQuickItem.Flags': ... # type: ignore[override, misc] + ItemClipsChildrenToShape = ... # type: QQuickItem.Flag ItemAcceptsInputMethod = ... # type: QQuickItem.Flag ItemIsFocusScope = ... # type: QQuickItem.Flag @@ -109,12 +112,20 @@ class QQuickItem(QtCore.QObject, QtQml.QQmlParserStatus): def __init__(self, f: typing.Union['QQuickItem.Flags', 'QQuickItem.Flag']) -> None: ... @typing.overload def __init__(self, a0: 'QQuickItem.Flags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QQuickItem.Flags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QQuickItem.Flags', 'QQuickItem.Flag', int]) -> 'QQuickItem.Flags': ... + def __and__(self, other: typing.Union['QQuickItem.Flags', 'QQuickItem.Flag', int]) -> 'QQuickItem.Flags': ... + def __xor__(self, other: typing.Union['QQuickItem.Flags', 'QQuickItem.Flag', int]) -> 'QQuickItem.Flags': ... + def __ror__ (self, other: 'QQuickItem.Flag') -> 'QQuickItem.Flags': ... + def __rand__(self, other: 'QQuickItem.Flag') -> 'QQuickItem.Flags': ... + def __rxor__(self, other: 'QQuickItem.Flag') -> 'QQuickItem.Flags': ... class ItemChangeData(sip.simplewrapper): @@ -142,7 +153,7 @@ class QQuickItem(QtCore.QObject, QtQml.QQmlParserStatus): def __init__(self, parent: typing.Optional['QQuickItem'] = ...) -> None: ... - def containmentMaskChanged(self) -> None: ... + containmentMaskChanged: typing.ClassVar[QtCore.pyqtSignal] def setContainmentMask(self, mask: QtCore.QObject) -> None: ... def containmentMask(self) -> QtCore.QObject: ... def setAcceptTouchEvents(self, accept: bool) -> None: ... @@ -153,7 +164,7 @@ class QQuickItem(QtCore.QObject, QtQml.QQmlParserStatus): def isAncestorOf(self, child: 'QQuickItem') -> bool: ... def grabToImage(self, targetSize: QtCore.QSize = ...) -> 'QQuickItemGrabResult': ... def resetAntialiasing(self) -> None: ... - def windowChanged(self, window: 'QQuickWindow') -> None: ... + windowChanged: typing.ClassVar[QtCore.pyqtSignal] def nextItemInFocusChain(self, forward: bool = ...) -> 'QQuickItem': ... def setActiveFocusOnTab(self, a0: bool) -> None: ... def activeFocusOnTab(self) -> bool: ... @@ -302,13 +313,13 @@ class QQuickFramebufferObject(QQuickItem): def __init__(self, parent: typing.Optional[QQuickItem] = ...) -> None: ... - def mirrorVerticallyChanged(self, a0: bool) -> None: ... + mirrorVerticallyChanged: typing.ClassVar[QtCore.pyqtSignal] def setMirrorVertically(self, enable: bool) -> None: ... def mirrorVertically(self) -> bool: ... def releaseResources(self) -> None: ... def textureProvider(self) -> 'QSGTextureProvider': ... def isTextureProvider(self) -> bool: ... - def textureFollowsItemSizeChanged(self, a0: bool) -> None: ... + textureFollowsItemSizeChanged: typing.ClassVar[QtCore.pyqtSignal] def updatePaintNode(self, a0: 'QSGNode', a1: QQuickItem.UpdatePaintNodeData) -> 'QSGNode': ... def geometryChanged(self, newGeometry: QtCore.QRectF, oldGeometry: QtCore.QRectF) -> None: ... def createRenderer(self) -> 'QQuickFramebufferObject.Renderer': ... @@ -346,7 +357,7 @@ class QQuickImageResponse(QtCore.QObject): def __init__(self) -> None: ... - def finished(self) -> None: ... + finished: typing.ClassVar[QtCore.pyqtSignal] def cancel(self) -> None: ... def errorString(self) -> str: ... def textureFactory(self) -> QQuickTextureFactory: ... @@ -364,7 +375,7 @@ class QQuickAsyncImageProvider(QQuickImageProvider): class QQuickItemGrabResult(QtCore.QObject): - def ready(self) -> None: ... + ready: typing.ClassVar[QtCore.pyqtSignal] def event(self, a0: QtCore.QEvent) -> bool: ... def saveToFile(self, fileName: str) -> bool: ... def url(self) -> QtCore.QUrl: ... @@ -374,6 +385,9 @@ class QQuickItemGrabResult(QtCore.QObject): class QQuickPaintedItem(QQuickItem): class PerformanceHint(int): + def __or__ (self, other: 'QQuickPaintedItem.PerformanceHint') -> 'QQuickPaintedItem.PerformanceHints': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QQuickPaintedItem.PerformanceHints': ... # type: ignore[override, misc] + FastFBOResizing = ... # type: QQuickPaintedItem.PerformanceHint FastFBOResizing = ... # type: QQuickPaintedItem.PerformanceHint @@ -395,16 +409,24 @@ class QQuickPaintedItem(QQuickItem): def __init__(self, f: typing.Union['QQuickPaintedItem.PerformanceHints', 'QQuickPaintedItem.PerformanceHint']) -> None: ... @typing.overload def __init__(self, a0: 'QQuickPaintedItem.PerformanceHints') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QQuickPaintedItem.PerformanceHints': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QQuickPaintedItem.PerformanceHints', 'QQuickPaintedItem.PerformanceHint', int]) -> 'QQuickPaintedItem.PerformanceHints': ... + def __and__(self, other: typing.Union['QQuickPaintedItem.PerformanceHints', 'QQuickPaintedItem.PerformanceHint', int]) -> 'QQuickPaintedItem.PerformanceHints': ... + def __xor__(self, other: typing.Union['QQuickPaintedItem.PerformanceHints', 'QQuickPaintedItem.PerformanceHint', int]) -> 'QQuickPaintedItem.PerformanceHints': ... + def __ror__ (self, other: 'QQuickPaintedItem.PerformanceHint') -> 'QQuickPaintedItem.PerformanceHints': ... + def __rand__(self, other: 'QQuickPaintedItem.PerformanceHint') -> 'QQuickPaintedItem.PerformanceHints': ... + def __rxor__(self, other: 'QQuickPaintedItem.PerformanceHint') -> 'QQuickPaintedItem.PerformanceHints': ... def __init__(self, parent: typing.Optional[QQuickItem] = ...) -> None: ... - def textureSizeChanged(self) -> None: ... + textureSizeChanged: typing.ClassVar[QtCore.pyqtSignal] def setTextureSize(self, size: QtCore.QSize) -> None: ... def textureSize(self) -> QtCore.QSize: ... def itemChange(self, a0: QQuickItem.ItemChange, a1: QQuickItem.ItemChangeData) -> None: ... @@ -412,10 +434,10 @@ class QQuickPaintedItem(QQuickItem): def textureProvider(self) -> 'QSGTextureProvider': ... def isTextureProvider(self) -> bool: ... def updatePaintNode(self, a0: 'QSGNode', a1: QQuickItem.UpdatePaintNodeData) -> 'QSGNode': ... - def renderTargetChanged(self) -> None: ... - def contentsScaleChanged(self) -> None: ... - def contentsSizeChanged(self) -> None: ... - def fillColorChanged(self) -> None: ... + renderTargetChanged: typing.ClassVar[QtCore.pyqtSignal] + contentsScaleChanged: typing.ClassVar[QtCore.pyqtSignal] + contentsSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + fillColorChanged: typing.ClassVar[QtCore.pyqtSignal] def paint(self, painter: QtGui.QPainter) -> None: ... def setRenderTarget(self, target: 'QQuickPaintedItem.RenderTarget') -> None: ... def renderTarget(self) -> 'QQuickPaintedItem.RenderTarget': ... @@ -443,8 +465,8 @@ class QQuickRenderControl(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def sceneChanged(self) -> None: ... - def renderRequested(self) -> None: ... + sceneChanged: typing.ClassVar[QtCore.pyqtSignal] + renderRequested: typing.ClassVar[QtCore.pyqtSignal] def prepareThread(self, targetThread: QtCore.QThread) -> None: ... def renderWindow(self, offset: QtCore.QPoint) -> QtGui.QWindow: ... @staticmethod @@ -519,12 +541,20 @@ class QQuickWindow(QtGui.QWindow): def __init__(self, f: typing.Union['QQuickWindow.CreateTextureOptions', 'QQuickWindow.CreateTextureOption']) -> None: ... @typing.overload def __init__(self, a0: 'QQuickWindow.CreateTextureOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QQuickWindow.CreateTextureOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QQuickWindow.CreateTextureOptions', 'QQuickWindow.CreateTextureOption', int]) -> 'QQuickWindow.CreateTextureOptions': ... + def __and__(self, other: typing.Union['QQuickWindow.CreateTextureOptions', 'QQuickWindow.CreateTextureOption', int]) -> 'QQuickWindow.CreateTextureOptions': ... + def __xor__(self, other: typing.Union['QQuickWindow.CreateTextureOptions', 'QQuickWindow.CreateTextureOption', int]) -> 'QQuickWindow.CreateTextureOptions': ... + def __ror__ (self, other: 'QQuickWindow.CreateTextureOption') -> 'QQuickWindow.CreateTextureOptions': ... + def __rand__(self, other: 'QQuickWindow.CreateTextureOption') -> 'QQuickWindow.CreateTextureOptions': ... + def __rxor__(self, other: 'QQuickWindow.CreateTextureOption') -> 'QQuickWindow.CreateTextureOptions': ... def __init__(self, parent: typing.Optional[QtGui.QWindow] = ...) -> None: ... @@ -651,7 +681,7 @@ class QQuickView(QQuickWindow): def keyPressEvent(self, a0: QtGui.QKeyEvent) -> None: ... def timerEvent(self, a0: QtCore.QTimerEvent) -> None: ... def resizeEvent(self, a0: QtGui.QResizeEvent) -> None: ... - def statusChanged(self, a0: 'QQuickView.Status') -> None: ... + statusChanged: typing.ClassVar[QtCore.pyqtSignal] def setInitialProperties(self, initialProperties: typing.Dict[str, typing.Any]) -> None: ... def setSource(self, a0: QtCore.QUrl) -> None: ... def initialSize(self) -> QtCore.QSize: ... @@ -676,6 +706,9 @@ class QSGAbstractRenderer(QtCore.QObject): MatrixTransformFlipY = ... # type: QSGAbstractRenderer.MatrixTransformFlag class ClearModeBit(int): + def __or__ (self, other: 'QSGAbstractRenderer.ClearModeBit') -> 'QSGAbstractRenderer.ClearMode': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGAbstractRenderer.ClearMode': ... # type: ignore[override, misc] + ClearColorBuffer = ... # type: QSGAbstractRenderer.ClearModeBit ClearDepthBuffer = ... # type: QSGAbstractRenderer.ClearModeBit ClearStencilBuffer = ... # type: QSGAbstractRenderer.ClearModeBit @@ -692,12 +725,20 @@ class QSGAbstractRenderer(QtCore.QObject): def __init__(self, f: typing.Union['QSGAbstractRenderer.ClearMode', 'QSGAbstractRenderer.ClearModeBit']) -> None: ... @typing.overload def __init__(self, a0: 'QSGAbstractRenderer.ClearMode') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGAbstractRenderer.ClearMode': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGAbstractRenderer.ClearMode', 'QSGAbstractRenderer.ClearModeBit', int]) -> 'QSGAbstractRenderer.ClearMode': ... + def __and__(self, other: typing.Union['QSGAbstractRenderer.ClearMode', 'QSGAbstractRenderer.ClearModeBit', int]) -> 'QSGAbstractRenderer.ClearMode': ... + def __xor__(self, other: typing.Union['QSGAbstractRenderer.ClearMode', 'QSGAbstractRenderer.ClearModeBit', int]) -> 'QSGAbstractRenderer.ClearMode': ... + def __ror__ (self, other: 'QSGAbstractRenderer.ClearModeBit') -> 'QSGAbstractRenderer.ClearMode': ... + def __rand__(self, other: 'QSGAbstractRenderer.ClearModeBit') -> 'QSGAbstractRenderer.ClearMode': ... + def __rxor__(self, other: 'QSGAbstractRenderer.ClearModeBit') -> 'QSGAbstractRenderer.ClearMode': ... class MatrixTransformFlags(sip.simplewrapper): @@ -707,14 +748,22 @@ class QSGAbstractRenderer(QtCore.QObject): def __init__(self, f: typing.Union['QSGAbstractRenderer.MatrixTransformFlags', 'QSGAbstractRenderer.MatrixTransformFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QSGAbstractRenderer.MatrixTransformFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGAbstractRenderer.MatrixTransformFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... - - def sceneGraphChanged(self) -> None: ... + def __or__ (self, other: typing.Union['QSGAbstractRenderer.MatrixTransformFlags', 'QSGAbstractRenderer.MatrixTransformFlag', int]) -> 'QSGAbstractRenderer.MatrixTransformFlags': ... + def __and__(self, other: typing.Union['QSGAbstractRenderer.MatrixTransformFlags', 'QSGAbstractRenderer.MatrixTransformFlag', int]) -> 'QSGAbstractRenderer.MatrixTransformFlags': ... + def __xor__(self, other: typing.Union['QSGAbstractRenderer.MatrixTransformFlags', 'QSGAbstractRenderer.MatrixTransformFlag', int]) -> 'QSGAbstractRenderer.MatrixTransformFlags': ... + def __ror__ (self, other: 'QSGAbstractRenderer.MatrixTransformFlag') -> 'QSGAbstractRenderer.MatrixTransformFlags': ... + def __rand__(self, other: 'QSGAbstractRenderer.MatrixTransformFlag') -> 'QSGAbstractRenderer.MatrixTransformFlags': ... + def __rxor__(self, other: 'QSGAbstractRenderer.MatrixTransformFlag') -> 'QSGAbstractRenderer.MatrixTransformFlags': ... + + sceneGraphChanged: typing.ClassVar[QtCore.pyqtSignal] def renderScene(self, fboId: int = ...) -> None: ... def clearMode(self) -> 'QSGAbstractRenderer.ClearMode': ... def setClearMode(self, mode: typing.Union['QSGAbstractRenderer.ClearMode', 'QSGAbstractRenderer.ClearModeBit']) -> None: ... @@ -759,12 +808,20 @@ class QSGEngine(QtCore.QObject): def __init__(self, f: typing.Union['QSGEngine.CreateTextureOptions', 'QSGEngine.CreateTextureOption']) -> None: ... @typing.overload def __init__(self, a0: 'QSGEngine.CreateTextureOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGEngine.CreateTextureOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGEngine.CreateTextureOptions', 'QSGEngine.CreateTextureOption', int]) -> 'QSGEngine.CreateTextureOptions': ... + def __and__(self, other: typing.Union['QSGEngine.CreateTextureOptions', 'QSGEngine.CreateTextureOption', int]) -> 'QSGEngine.CreateTextureOptions': ... + def __xor__(self, other: typing.Union['QSGEngine.CreateTextureOptions', 'QSGEngine.CreateTextureOption', int]) -> 'QSGEngine.CreateTextureOptions': ... + def __ror__ (self, other: 'QSGEngine.CreateTextureOption') -> 'QSGEngine.CreateTextureOptions': ... + def __rand__(self, other: 'QSGEngine.CreateTextureOption') -> 'QSGEngine.CreateTextureOptions': ... + def __rxor__(self, other: 'QSGEngine.CreateTextureOption') -> 'QSGEngine.CreateTextureOptions': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -781,6 +838,9 @@ class QSGEngine(QtCore.QObject): class QSGMaterial(sip.wrapper): class Flag(int): + def __or__ (self, other: 'QSGMaterial.Flag') -> 'QSGMaterial.Flags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGMaterial.Flags': ... # type: ignore[override, misc] + Blending = ... # type: QSGMaterial.Flag RequiresDeterminant = ... # type: QSGMaterial.Flag RequiresFullMatrixExceptTranslate = ... # type: QSGMaterial.Flag @@ -805,12 +865,20 @@ class QSGMaterial(sip.wrapper): def __init__(self, f: typing.Union['QSGMaterial.Flags', 'QSGMaterial.Flag']) -> None: ... @typing.overload def __init__(self, a0: 'QSGMaterial.Flags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGMaterial.Flags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGMaterial.Flags', 'QSGMaterial.Flag', int]) -> 'QSGMaterial.Flags': ... + def __and__(self, other: typing.Union['QSGMaterial.Flags', 'QSGMaterial.Flag', int]) -> 'QSGMaterial.Flags': ... + def __xor__(self, other: typing.Union['QSGMaterial.Flags', 'QSGMaterial.Flag', int]) -> 'QSGMaterial.Flags': ... + def __ror__ (self, other: 'QSGMaterial.Flag') -> 'QSGMaterial.Flags': ... + def __rand__(self, other: 'QSGMaterial.Flag') -> 'QSGMaterial.Flags': ... + def __rxor__(self, other: 'QSGMaterial.Flag') -> 'QSGMaterial.Flags': ... def __init__(self) -> None: ... @@ -1027,6 +1095,9 @@ class QSGGeometry(sip.wrapper): class QSGNode(sip.wrapper): class DirtyStateBit(int): + def __or__ (self, other: 'QSGNode.DirtyStateBit') -> 'QSGNode.DirtyState': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGNode.DirtyState': ... # type: ignore[override, misc] + DirtyMatrix = ... # type: QSGNode.DirtyStateBit DirtyNodeAdded = ... # type: QSGNode.DirtyStateBit DirtyNodeRemoved = ... # type: QSGNode.DirtyStateBit @@ -1042,6 +1113,9 @@ class QSGNode(sip.wrapper): DirtyOpacity = ... # type: QSGNode.DirtyStateBit class Flag(int): + def __or__ (self, other: 'QSGNode.Flag') -> 'QSGNode.Flags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGNode.Flags': ... # type: ignore[override, misc] + OwnedByParent = ... # type: QSGNode.Flag UsePreprocess = ... # type: QSGNode.Flag OwnsGeometry = ... # type: QSGNode.Flag @@ -1075,12 +1149,20 @@ class QSGNode(sip.wrapper): def __init__(self, f: typing.Union['QSGNode.Flags', 'QSGNode.Flag']) -> None: ... @typing.overload def __init__(self, a0: 'QSGNode.Flags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGNode.Flags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGNode.Flags', 'QSGNode.Flag', int]) -> 'QSGNode.Flags': ... + def __and__(self, other: typing.Union['QSGNode.Flags', 'QSGNode.Flag', int]) -> 'QSGNode.Flags': ... + def __xor__(self, other: typing.Union['QSGNode.Flags', 'QSGNode.Flag', int]) -> 'QSGNode.Flags': ... + def __ror__ (self, other: 'QSGNode.Flag') -> 'QSGNode.Flags': ... + def __rand__(self, other: 'QSGNode.Flag') -> 'QSGNode.Flags': ... + def __rxor__(self, other: 'QSGNode.Flag') -> 'QSGNode.Flags': ... class DirtyState(sip.simplewrapper): @@ -1090,12 +1172,20 @@ class QSGNode(sip.wrapper): def __init__(self, f: typing.Union['QSGNode.DirtyState', 'QSGNode.DirtyStateBit']) -> None: ... @typing.overload def __init__(self, a0: 'QSGNode.DirtyState') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGNode.DirtyState': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGNode.DirtyState', 'QSGNode.DirtyStateBit', int]) -> 'QSGNode.DirtyState': ... + def __and__(self, other: typing.Union['QSGNode.DirtyState', 'QSGNode.DirtyStateBit', int]) -> 'QSGNode.DirtyState': ... + def __xor__(self, other: typing.Union['QSGNode.DirtyState', 'QSGNode.DirtyStateBit', int]) -> 'QSGNode.DirtyState': ... + def __ror__ (self, other: 'QSGNode.DirtyStateBit') -> 'QSGNode.DirtyState': ... + def __rand__(self, other: 'QSGNode.DirtyStateBit') -> 'QSGNode.DirtyState': ... + def __rxor__(self, other: 'QSGNode.DirtyStateBit') -> 'QSGNode.DirtyState': ... def __init__(self) -> None: ... @@ -1141,6 +1231,9 @@ class QSGGeometryNode(QSGBasicGeometryNode): class QSGImageNode(QSGGeometryNode): class TextureCoordinatesTransformFlag(int): + def __or__ (self, other: 'QSGImageNode.TextureCoordinatesTransformFlag') -> 'QSGImageNode.TextureCoordinatesTransformMode': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGImageNode.TextureCoordinatesTransformMode': ... # type: ignore[override, misc] + NoTransform = ... # type: QSGImageNode.TextureCoordinatesTransformFlag MirrorHorizontally = ... # type: QSGImageNode.TextureCoordinatesTransformFlag MirrorVertically = ... # type: QSGImageNode.TextureCoordinatesTransformFlag @@ -1157,12 +1250,20 @@ class QSGImageNode(QSGGeometryNode): def __init__(self, f: typing.Union['QSGImageNode.TextureCoordinatesTransformMode', 'QSGImageNode.TextureCoordinatesTransformFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QSGImageNode.TextureCoordinatesTransformMode') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGImageNode.TextureCoordinatesTransformMode': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGImageNode.TextureCoordinatesTransformMode', 'QSGImageNode.TextureCoordinatesTransformFlag', int]) -> 'QSGImageNode.TextureCoordinatesTransformMode': ... + def __and__(self, other: typing.Union['QSGImageNode.TextureCoordinatesTransformMode', 'QSGImageNode.TextureCoordinatesTransformFlag', int]) -> 'QSGImageNode.TextureCoordinatesTransformMode': ... + def __xor__(self, other: typing.Union['QSGImageNode.TextureCoordinatesTransformMode', 'QSGImageNode.TextureCoordinatesTransformFlag', int]) -> 'QSGImageNode.TextureCoordinatesTransformMode': ... + def __ror__ (self, other: 'QSGImageNode.TextureCoordinatesTransformFlag') -> 'QSGImageNode.TextureCoordinatesTransformMode': ... + def __rand__(self, other: 'QSGImageNode.TextureCoordinatesTransformFlag') -> 'QSGImageNode.TextureCoordinatesTransformMode': ... + def __rxor__(self, other: 'QSGImageNode.TextureCoordinatesTransformFlag') -> 'QSGImageNode.TextureCoordinatesTransformMode': ... @staticmethod def rebuildGeometry(g: QSGGeometry, texture: 'QSGTexture', rect: QtCore.QRectF, sourceRect: QtCore.QRectF, texCoordMode: typing.Union['QSGImageNode.TextureCoordinatesTransformMode', 'QSGImageNode.TextureCoordinatesTransformFlag']) -> None: ... @@ -1263,6 +1364,9 @@ class QSGMaterialType(sip.simplewrapper): class QSGMaterialRhiShader(QSGMaterialShader): class Flag(int): + def __or__ (self, other: 'QSGMaterialRhiShader.Flag') -> 'QSGMaterialRhiShader.Flags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGMaterialRhiShader.Flags': ... # type: ignore[override, misc] + UpdatesGraphicsPipelineState = ... # type: QSGMaterialRhiShader.Flag UpdatesGraphicsPipelineState = ... # type: QSGMaterialRhiShader.Flag @@ -1299,6 +1403,9 @@ class QSGMaterialRhiShader(QSGMaterialShader): CullBack = ... # type: QSGMaterialRhiShader.GraphicsPipelineState.CullMode class ColorMaskComponent(int): + def __or__ (self, other: 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent') -> 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask': ... # type: ignore[override, misc] + R = ... # type: QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent G = ... # type: QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent B = ... # type: QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent @@ -1358,12 +1465,20 @@ class QSGMaterialRhiShader(QSGMaterialShader): def __init__(self, f: typing.Union['QSGMaterialRhiShader.GraphicsPipelineState.ColorMask', 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent']) -> None: ... @typing.overload def __init__(self, a0: 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGMaterialRhiShader.GraphicsPipelineState.ColorMask', 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent', int]) -> 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask': ... + def __and__(self, other: typing.Union['QSGMaterialRhiShader.GraphicsPipelineState.ColorMask', 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent', int]) -> 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask': ... + def __xor__(self, other: typing.Union['QSGMaterialRhiShader.GraphicsPipelineState.ColorMask', 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent', int]) -> 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask': ... + def __ror__ (self, other: 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent') -> 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask': ... + def __rand__(self, other: 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent') -> 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask': ... + def __rxor__(self, other: 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent') -> 'QSGMaterialRhiShader.GraphicsPipelineState.ColorMask': ... @typing.overload def __init__(self) -> None: ... @@ -1378,12 +1493,20 @@ class QSGMaterialRhiShader(QSGMaterialShader): def __init__(self, f: typing.Union['QSGMaterialRhiShader.Flags', 'QSGMaterialRhiShader.Flag']) -> None: ... @typing.overload def __init__(self, a0: 'QSGMaterialRhiShader.Flags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGMaterialRhiShader.Flags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGMaterialRhiShader.Flags', 'QSGMaterialRhiShader.Flag', int]) -> 'QSGMaterialRhiShader.Flags': ... + def __and__(self, other: typing.Union['QSGMaterialRhiShader.Flags', 'QSGMaterialRhiShader.Flag', int]) -> 'QSGMaterialRhiShader.Flags': ... + def __xor__(self, other: typing.Union['QSGMaterialRhiShader.Flags', 'QSGMaterialRhiShader.Flag', int]) -> 'QSGMaterialRhiShader.Flags': ... + def __ror__ (self, other: 'QSGMaterialRhiShader.Flag') -> 'QSGMaterialRhiShader.Flags': ... + def __rand__(self, other: 'QSGMaterialRhiShader.Flag') -> 'QSGMaterialRhiShader.Flags': ... + def __rxor__(self, other: 'QSGMaterialRhiShader.Flag') -> 'QSGMaterialRhiShader.Flags': ... def __init__(self) -> None: ... @@ -1434,6 +1557,9 @@ class QSGRectangleNode(QSGGeometryNode): class QSGRendererInterface(sip.simplewrapper): class ShaderSourceType(int): + def __or__ (self, other: 'QSGRendererInterface.ShaderSourceType') -> 'QSGRendererInterface.ShaderSourceTypes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGRendererInterface.ShaderSourceTypes': ... # type: ignore[override, misc] + ShaderSourceString = ... # type: QSGRendererInterface.ShaderSourceType ShaderSourceFile = ... # type: QSGRendererInterface.ShaderSourceType ShaderByteCode = ... # type: QSGRendererInterface.ShaderSourceType @@ -1443,6 +1569,9 @@ class QSGRendererInterface(sip.simplewrapper): ShaderByteCode = ... # type: QSGRendererInterface.ShaderSourceType class ShaderCompilationType(int): + def __or__ (self, other: 'QSGRendererInterface.ShaderCompilationType') -> 'QSGRendererInterface.ShaderCompilationTypes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGRendererInterface.ShaderCompilationTypes': ... # type: ignore[override, misc] + RuntimeCompilation = ... # type: QSGRendererInterface.ShaderCompilationType OfflineCompilation = ... # type: QSGRendererInterface.ShaderCompilationType @@ -1516,12 +1645,20 @@ class QSGRendererInterface(sip.simplewrapper): def __init__(self, f: typing.Union['QSGRendererInterface.ShaderCompilationTypes', 'QSGRendererInterface.ShaderCompilationType']) -> None: ... @typing.overload def __init__(self, a0: 'QSGRendererInterface.ShaderCompilationTypes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGRendererInterface.ShaderCompilationTypes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGRendererInterface.ShaderCompilationTypes', 'QSGRendererInterface.ShaderCompilationType', int]) -> 'QSGRendererInterface.ShaderCompilationTypes': ... + def __and__(self, other: typing.Union['QSGRendererInterface.ShaderCompilationTypes', 'QSGRendererInterface.ShaderCompilationType', int]) -> 'QSGRendererInterface.ShaderCompilationTypes': ... + def __xor__(self, other: typing.Union['QSGRendererInterface.ShaderCompilationTypes', 'QSGRendererInterface.ShaderCompilationType', int]) -> 'QSGRendererInterface.ShaderCompilationTypes': ... + def __ror__ (self, other: 'QSGRendererInterface.ShaderCompilationType') -> 'QSGRendererInterface.ShaderCompilationTypes': ... + def __rand__(self, other: 'QSGRendererInterface.ShaderCompilationType') -> 'QSGRendererInterface.ShaderCompilationTypes': ... + def __rxor__(self, other: 'QSGRendererInterface.ShaderCompilationType') -> 'QSGRendererInterface.ShaderCompilationTypes': ... class ShaderSourceTypes(sip.simplewrapper): @@ -1531,12 +1668,20 @@ class QSGRendererInterface(sip.simplewrapper): def __init__(self, f: typing.Union['QSGRendererInterface.ShaderSourceTypes', 'QSGRendererInterface.ShaderSourceType']) -> None: ... @typing.overload def __init__(self, a0: 'QSGRendererInterface.ShaderSourceTypes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGRendererInterface.ShaderSourceTypes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGRendererInterface.ShaderSourceTypes', 'QSGRendererInterface.ShaderSourceType', int]) -> 'QSGRendererInterface.ShaderSourceTypes': ... + def __and__(self, other: typing.Union['QSGRendererInterface.ShaderSourceTypes', 'QSGRendererInterface.ShaderSourceType', int]) -> 'QSGRendererInterface.ShaderSourceTypes': ... + def __xor__(self, other: typing.Union['QSGRendererInterface.ShaderSourceTypes', 'QSGRendererInterface.ShaderSourceType', int]) -> 'QSGRendererInterface.ShaderSourceTypes': ... + def __ror__ (self, other: 'QSGRendererInterface.ShaderSourceType') -> 'QSGRendererInterface.ShaderSourceTypes': ... + def __rand__(self, other: 'QSGRendererInterface.ShaderSourceType') -> 'QSGRendererInterface.ShaderSourceTypes': ... + def __rxor__(self, other: 'QSGRendererInterface.ShaderSourceType') -> 'QSGRendererInterface.ShaderSourceTypes': ... @staticmethod def isApiRhiBased(api: 'QSGRendererInterface.GraphicsApi') -> bool: ... @@ -1553,6 +1698,9 @@ class QSGRendererInterface(sip.simplewrapper): class QSGRenderNode(QSGNode): class RenderingFlag(int): + def __or__ (self, other: 'QSGRenderNode.RenderingFlag') -> 'QSGRenderNode.RenderingFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGRenderNode.RenderingFlags': ... # type: ignore[override, misc] + BoundedRectRendering = ... # type: QSGRenderNode.RenderingFlag DepthAwareRendering = ... # type: QSGRenderNode.RenderingFlag OpaqueRendering = ... # type: QSGRenderNode.RenderingFlag @@ -1562,6 +1710,9 @@ class QSGRenderNode(QSGNode): OpaqueRendering = ... # type: QSGRenderNode.RenderingFlag class StateFlag(int): + def __or__ (self, other: 'QSGRenderNode.StateFlag') -> 'QSGRenderNode.StateFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGRenderNode.StateFlags': ... # type: ignore[override, misc] + DepthState = ... # type: QSGRenderNode.StateFlag StencilState = ... # type: QSGRenderNode.StateFlag ScissorState = ... # type: QSGRenderNode.StateFlag @@ -1588,12 +1739,20 @@ class QSGRenderNode(QSGNode): def __init__(self, f: typing.Union['QSGRenderNode.StateFlags', 'QSGRenderNode.StateFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QSGRenderNode.StateFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGRenderNode.StateFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGRenderNode.StateFlags', 'QSGRenderNode.StateFlag', int]) -> 'QSGRenderNode.StateFlags': ... + def __and__(self, other: typing.Union['QSGRenderNode.StateFlags', 'QSGRenderNode.StateFlag', int]) -> 'QSGRenderNode.StateFlags': ... + def __xor__(self, other: typing.Union['QSGRenderNode.StateFlags', 'QSGRenderNode.StateFlag', int]) -> 'QSGRenderNode.StateFlags': ... + def __ror__ (self, other: 'QSGRenderNode.StateFlag') -> 'QSGRenderNode.StateFlags': ... + def __rand__(self, other: 'QSGRenderNode.StateFlag') -> 'QSGRenderNode.StateFlags': ... + def __rxor__(self, other: 'QSGRenderNode.StateFlag') -> 'QSGRenderNode.StateFlags': ... class RenderingFlags(sip.simplewrapper): @@ -1603,12 +1762,20 @@ class QSGRenderNode(QSGNode): def __init__(self, f: typing.Union['QSGRenderNode.RenderingFlags', 'QSGRenderNode.RenderingFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QSGRenderNode.RenderingFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGRenderNode.RenderingFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGRenderNode.RenderingFlags', 'QSGRenderNode.RenderingFlag', int]) -> 'QSGRenderNode.RenderingFlags': ... + def __and__(self, other: typing.Union['QSGRenderNode.RenderingFlags', 'QSGRenderNode.RenderingFlag', int]) -> 'QSGRenderNode.RenderingFlags': ... + def __xor__(self, other: typing.Union['QSGRenderNode.RenderingFlags', 'QSGRenderNode.RenderingFlag', int]) -> 'QSGRenderNode.RenderingFlags': ... + def __ror__ (self, other: 'QSGRenderNode.RenderingFlag') -> 'QSGRenderNode.RenderingFlags': ... + def __rand__(self, other: 'QSGRenderNode.RenderingFlag') -> 'QSGRenderNode.RenderingFlags': ... + def __rxor__(self, other: 'QSGRenderNode.RenderingFlag') -> 'QSGRenderNode.RenderingFlags': ... class RenderState(sip.simplewrapper): @@ -1651,6 +1818,9 @@ class QSGSimpleRectNode(QSGGeometryNode): class QSGSimpleTextureNode(QSGGeometryNode): class TextureCoordinatesTransformFlag(int): + def __or__ (self, other: 'QSGSimpleTextureNode.TextureCoordinatesTransformFlag') -> 'QSGSimpleTextureNode.TextureCoordinatesTransformMode': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSGSimpleTextureNode.TextureCoordinatesTransformMode': ... # type: ignore[override, misc] + NoTransform = ... # type: QSGSimpleTextureNode.TextureCoordinatesTransformFlag MirrorHorizontally = ... # type: QSGSimpleTextureNode.TextureCoordinatesTransformFlag MirrorVertically = ... # type: QSGSimpleTextureNode.TextureCoordinatesTransformFlag @@ -1667,12 +1837,20 @@ class QSGSimpleTextureNode(QSGGeometryNode): def __init__(self, f: typing.Union['QSGSimpleTextureNode.TextureCoordinatesTransformMode', 'QSGSimpleTextureNode.TextureCoordinatesTransformFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QSGSimpleTextureNode.TextureCoordinatesTransformMode') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSGSimpleTextureNode.TextureCoordinatesTransformMode': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSGSimpleTextureNode.TextureCoordinatesTransformMode', 'QSGSimpleTextureNode.TextureCoordinatesTransformFlag', int]) -> 'QSGSimpleTextureNode.TextureCoordinatesTransformMode': ... + def __and__(self, other: typing.Union['QSGSimpleTextureNode.TextureCoordinatesTransformMode', 'QSGSimpleTextureNode.TextureCoordinatesTransformFlag', int]) -> 'QSGSimpleTextureNode.TextureCoordinatesTransformMode': ... + def __xor__(self, other: typing.Union['QSGSimpleTextureNode.TextureCoordinatesTransformMode', 'QSGSimpleTextureNode.TextureCoordinatesTransformFlag', int]) -> 'QSGSimpleTextureNode.TextureCoordinatesTransformMode': ... + def __ror__ (self, other: 'QSGSimpleTextureNode.TextureCoordinatesTransformFlag') -> 'QSGSimpleTextureNode.TextureCoordinatesTransformMode': ... + def __rand__(self, other: 'QSGSimpleTextureNode.TextureCoordinatesTransformFlag') -> 'QSGSimpleTextureNode.TextureCoordinatesTransformMode': ... + def __rxor__(self, other: 'QSGSimpleTextureNode.TextureCoordinatesTransformFlag') -> 'QSGSimpleTextureNode.TextureCoordinatesTransformMode': ... def __init__(self) -> None: ... @@ -1805,7 +1983,7 @@ class QSGTextureProvider(QtCore.QObject): def __init__(self) -> None: ... - def textureChanged(self) -> None: ... + textureChanged: typing.ClassVar[QtCore.pyqtSignal] def texture(self) -> QSGTexture: ... diff --git a/PyQt5-stubs/QtQuickWidgets.pyi b/PyQt5-stubs/QtQuickWidgets.pyi index e3cc6b57..922d90de 100644 --- a/PyQt5-stubs/QtQuickWidgets.pyi +++ b/PyQt5-stubs/QtQuickWidgets.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtQuickWidgets module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -92,8 +92,8 @@ class QQuickWidget(QtWidgets.QWidget): def keyPressEvent(self, a0: QtGui.QKeyEvent) -> None: ... def timerEvent(self, a0: QtCore.QTimerEvent) -> None: ... def resizeEvent(self, a0: QtGui.QResizeEvent) -> None: ... - def sceneGraphError(self, error: QtQuick.QQuickWindow.SceneGraphError, message: str) -> None: ... - def statusChanged(self, a0: 'QQuickWidget.Status') -> None: ... + sceneGraphError: typing.ClassVar[QtCore.pyqtSignal] + statusChanged: typing.ClassVar[QtCore.pyqtSignal] def setSource(self, a0: QtCore.QUrl) -> None: ... def format(self) -> QtGui.QSurfaceFormat: ... def setFormat(self, format: QtGui.QSurfaceFormat) -> None: ... diff --git a/PyQt5-stubs/QtRemoteObjects.pyi b/PyQt5-stubs/QtRemoteObjects.pyi index 8ae155b2..18f65541 100644 --- a/PyQt5-stubs/QtRemoteObjects.pyi +++ b/PyQt5-stubs/QtRemoteObjects.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtRemoteObjects module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -34,7 +34,7 @@ PYQT_SLOT = typing.Union[typing.Callable[..., None], QtCore.pyqtBoundSignal] class QAbstractItemModelReplica(QtCore.QAbstractItemModel): - def initialized(self) -> None: ... + initialized: typing.ClassVar[QtCore.pyqtSignal] def setRootCacheSize(self, rootCacheSize: int) -> None: ... def rootCacheSize(self) -> int: ... def hasData(self, index: QtCore.QModelIndex, role: int) -> bool: ... @@ -68,9 +68,9 @@ class QRemoteObjectReplica(QtCore.QObject): Suspect = ... # type: QRemoteObjectReplica.State SignatureMismatch = ... # type: QRemoteObjectReplica.State - def notified(self) -> None: ... - def stateChanged(self, state: 'QRemoteObjectReplica.State', oldState: 'QRemoteObjectReplica.State') -> None: ... - def initialized(self) -> None: ... + notified: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + initialized: typing.ClassVar[QtCore.pyqtSignal] def setNode(self, node: 'QRemoteObjectNode') -> None: ... def node(self) -> 'QRemoteObjectNode': ... def state(self) -> 'QRemoteObjectReplica.State': ... @@ -125,10 +125,10 @@ class QRemoteObjectNode(QtCore.QObject): def __init__(self, registryAddress: QtCore.QUrl, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def timerEvent(self, a0: QtCore.QTimerEvent) -> None: ... - def heartbeatIntervalChanged(self, heartbeatInterval: int) -> None: ... - def error(self, errorCode: 'QRemoteObjectNode.ErrorCode') -> None: ... - def remoteObjectRemoved(self, a0: typing.Tuple[str, 'QRemoteObjectSourceLocationInfo']) -> None: ... - def remoteObjectAdded(self, a0: typing.Tuple[str, 'QRemoteObjectSourceLocationInfo']) -> None: ... + heartbeatIntervalChanged: typing.ClassVar[QtCore.pyqtSignal] + error: typing.ClassVar[QtCore.pyqtSignal] + remoteObjectRemoved: typing.ClassVar[QtCore.pyqtSignal] + remoteObjectAdded: typing.ClassVar[QtCore.pyqtSignal] def setHeartbeatInterval(self, interval: int) -> None: ... def heartbeatInterval(self) -> int: ... def lastError(self) -> 'QRemoteObjectNode.ErrorCode': ... @@ -175,7 +175,7 @@ class QRemoteObjectHost(QRemoteObjectHostBase): @typing.overload def __init__(self, address: QtCore.QUrl, parent: QtCore.QObject) -> None: ... - def hostUrlChanged(self) -> None: ... + hostUrlChanged: typing.ClassVar[QtCore.pyqtSignal] def setHostUrl(self, hostAddress: QtCore.QUrl, allowedSchemas: QRemoteObjectHostBase.AllowedSchemas = ...) -> bool: ... def hostUrl(self) -> QtCore.QUrl: ... @@ -189,8 +189,8 @@ class QRemoteObjectRegistryHost(QRemoteObjectHostBase): class QRemoteObjectRegistry(QRemoteObjectReplica): - def remoteObjectRemoved(self, entry: typing.Tuple[str, 'QRemoteObjectSourceLocationInfo']) -> None: ... - def remoteObjectAdded(self, entry: typing.Tuple[str, 'QRemoteObjectSourceLocationInfo']) -> None: ... + remoteObjectRemoved: typing.ClassVar[QtCore.pyqtSignal] + remoteObjectAdded: typing.ClassVar[QtCore.pyqtSignal] def sourceLocations(self) -> typing.Dict[str, 'QRemoteObjectSourceLocationInfo']: ... diff --git a/PyQt5-stubs/QtSensors.pyi b/PyQt5-stubs/QtSensors.pyi index 017cbd80..7953d24c 100644 --- a/PyQt5-stubs/QtSensors.pyi +++ b/PyQt5-stubs/QtSensors.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtSensors module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -102,20 +102,20 @@ class QSensor(QtCore.QObject): def __init__(self, type: typing.Union[QtCore.QByteArray, bytes, bytearray], parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def bufferSizeChanged(self, bufferSize: int) -> None: ... - def efficientBufferSizeChanged(self, efficientBufferSize: int) -> None: ... - def maxBufferSizeChanged(self, maxBufferSize: int) -> None: ... - def userOrientationChanged(self, userOrientation: int) -> None: ... - def currentOrientationChanged(self, currentOrientation: int) -> None: ... - def axesOrientationModeChanged(self, axesOrientationMode: 'QSensor.AxesOrientationMode') -> None: ... - def skipDuplicatesChanged(self, skipDuplicates: bool) -> None: ... - def dataRateChanged(self) -> None: ... - def alwaysOnChanged(self) -> None: ... - def availableSensorsChanged(self) -> None: ... - def sensorError(self, error: int) -> None: ... - def readingChanged(self) -> None: ... - def activeChanged(self) -> None: ... - def busyChanged(self) -> None: ... + bufferSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + efficientBufferSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + maxBufferSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + userOrientationChanged: typing.ClassVar[QtCore.pyqtSignal] + currentOrientationChanged: typing.ClassVar[QtCore.pyqtSignal] + axesOrientationModeChanged: typing.ClassVar[QtCore.pyqtSignal] + skipDuplicatesChanged: typing.ClassVar[QtCore.pyqtSignal] + dataRateChanged: typing.ClassVar[QtCore.pyqtSignal] + alwaysOnChanged: typing.ClassVar[QtCore.pyqtSignal] + availableSensorsChanged: typing.ClassVar[QtCore.pyqtSignal] + sensorError: typing.ClassVar[QtCore.pyqtSignal] + readingChanged: typing.ClassVar[QtCore.pyqtSignal] + activeChanged: typing.ClassVar[QtCore.pyqtSignal] + busyChanged: typing.ClassVar[QtCore.pyqtSignal] def stop(self) -> None: ... def start(self) -> bool: ... def setBufferSize(self, bufferSize: int) -> None: ... @@ -176,7 +176,7 @@ class QAccelerometer(QSensor): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def accelerationModeChanged(self, accelerationMode: 'QAccelerometer.AccelerationMode') -> None: ... + accelerationModeChanged: typing.ClassVar[QtCore.pyqtSignal] def reading(self) -> QAccelerometerReading: ... def setAccelerationMode(self, accelerationMode: 'QAccelerometer.AccelerationMode') -> None: ... def accelerationMode(self) -> 'QAccelerometer.AccelerationMode': ... @@ -414,8 +414,8 @@ class QIRProximitySensor(QSensor): class QLidReading(QSensorReading): - def frontLidChanged(self, closed: bool) -> None: ... - def backLidChanged(self, closed: bool) -> None: ... + frontLidChanged: typing.ClassVar[QtCore.pyqtSignal] + backLidChanged: typing.ClassVar[QtCore.pyqtSignal] def setFrontLidClosed(self, closed: bool) -> None: ... def frontLidClosed(self) -> bool: ... def setBackLidClosed(self, closed: bool) -> None: ... @@ -459,7 +459,7 @@ class QLightSensor(QSensor): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def fieldOfViewChanged(self, fieldOfView: float) -> None: ... + fieldOfViewChanged: typing.ClassVar[QtCore.pyqtSignal] def setFieldOfView(self, fieldOfView: float) -> None: ... def fieldOfView(self) -> float: ... def reading(self) -> QLightReading: ... @@ -491,7 +491,7 @@ class QMagnetometer(QSensor): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def returnGeoValuesChanged(self, returnGeoValues: bool) -> None: ... + returnGeoValuesChanged: typing.ClassVar[QtCore.pyqtSignal] def setReturnGeoValues(self, returnGeoValues: bool) -> None: ... def returnGeoValues(self) -> bool: ... def reading(self) -> QMagnetometerReading: ... @@ -648,7 +648,7 @@ class QTapSensor(QSensor): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def returnDoubleTapEventsChanged(self, returnDoubleTapEvents: bool) -> None: ... + returnDoubleTapEventsChanged: typing.ClassVar[QtCore.pyqtSignal] def setReturnDoubleTapEvents(self, returnDoubleTapEvents: bool) -> None: ... def returnDoubleTapEvents(self) -> bool: ... def reading(self) -> QTapReading: ... @@ -702,7 +702,7 @@ class QRotationSensor(QSensor): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def hasZChanged(self, hasZ: bool) -> None: ... + hasZChanged: typing.ClassVar[QtCore.pyqtSignal] def setHasZ(self, hasZ: bool) -> None: ... def hasZ(self) -> bool: ... def reading(self) -> QRotationReading: ... diff --git a/PyQt5-stubs/QtSerialPort.pyi b/PyQt5-stubs/QtSerialPort.pyi index 607e7f50..95fa4020 100644 --- a/PyQt5-stubs/QtSerialPort.pyi +++ b/PyQt5-stubs/QtSerialPort.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtSerialPort module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -79,6 +79,9 @@ class QSerialPort(QtCore.QIODevice): UnknownPolicy = ... # type: QSerialPort.DataErrorPolicy class PinoutSignal(int): + def __or__ (self, other: 'QSerialPort.PinoutSignal') -> 'QSerialPort.PinoutSignals': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSerialPort.PinoutSignals': ... # type: ignore[override, misc] + NoSignal = ... # type: QSerialPort.PinoutSignal TransmittedDataSignal = ... # type: QSerialPort.PinoutSignal ReceivedDataSignal = ... # type: QSerialPort.PinoutSignal @@ -175,6 +178,9 @@ class QSerialPort(QtCore.QIODevice): UnknownBaud = ... # type: QSerialPort.BaudRate class Direction(int): + def __or__ (self, other: 'QSerialPort.Direction') -> 'QSerialPort.Directions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSerialPort.Directions': ... # type: ignore[override, misc] + Input = ... # type: QSerialPort.Direction Output = ... # type: QSerialPort.Direction AllDirections = ... # type: QSerialPort.Direction @@ -191,12 +197,20 @@ class QSerialPort(QtCore.QIODevice): def __init__(self, f: typing.Union['QSerialPort.Directions', 'QSerialPort.Direction']) -> None: ... @typing.overload def __init__(self, a0: 'QSerialPort.Directions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSerialPort.Directions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSerialPort.Directions', 'QSerialPort.Direction', int]) -> 'QSerialPort.Directions': ... + def __and__(self, other: typing.Union['QSerialPort.Directions', 'QSerialPort.Direction', int]) -> 'QSerialPort.Directions': ... + def __xor__(self, other: typing.Union['QSerialPort.Directions', 'QSerialPort.Direction', int]) -> 'QSerialPort.Directions': ... + def __ror__ (self, other: 'QSerialPort.Direction') -> 'QSerialPort.Directions': ... + def __rand__(self, other: 'QSerialPort.Direction') -> 'QSerialPort.Directions': ... + def __rxor__(self, other: 'QSerialPort.Direction') -> 'QSerialPort.Directions': ... class PinoutSignals(sip.simplewrapper): @@ -206,12 +220,20 @@ class QSerialPort(QtCore.QIODevice): def __init__(self, f: typing.Union['QSerialPort.PinoutSignals', 'QSerialPort.PinoutSignal']) -> None: ... @typing.overload def __init__(self, a0: 'QSerialPort.PinoutSignals') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSerialPort.PinoutSignals': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSerialPort.PinoutSignals', 'QSerialPort.PinoutSignal', int]) -> 'QSerialPort.PinoutSignals': ... + def __and__(self, other: typing.Union['QSerialPort.PinoutSignals', 'QSerialPort.PinoutSignal', int]) -> 'QSerialPort.PinoutSignals': ... + def __xor__(self, other: typing.Union['QSerialPort.PinoutSignals', 'QSerialPort.PinoutSignal', int]) -> 'QSerialPort.PinoutSignals': ... + def __ror__ (self, other: 'QSerialPort.PinoutSignal') -> 'QSerialPort.PinoutSignals': ... + def __rand__(self, other: 'QSerialPort.PinoutSignal') -> 'QSerialPort.PinoutSignals': ... + def __rxor__(self, other: 'QSerialPort.PinoutSignal') -> 'QSerialPort.PinoutSignals': ... @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -220,22 +242,22 @@ class QSerialPort(QtCore.QIODevice): @typing.overload def __init__(self, info: 'QSerialPortInfo', parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def errorOccurred(self, error: 'QSerialPort.SerialPortError') -> None: ... - def breakEnabledChanged(self, set: bool) -> None: ... + errorOccurred: typing.ClassVar[QtCore.pyqtSignal] + breakEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] def isBreakEnabled(self) -> bool: ... def handle(self) -> int: ... def writeData(self, data: bytes) -> int: ... def readLineData(self, maxlen: int) -> bytes: ... def readData(self, maxlen: int) -> bytes: ... - def settingsRestoredOnCloseChanged(self, restore: bool) -> None: ... - def requestToSendChanged(self, set: bool) -> None: ... - def dataTerminalReadyChanged(self, set: bool) -> None: ... - def dataErrorPolicyChanged(self, policy: 'QSerialPort.DataErrorPolicy') -> None: ... - def flowControlChanged(self, flow: 'QSerialPort.FlowControl') -> None: ... - def stopBitsChanged(self, stopBits: 'QSerialPort.StopBits') -> None: ... - def parityChanged(self, parity: 'QSerialPort.Parity') -> None: ... - def dataBitsChanged(self, dataBits: 'QSerialPort.DataBits') -> None: ... - def baudRateChanged(self, baudRate: int, directions: typing.Union['QSerialPort.Directions', 'QSerialPort.Direction']) -> None: ... + settingsRestoredOnCloseChanged: typing.ClassVar[QtCore.pyqtSignal] + requestToSendChanged: typing.ClassVar[QtCore.pyqtSignal] + dataTerminalReadyChanged: typing.ClassVar[QtCore.pyqtSignal] + dataErrorPolicyChanged: typing.ClassVar[QtCore.pyqtSignal] + flowControlChanged: typing.ClassVar[QtCore.pyqtSignal] + stopBitsChanged: typing.ClassVar[QtCore.pyqtSignal] + parityChanged: typing.ClassVar[QtCore.pyqtSignal] + dataBitsChanged: typing.ClassVar[QtCore.pyqtSignal] + baudRateChanged: typing.ClassVar[QtCore.pyqtSignal] def setBreakEnabled(self, enabled: bool = ...) -> bool: ... def sendBreak(self, duration: int = ...) -> bool: ... def waitForBytesWritten(self, msecs: int = ...) -> bool: ... @@ -247,10 +269,7 @@ class QSerialPort(QtCore.QIODevice): def setReadBufferSize(self, size: int) -> None: ... def readBufferSize(self) -> int: ... def clearError(self) -> None: ... - @typing.overload - def error(self) -> 'QSerialPort.SerialPortError': ... - @typing.overload - def error(self, serialPortError: 'QSerialPort.SerialPortError') -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def dataErrorPolicy(self) -> 'QSerialPort.DataErrorPolicy': ... def setDataErrorPolicy(self, policy: 'QSerialPort.DataErrorPolicy' = ...) -> bool: ... def atEnd(self) -> bool: ... diff --git a/PyQt5-stubs/QtSql.pyi b/PyQt5-stubs/QtSql.pyi index 160fcf4e..007b4217 100644 --- a/PyQt5-stubs/QtSql.pyi +++ b/PyQt5-stubs/QtSql.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtSql module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -213,10 +213,7 @@ class QSqlDriver(QtCore.QObject): def setNumericalPrecisionPolicy(self, precisionPolicy: 'QSql.NumericalPrecisionPolicy') -> None: ... def stripDelimiters(self, identifier: str, type: 'QSqlDriver.IdentifierType') -> str: ... def isIdentifierEscaped(self, identifier: str, type: 'QSqlDriver.IdentifierType') -> bool: ... - @typing.overload - def notification(self, name: str) -> None: ... - @typing.overload - def notification(self, name: str, source: 'QSqlDriver.NotificationSource', payload: typing.Any) -> None: ... + notification: typing.ClassVar[QtCore.pyqtSignal] def subscribedToNotifications(self) -> typing.List[str]: ... def unsubscribeFromNotification(self, name: str) -> bool: ... def subscribeToNotification(self, name: str) -> bool: ... @@ -560,10 +557,10 @@ class QSqlTableModel(QSqlQueryModel): def deleteRowFromTable(self, row: int) -> bool: ... def insertRowIntoTable(self, values: QSqlRecord) -> bool: ... def updateRowInTable(self, row: int, values: QSqlRecord) -> bool: ... - def beforeDelete(self, row: int) -> None: ... - def beforeUpdate(self, row: int, record: QSqlRecord) -> None: ... - def beforeInsert(self, record: QSqlRecord) -> None: ... - def primeInsert(self, row: int, record: QSqlRecord) -> None: ... + beforeDelete: typing.ClassVar[QtCore.pyqtSignal] + beforeUpdate: typing.ClassVar[QtCore.pyqtSignal] + beforeInsert: typing.ClassVar[QtCore.pyqtSignal] + primeInsert: typing.ClassVar[QtCore.pyqtSignal] def revertAll(self) -> None: ... def submitAll(self) -> bool: ... def revert(self) -> None: ... @@ -715,6 +712,9 @@ class QSql(sip.simplewrapper): AllTables = ... # type: QSql.TableType class ParamTypeFlag(int): + def __or__ (self, other: 'QSql.ParamTypeFlag') -> 'QSql.ParamType': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSql.ParamType': ... # type: ignore[override, misc] + In = ... # type: QSql.ParamTypeFlag Out = ... # type: QSql.ParamTypeFlag InOut = ... # type: QSql.ParamTypeFlag @@ -740,9 +740,17 @@ class QSql(sip.simplewrapper): def __init__(self, f: typing.Union['QSql.ParamType', 'QSql.ParamTypeFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QSql.ParamType') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSql.ParamType': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSql.ParamType', 'QSql.ParamTypeFlag', int]) -> 'QSql.ParamType': ... + def __and__(self, other: typing.Union['QSql.ParamType', 'QSql.ParamTypeFlag', int]) -> 'QSql.ParamType': ... + def __xor__(self, other: typing.Union['QSql.ParamType', 'QSql.ParamTypeFlag', int]) -> 'QSql.ParamType': ... + def __ror__ (self, other: 'QSql.ParamTypeFlag') -> 'QSql.ParamType': ... + def __rand__(self, other: 'QSql.ParamTypeFlag') -> 'QSql.ParamType': ... + def __rxor__(self, other: 'QSql.ParamTypeFlag') -> 'QSql.ParamType': ... diff --git a/PyQt5-stubs/QtSvg.pyi b/PyQt5-stubs/QtSvg.pyi index 97d2b50b..e9973abc 100644 --- a/PyQt5-stubs/QtSvg.pyi +++ b/PyQt5-stubs/QtSvg.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtSvg module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -98,7 +98,7 @@ class QSvgRenderer(QtCore.QObject): def transformForElement(self, id: str) -> QtGui.QTransform: ... def setAspectRatioMode(self, mode: QtCore.Qt.AspectRatioMode) -> None: ... def aspectRatioMode(self) -> QtCore.Qt.AspectRatioMode: ... - def repaintNeeded(self) -> None: ... + repaintNeeded: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def render(self, p: QtGui.QPainter) -> None: ... @typing.overload diff --git a/PyQt5-stubs/QtTest.pyi b/PyQt5-stubs/QtTest.pyi index 8d9a7e6b..a6d4f9df 100644 --- a/PyQt5-stubs/QtTest.pyi +++ b/PyQt5-stubs/QtTest.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtTest module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # diff --git a/PyQt5-stubs/QtWebChannel.pyi b/PyQt5-stubs/QtWebChannel.pyi index 4ff9b336..841cbdd2 100644 --- a/PyQt5-stubs/QtWebChannel.pyi +++ b/PyQt5-stubs/QtWebChannel.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtWebChannel module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -38,7 +38,7 @@ class QWebChannel(QtCore.QObject): def disconnectFrom(self, transport: 'QWebChannelAbstractTransport') -> None: ... def connectTo(self, transport: 'QWebChannelAbstractTransport') -> None: ... - def blockUpdatesChanged(self, block: bool) -> None: ... + blockUpdatesChanged: typing.ClassVar[QtCore.pyqtSignal] def setBlockUpdates(self, block: bool) -> None: ... def blockUpdates(self) -> bool: ... def deregisterObject(self, object: QtCore.QObject) -> None: ... @@ -51,5 +51,5 @@ class QWebChannelAbstractTransport(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def messageReceived(self, message: typing.Dict[str, typing.Union[QtCore.QJsonValue, QtCore.QJsonValue.Type, typing.Iterable[QtCore.QJsonValue], bool, int, float, None, str]], transport: 'QWebChannelAbstractTransport') -> None: ... + messageReceived: typing.ClassVar[QtCore.pyqtSignal] def sendMessage(self, message: typing.Dict[str, typing.Union[QtCore.QJsonValue, QtCore.QJsonValue.Type, typing.Iterable[QtCore.QJsonValue], bool, int, float, None, str]]) -> None: ... diff --git a/PyQt5-stubs/QtWebEngine.pyi b/PyQt5-stubs/QtWebEngine.pyi index 7b3c7fe0..fb0fe0cf 100644 --- a/PyQt5-stubs/QtWebEngine.pyi +++ b/PyQt5-stubs/QtWebEngine.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtWebEngine module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -61,29 +61,29 @@ class QQuickWebEngineProfile(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def presentNotification(self, notification: QtWebEngineCore.QWebEngineNotification) -> None: ... - def downloadPathChanged(self) -> None: ... - def useForGlobalCertificateVerificationChanged(self) -> None: ... + presentNotification: typing.ClassVar[QtCore.pyqtSignal] + downloadPathChanged: typing.ClassVar[QtCore.pyqtSignal] + useForGlobalCertificateVerificationChanged: typing.ClassVar[QtCore.pyqtSignal] def clientCertificateStore(self) -> QtWebEngineCore.QWebEngineClientCertificateStore: ... def setDownloadPath(self, path: str) -> None: ... def downloadPath(self) -> str: ... def isUsedForGlobalCertificateVerification(self) -> bool: ... def setUseForGlobalCertificateVerification(self, b: bool) -> None: ... - def spellCheckEnabledChanged(self) -> None: ... - def spellCheckLanguagesChanged(self) -> None: ... + spellCheckEnabledChanged: typing.ClassVar[QtCore.pyqtSignal] + spellCheckLanguagesChanged: typing.ClassVar[QtCore.pyqtSignal] def isSpellCheckEnabled(self) -> bool: ... def setSpellCheckEnabled(self, enabled: bool) -> None: ... def spellCheckLanguages(self) -> typing.List[str]: ... def setSpellCheckLanguages(self, languages: typing.Iterable[str]) -> None: ... - def httpAcceptLanguageChanged(self) -> None: ... - def httpCacheMaximumSizeChanged(self) -> None: ... - def persistentCookiesPolicyChanged(self) -> None: ... - def httpCacheTypeChanged(self) -> None: ... - def httpUserAgentChanged(self) -> None: ... - def cachePathChanged(self) -> None: ... - def persistentStoragePathChanged(self) -> None: ... - def offTheRecordChanged(self) -> None: ... - def storageNameChanged(self) -> None: ... + httpAcceptLanguageChanged: typing.ClassVar[QtCore.pyqtSignal] + httpCacheMaximumSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + persistentCookiesPolicyChanged: typing.ClassVar[QtCore.pyqtSignal] + httpCacheTypeChanged: typing.ClassVar[QtCore.pyqtSignal] + httpUserAgentChanged: typing.ClassVar[QtCore.pyqtSignal] + cachePathChanged: typing.ClassVar[QtCore.pyqtSignal] + persistentStoragePathChanged: typing.ClassVar[QtCore.pyqtSignal] + offTheRecordChanged: typing.ClassVar[QtCore.pyqtSignal] + storageNameChanged: typing.ClassVar[QtCore.pyqtSignal] @staticmethod def defaultProfile() -> 'QQuickWebEngineProfile': ... def clearHttpCache(self) -> None: ... @@ -138,12 +138,12 @@ class QQuickWebEngineScript(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def timerEvent(self, e: QtCore.QTimerEvent) -> None: ... - def runOnSubframesChanged(self, on: bool) -> None: ... - def worldIdChanged(self, scriptWorldId: 'QQuickWebEngineScript.ScriptWorldId') -> None: ... - def injectionPointChanged(self, injectionPoint: 'QQuickWebEngineScript.InjectionPoint') -> None: ... - def sourceCodeChanged(self, code: str) -> None: ... - def sourceUrlChanged(self, url: QtCore.QUrl) -> None: ... - def nameChanged(self, name: str) -> None: ... + runOnSubframesChanged: typing.ClassVar[QtCore.pyqtSignal] + worldIdChanged: typing.ClassVar[QtCore.pyqtSignal] + injectionPointChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceCodeChanged: typing.ClassVar[QtCore.pyqtSignal] + sourceUrlChanged: typing.ClassVar[QtCore.pyqtSignal] + nameChanged: typing.ClassVar[QtCore.pyqtSignal] def setRunOnSubframes(self, on: bool) -> None: ... def setWorldId(self, scriptWorldId: 'QQuickWebEngineScript.ScriptWorldId') -> None: ... def setInjectionPoint(self, injectionPoint: 'QQuickWebEngineScript.InjectionPoint') -> None: ... diff --git a/PyQt5-stubs/QtWebEngineCore.pyi b/PyQt5-stubs/QtWebEngineCore.pyi index 4fd28480..d1ba5194 100644 --- a/PyQt5-stubs/QtWebEngineCore.pyi +++ b/PyQt5-stubs/QtWebEngineCore.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtWebEngineCore module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -40,9 +40,6 @@ PYQT_OPENGL_BOUND_ARRAY = typing.Union[typing.Sequence[int], typing.Sequence[float], sip.Buffer, int, None] -class QtWebEngineCore(sip.simplewrapper): ... - - class QWebEngineClientCertificateStore(sip.simplewrapper): def clear(self) -> None: ... @@ -65,8 +62,8 @@ class QWebEngineCookieStore(QtCore.QObject): def __init__(self, a0: 'QWebEngineCookieStore.FilterRequest') -> None: ... def setCookieFilter(self, filterCallback: typing.Optional[typing.Callable[[FilterRequest], bool]] = ...) -> None: ... - def cookieRemoved(self, cookie: QtNetwork.QNetworkCookie) -> None: ... - def cookieAdded(self, cookie: QtNetwork.QNetworkCookie) -> None: ... + cookieRemoved: typing.ClassVar[QtCore.pyqtSignal] + cookieAdded: typing.ClassVar[QtCore.pyqtSignal] def loadAllCookies(self) -> None: ... def deleteAllCookies(self) -> None: ... def deleteSessionCookies(self) -> None: ... @@ -117,7 +114,7 @@ class QWebEngineHttpRequest(sip.simplewrapper): class QWebEngineNotification(QtCore.QObject): - def closed(self) -> None: ... + closed: typing.ClassVar[QtCore.pyqtSignal] def close(self) -> None: ... def click(self) -> None: ... def show(self) -> None: ... @@ -268,6 +265,9 @@ class QWebEngineUrlRequestJob(QtCore.QObject): class QWebEngineUrlScheme(sip.simplewrapper): class Flag(int): + def __or__ (self, other: 'QWebEngineUrlScheme.Flag') -> 'QWebEngineUrlScheme.Flags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QWebEngineUrlScheme.Flags': ... # type: ignore[override, misc] + SecureScheme = ... # type: QWebEngineUrlScheme.Flag LocalScheme = ... # type: QWebEngineUrlScheme.Flag LocalAccessAllowed = ... # type: QWebEngineUrlScheme.Flag @@ -310,12 +310,20 @@ class QWebEngineUrlScheme(sip.simplewrapper): def __init__(self, f: typing.Union['QWebEngineUrlScheme.Flags', 'QWebEngineUrlScheme.Flag']) -> None: ... @typing.overload def __init__(self, a0: 'QWebEngineUrlScheme.Flags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QWebEngineUrlScheme.Flags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QWebEngineUrlScheme.Flags', 'QWebEngineUrlScheme.Flag', int]) -> 'QWebEngineUrlScheme.Flags': ... + def __and__(self, other: typing.Union['QWebEngineUrlScheme.Flags', 'QWebEngineUrlScheme.Flag', int]) -> 'QWebEngineUrlScheme.Flags': ... + def __xor__(self, other: typing.Union['QWebEngineUrlScheme.Flags', 'QWebEngineUrlScheme.Flag', int]) -> 'QWebEngineUrlScheme.Flags': ... + def __ror__ (self, other: 'QWebEngineUrlScheme.Flag') -> 'QWebEngineUrlScheme.Flags': ... + def __rand__(self, other: 'QWebEngineUrlScheme.Flag') -> 'QWebEngineUrlScheme.Flags': ... + def __rxor__(self, other: 'QWebEngineUrlScheme.Flag') -> 'QWebEngineUrlScheme.Flags': ... @typing.overload def __init__(self) -> None: ... diff --git a/PyQt5-stubs/QtWebEngineWidgets.pyi b/PyQt5-stubs/QtWebEngineWidgets.pyi index fe699fc7..42e415cc 100644 --- a/PyQt5-stubs/QtWebEngineWidgets.pyi +++ b/PyQt5-stubs/QtWebEngineWidgets.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtWebEngineWidgets module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -108,6 +108,9 @@ class QWebEngineClientCertificateSelection(sip.simplewrapper): class QWebEngineContextMenuData(sip.simplewrapper): class EditFlag(int): + def __or__ (self, other: 'QWebEngineContextMenuData.EditFlag') -> 'QWebEngineContextMenuData.EditFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QWebEngineContextMenuData.EditFlags': ... # type: ignore[override, misc] + CanUndo = ... # type: QWebEngineContextMenuData.EditFlag CanRedo = ... # type: QWebEngineContextMenuData.EditFlag CanCut = ... # type: QWebEngineContextMenuData.EditFlag @@ -129,6 +132,9 @@ class QWebEngineContextMenuData(sip.simplewrapper): CanEditRichly = ... # type: QWebEngineContextMenuData.EditFlag class MediaFlag(int): + def __or__ (self, other: 'QWebEngineContextMenuData.MediaFlag') -> 'QWebEngineContextMenuData.MediaFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QWebEngineContextMenuData.MediaFlags': ... # type: ignore[override, misc] + MediaInError = ... # type: QWebEngineContextMenuData.MediaFlag MediaPaused = ... # type: QWebEngineContextMenuData.MediaFlag MediaMuted = ... # type: QWebEngineContextMenuData.MediaFlag @@ -176,12 +182,20 @@ class QWebEngineContextMenuData(sip.simplewrapper): def __init__(self, f: typing.Union['QWebEngineContextMenuData.MediaFlags', 'QWebEngineContextMenuData.MediaFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QWebEngineContextMenuData.MediaFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QWebEngineContextMenuData.MediaFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QWebEngineContextMenuData.MediaFlags', 'QWebEngineContextMenuData.MediaFlag', int]) -> 'QWebEngineContextMenuData.MediaFlags': ... + def __and__(self, other: typing.Union['QWebEngineContextMenuData.MediaFlags', 'QWebEngineContextMenuData.MediaFlag', int]) -> 'QWebEngineContextMenuData.MediaFlags': ... + def __xor__(self, other: typing.Union['QWebEngineContextMenuData.MediaFlags', 'QWebEngineContextMenuData.MediaFlag', int]) -> 'QWebEngineContextMenuData.MediaFlags': ... + def __ror__ (self, other: 'QWebEngineContextMenuData.MediaFlag') -> 'QWebEngineContextMenuData.MediaFlags': ... + def __rand__(self, other: 'QWebEngineContextMenuData.MediaFlag') -> 'QWebEngineContextMenuData.MediaFlags': ... + def __rxor__(self, other: 'QWebEngineContextMenuData.MediaFlag') -> 'QWebEngineContextMenuData.MediaFlags': ... class EditFlags(sip.simplewrapper): @@ -191,12 +205,20 @@ class QWebEngineContextMenuData(sip.simplewrapper): def __init__(self, f: typing.Union['QWebEngineContextMenuData.EditFlags', 'QWebEngineContextMenuData.EditFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QWebEngineContextMenuData.EditFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QWebEngineContextMenuData.EditFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QWebEngineContextMenuData.EditFlags', 'QWebEngineContextMenuData.EditFlag', int]) -> 'QWebEngineContextMenuData.EditFlags': ... + def __and__(self, other: typing.Union['QWebEngineContextMenuData.EditFlags', 'QWebEngineContextMenuData.EditFlag', int]) -> 'QWebEngineContextMenuData.EditFlags': ... + def __xor__(self, other: typing.Union['QWebEngineContextMenuData.EditFlags', 'QWebEngineContextMenuData.EditFlag', int]) -> 'QWebEngineContextMenuData.EditFlags': ... + def __ror__ (self, other: 'QWebEngineContextMenuData.EditFlag') -> 'QWebEngineContextMenuData.EditFlags': ... + def __rand__(self, other: 'QWebEngineContextMenuData.EditFlag') -> 'QWebEngineContextMenuData.EditFlags': ... + def __rxor__(self, other: 'QWebEngineContextMenuData.EditFlag') -> 'QWebEngineContextMenuData.EditFlags': ... @typing.overload def __init__(self) -> None: ... @@ -312,7 +334,7 @@ class QWebEngineDownloadItem(QtCore.QObject): def suggestedFileName(self) -> str: ... def page(self) -> 'QWebEnginePage': ... def isSavePageDownload(self) -> bool: ... - def isPausedChanged(self, isPaused: bool) -> None: ... + isPausedChanged: typing.ClassVar[QtCore.pyqtSignal] def resume(self) -> None: ... def pause(self) -> None: ... def isPaused(self) -> bool: ... @@ -322,9 +344,9 @@ class QWebEngineDownloadItem(QtCore.QObject): def setSavePageFormat(self, format: 'QWebEngineDownloadItem.SavePageFormat') -> None: ... def savePageFormat(self) -> 'QWebEngineDownloadItem.SavePageFormat': ... def mimeType(self) -> str: ... - def downloadProgress(self, bytesReceived: int, bytesTotal: int) -> None: ... - def stateChanged(self, state: 'QWebEngineDownloadItem.DownloadState') -> None: ... - def finished(self) -> None: ... + downloadProgress: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + finished: typing.ClassVar[QtCore.pyqtSignal] def cancel(self) -> None: ... def accept(self) -> None: ... def isFinished(self) -> bool: ... @@ -473,6 +495,9 @@ class QWebEnginePage(QtCore.QObject): WebBrowserBackgroundTab = ... # type: QWebEnginePage.WebWindowType class FindFlag(int): + def __or__ (self, other: 'QWebEnginePage.FindFlag') -> 'QWebEnginePage.FindFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QWebEnginePage.FindFlags': ... # type: ignore[override, misc] + FindBackward = ... # type: QWebEnginePage.FindFlag FindCaseSensitively = ... # type: QWebEnginePage.FindFlag @@ -582,34 +607,42 @@ class QWebEnginePage(QtCore.QObject): def __init__(self, f: typing.Union['QWebEnginePage.FindFlags', 'QWebEnginePage.FindFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QWebEnginePage.FindFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QWebEnginePage.FindFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QWebEnginePage.FindFlags', 'QWebEnginePage.FindFlag', int]) -> 'QWebEnginePage.FindFlags': ... + def __and__(self, other: typing.Union['QWebEnginePage.FindFlags', 'QWebEnginePage.FindFlag', int]) -> 'QWebEnginePage.FindFlags': ... + def __xor__(self, other: typing.Union['QWebEnginePage.FindFlags', 'QWebEnginePage.FindFlag', int]) -> 'QWebEnginePage.FindFlags': ... + def __ror__ (self, other: 'QWebEnginePage.FindFlag') -> 'QWebEnginePage.FindFlags': ... + def __rand__(self, other: 'QWebEnginePage.FindFlag') -> 'QWebEnginePage.FindFlags': ... + def __rxor__(self, other: 'QWebEnginePage.FindFlag') -> 'QWebEnginePage.FindFlags': ... @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @typing.overload def __init__(self, profile: 'QWebEngineProfile', parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def renderProcessPidChanged(self, pid: int) -> None: ... + renderProcessPidChanged: typing.ClassVar[QtCore.pyqtSignal] def renderProcessPid(self) -> int: ... - def findTextFinished(self, result: QtWebEngineCore.QWebEngineFindTextResult) -> None: ... - def recommendedStateChanged(self, state: 'QWebEnginePage.LifecycleState') -> None: ... - def lifecycleStateChanged(self, state: 'QWebEnginePage.LifecycleState') -> None: ... - def visibleChanged(self, visible: bool) -> None: ... + findTextFinished: typing.ClassVar[QtCore.pyqtSignal] + recommendedStateChanged: typing.ClassVar[QtCore.pyqtSignal] + lifecycleStateChanged: typing.ClassVar[QtCore.pyqtSignal] + visibleChanged: typing.ClassVar[QtCore.pyqtSignal] def setVisible(self, visible: bool) -> None: ... def isVisible(self) -> bool: ... def recommendedState(self) -> 'QWebEnginePage.LifecycleState': ... def setLifecycleState(self, state: 'QWebEnginePage.LifecycleState') -> None: ... def lifecycleState(self) -> 'QWebEnginePage.LifecycleState': ... def setUrlRequestInterceptor(self, interceptor: QtWebEngineCore.QWebEngineUrlRequestInterceptor) -> None: ... - def printRequested(self) -> None: ... - def selectClientCertificate(self, clientCertSelection: QWebEngineClientCertificateSelection) -> None: ... - def registerProtocolHandlerRequested(self, request: QtWebEngineCore.QWebEngineRegisterProtocolHandlerRequest) -> None: ... - def quotaRequested(self, quotaRequest: QtWebEngineCore.QWebEngineQuotaRequest) -> None: ... + printRequested: typing.ClassVar[QtCore.pyqtSignal] + selectClientCertificate: typing.ClassVar[QtCore.pyqtSignal] + registerProtocolHandlerRequested: typing.ClassVar[QtCore.pyqtSignal] + quotaRequested: typing.ClassVar[QtCore.pyqtSignal] def devToolsPage(self) -> 'QWebEnginePage': ... def setDevToolsPage(self, page: 'QWebEnginePage') -> None: ... def inspectedPage(self) -> 'QWebEnginePage': ... @@ -618,12 +651,12 @@ class QWebEnginePage(QtCore.QObject): def print(self, printer: QtPrintSupport.QPrinter, resultCallback: typing.Callable[[bool], None]) -> None: ... def save(self, filePath: str, format: QWebEngineDownloadItem.SavePageFormat = ...) -> None: ... def replaceMisspelledWord(self, replacement: str) -> None: ... - def pdfPrintingFinished(self, filePath: str, success: bool) -> None: ... - def recentlyAudibleChanged(self, recentlyAudible: bool) -> None: ... - def audioMutedChanged(self, muted: bool) -> None: ... - def contentsSizeChanged(self, size: QtCore.QSizeF) -> None: ... - def scrollPositionChanged(self, position: typing.Union[QtCore.QPointF, QtCore.QPoint]) -> None: ... - def iconChanged(self, icon: QtGui.QIcon) -> None: ... + pdfPrintingFinished: typing.ClassVar[QtCore.pyqtSignal] + recentlyAudibleChanged: typing.ClassVar[QtCore.pyqtSignal] + audioMutedChanged: typing.ClassVar[QtCore.pyqtSignal] + contentsSizeChanged: typing.ClassVar[QtCore.pyqtSignal] + scrollPositionChanged: typing.ClassVar[QtCore.pyqtSignal] + iconChanged: typing.ClassVar[QtCore.pyqtSignal] def contextMenuData(self) -> QWebEngineContextMenuData: ... @typing.overload def printToPdf(self, filePath: str, pageLayout: QtGui.QPageLayout = ...) -> None: ... @@ -635,8 +668,8 @@ class QWebEnginePage(QtCore.QObject): def contentsSize(self) -> QtCore.QSizeF: ... def scrollPosition(self) -> QtCore.QPointF: ... def icon(self) -> QtGui.QIcon: ... - def renderProcessTerminated(self, terminationStatus: 'QWebEnginePage.RenderProcessTerminationStatus', exitCode: int) -> None: ... - def fullScreenRequested(self, fullScreenRequest: QWebEngineFullScreenRequest) -> None: ... + renderProcessTerminated: typing.ClassVar[QtCore.pyqtSignal] + fullScreenRequested: typing.ClassVar[QtCore.pyqtSignal] def setBackgroundColor(self, color: typing.Union[QtGui.QColor, QtCore.Qt.GlobalColor]) -> None: ... def backgroundColor(self) -> QtGui.QColor: ... def acceptNavigationRequest(self, url: QtCore.QUrl, type: 'QWebEnginePage.NavigationType', isMainFrame: bool) -> bool: ... @@ -654,20 +687,20 @@ class QWebEnginePage(QtCore.QObject): def javaScriptAlert(self, securityOrigin: QtCore.QUrl, msg: str) -> None: ... def chooseFiles(self, mode: 'QWebEnginePage.FileSelectionMode', oldFiles: typing.Iterable[str], acceptedMimeTypes: typing.Iterable[str]) -> typing.List[str]: ... def createWindow(self, type: 'QWebEnginePage.WebWindowType') -> 'QWebEnginePage': ... - def iconUrlChanged(self, url: QtCore.QUrl) -> None: ... - def urlChanged(self, url: QtCore.QUrl) -> None: ... - def titleChanged(self, title: str) -> None: ... - def proxyAuthenticationRequired(self, requestUrl: QtCore.QUrl, authenticator: QtNetwork.QAuthenticator, proxyHost: str) -> None: ... - def authenticationRequired(self, requestUrl: QtCore.QUrl, authenticator: QtNetwork.QAuthenticator) -> None: ... - def featurePermissionRequestCanceled(self, securityOrigin: QtCore.QUrl, feature: 'QWebEnginePage.Feature') -> None: ... - def featurePermissionRequested(self, securityOrigin: QtCore.QUrl, feature: 'QWebEnginePage.Feature') -> None: ... - def windowCloseRequested(self) -> None: ... - def geometryChangeRequested(self, geom: QtCore.QRect) -> None: ... - def selectionChanged(self) -> None: ... - def linkHovered(self, url: str) -> None: ... - def loadFinished(self, ok: bool) -> None: ... - def loadProgress(self, progress: int) -> None: ... - def loadStarted(self) -> None: ... + iconUrlChanged: typing.ClassVar[QtCore.pyqtSignal] + urlChanged: typing.ClassVar[QtCore.pyqtSignal] + titleChanged: typing.ClassVar[QtCore.pyqtSignal] + proxyAuthenticationRequired: typing.ClassVar[QtCore.pyqtSignal] + authenticationRequired: typing.ClassVar[QtCore.pyqtSignal] + featurePermissionRequestCanceled: typing.ClassVar[QtCore.pyqtSignal] + featurePermissionRequested: typing.ClassVar[QtCore.pyqtSignal] + windowCloseRequested: typing.ClassVar[QtCore.pyqtSignal] + geometryChangeRequested: typing.ClassVar[QtCore.pyqtSignal] + selectionChanged: typing.ClassVar[QtCore.pyqtSignal] + linkHovered: typing.ClassVar[QtCore.pyqtSignal] + loadFinished: typing.ClassVar[QtCore.pyqtSignal] + loadProgress: typing.ClassVar[QtCore.pyqtSignal] + loadStarted: typing.ClassVar[QtCore.pyqtSignal] def settings(self) -> 'QWebEngineSettings': ... @typing.overload def runJavaScript(self, scriptSource: str, worldId: int) -> None: ... @@ -751,7 +784,7 @@ class QWebEngineProfile(QtCore.QObject): def cookieStore(self) -> QtWebEngineCore.QWebEngineCookieStore: ... def httpAcceptLanguage(self) -> str: ... def setHttpAcceptLanguage(self, httpAcceptLanguage: str) -> None: ... - def downloadRequested(self, download: QWebEngineDownloadItem) -> None: ... + downloadRequested: typing.ClassVar[QtCore.pyqtSignal] @staticmethod def defaultProfile() -> 'QWebEngineProfile': ... def scripts(self) -> 'QWebEngineScriptCollection': ... @@ -964,21 +997,21 @@ class QWebEngineView(QtWidgets.QWidget): def dragMoveEvent(self, e: QtGui.QDragMoveEvent) -> None: ... def dragLeaveEvent(self, e: QtGui.QDragLeaveEvent) -> None: ... def dragEnterEvent(self, e: QtGui.QDragEnterEvent) -> None: ... - def iconChanged(self, a0: QtGui.QIcon) -> None: ... + iconChanged: typing.ClassVar[QtCore.pyqtSignal] def icon(self) -> QtGui.QIcon: ... def hideEvent(self, a0: QtGui.QHideEvent) -> None: ... def showEvent(self, a0: QtGui.QShowEvent) -> None: ... def event(self, a0: QtCore.QEvent) -> bool: ... def contextMenuEvent(self, a0: QtGui.QContextMenuEvent) -> None: ... def createWindow(self, type: QWebEnginePage.WebWindowType) -> 'QWebEngineView': ... - def renderProcessTerminated(self, terminationStatus: QWebEnginePage.RenderProcessTerminationStatus, exitCode: int) -> None: ... - def iconUrlChanged(self, a0: QtCore.QUrl) -> None: ... - def urlChanged(self, a0: QtCore.QUrl) -> None: ... - def selectionChanged(self) -> None: ... - def titleChanged(self, title: str) -> None: ... - def loadFinished(self, a0: bool) -> None: ... - def loadProgress(self, progress: int) -> None: ... - def loadStarted(self) -> None: ... + renderProcessTerminated: typing.ClassVar[QtCore.pyqtSignal] + iconUrlChanged: typing.ClassVar[QtCore.pyqtSignal] + urlChanged: typing.ClassVar[QtCore.pyqtSignal] + selectionChanged: typing.ClassVar[QtCore.pyqtSignal] + titleChanged: typing.ClassVar[QtCore.pyqtSignal] + loadFinished: typing.ClassVar[QtCore.pyqtSignal] + loadProgress: typing.ClassVar[QtCore.pyqtSignal] + loadStarted: typing.ClassVar[QtCore.pyqtSignal] def reload(self) -> None: ... def forward(self) -> None: ... def back(self) -> None: ... diff --git a/PyQt5-stubs/QtWebKit.pyi b/PyQt5-stubs/QtWebKit.pyi index b16abad2..a477bb2d 100644 --- a/PyQt5-stubs/QtWebKit.pyi +++ b/PyQt5-stubs/QtWebKit.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtWebKit module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # diff --git a/PyQt5-stubs/QtWebKitWidgets.pyi b/PyQt5-stubs/QtWebKitWidgets.pyi index c74714cd..042b8881 100644 --- a/PyQt5-stubs/QtWebKitWidgets.pyi +++ b/PyQt5-stubs/QtWebKitWidgets.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtWebKitWidgets module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # diff --git a/PyQt5-stubs/QtWebSockets.pyi b/PyQt5-stubs/QtWebSockets.pyi index bdb0d168..7c203ff5 100644 --- a/PyQt5-stubs/QtWebSockets.pyi +++ b/PyQt5-stubs/QtWebSockets.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtWebSockets module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -58,20 +58,20 @@ class QWebSocket(QtCore.QObject): def maxAllowedIncomingFrameSize(self) -> int: ... def setMaxAllowedIncomingFrameSize(self, maxAllowedIncomingFrameSize: int) -> None: ... def bytesToWrite(self) -> int: ... - def preSharedKeyAuthenticationRequired(self, authenticator: QtNetwork.QSslPreSharedKeyAuthenticator) -> None: ... - def sslErrors(self, errors: typing.Iterable[QtNetwork.QSslError]) -> None: ... - def bytesWritten(self, bytes: int) -> None: ... - def pong(self, elapsedTime: int, payload: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def binaryMessageReceived(self, message: typing.Union[QtCore.QByteArray, bytes, bytearray]) -> None: ... - def textMessageReceived(self, message: str) -> None: ... - def binaryFrameReceived(self, frame: typing.Union[QtCore.QByteArray, bytes, bytearray], isLastFrame: bool) -> None: ... - def textFrameReceived(self, frame: str, isLastFrame: bool) -> None: ... - def readChannelFinished(self) -> None: ... - def proxyAuthenticationRequired(self, proxy: QtNetwork.QNetworkProxy, pAuthenticator: QtNetwork.QAuthenticator) -> None: ... - def stateChanged(self, state: QtNetwork.QAbstractSocket.SocketState) -> None: ... - def disconnected(self) -> None: ... - def connected(self) -> None: ... - def aboutToClose(self) -> None: ... + preSharedKeyAuthenticationRequired: typing.ClassVar[QtCore.pyqtSignal] + sslErrors: typing.ClassVar[QtCore.pyqtSignal] + bytesWritten: typing.ClassVar[QtCore.pyqtSignal] + pong: typing.ClassVar[QtCore.pyqtSignal] + binaryMessageReceived: typing.ClassVar[QtCore.pyqtSignal] + textMessageReceived: typing.ClassVar[QtCore.pyqtSignal] + binaryFrameReceived: typing.ClassVar[QtCore.pyqtSignal] + textFrameReceived: typing.ClassVar[QtCore.pyqtSignal] + readChannelFinished: typing.ClassVar[QtCore.pyqtSignal] + proxyAuthenticationRequired: typing.ClassVar[QtCore.pyqtSignal] + stateChanged: typing.ClassVar[QtCore.pyqtSignal] + disconnected: typing.ClassVar[QtCore.pyqtSignal] + connected: typing.ClassVar[QtCore.pyqtSignal] + aboutToClose: typing.ClassVar[QtCore.pyqtSignal] def ping(self, payload: typing.Union[QtCore.QByteArray, bytes, bytearray] = ...) -> None: ... @typing.overload def open(self, url: QtCore.QUrl) -> None: ... @@ -111,10 +111,7 @@ class QWebSocket(QtCore.QObject): def isValid(self) -> bool: ... def flush(self) -> bool: ... def errorString(self) -> str: ... - @typing.overload - def error(self) -> QtNetwork.QAbstractSocket.SocketError: ... - @typing.overload - def error(self, error: QtNetwork.QAbstractSocket.SocketError) -> None: ... + error: typing.ClassVar[QtCore.pyqtSignal] def abort(self) -> None: ... @@ -199,14 +196,14 @@ class QWebSocketServer(QtCore.QObject): def setHandshakeTimeout(self, msec: int) -> None: ... def nativeDescriptor(self) -> sip.voidptr: ... def setNativeDescriptor(self, descriptor: sip.voidptr) -> bool: ... - def preSharedKeyAuthenticationRequired(self, authenticator: QtNetwork.QSslPreSharedKeyAuthenticator) -> None: ... - def closed(self) -> None: ... - def sslErrors(self, errors: typing.Iterable[QtNetwork.QSslError]) -> None: ... - def peerVerifyError(self, error: QtNetwork.QSslError) -> None: ... - def newConnection(self) -> None: ... - def originAuthenticationRequired(self, pAuthenticator: QWebSocketCorsAuthenticator) -> None: ... - def serverError(self, closeCode: QWebSocketProtocol.CloseCode) -> None: ... - def acceptError(self, socketError: QtNetwork.QAbstractSocket.SocketError) -> None: ... + preSharedKeyAuthenticationRequired: typing.ClassVar[QtCore.pyqtSignal] + closed: typing.ClassVar[QtCore.pyqtSignal] + sslErrors: typing.ClassVar[QtCore.pyqtSignal] + peerVerifyError: typing.ClassVar[QtCore.pyqtSignal] + newConnection: typing.ClassVar[QtCore.pyqtSignal] + originAuthenticationRequired: typing.ClassVar[QtCore.pyqtSignal] + serverError: typing.ClassVar[QtCore.pyqtSignal] + acceptError: typing.ClassVar[QtCore.pyqtSignal] def handleConnection(self, socket: QtNetwork.QTcpSocket) -> None: ... def serverUrl(self) -> QtCore.QUrl: ... def supportedVersions(self) -> typing.List[QWebSocketProtocol.Version]: ... diff --git a/PyQt5-stubs/QtWidgets.pyi b/PyQt5-stubs/QtWidgets.pyi index 92d28ffb..161f6e0b 100644 --- a/PyQt5-stubs/QtWidgets.pyi +++ b/PyQt5-stubs/QtWidgets.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtWidgets module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # @@ -43,6 +43,9 @@ PYQT_OPENGL_BOUND_ARRAY = typing.Union[typing.Sequence[int], class QWidget(QtCore.QObject, QtGui.QPaintDevice): class RenderFlag(int): + def __or__ (self, other: 'QWidget.RenderFlag') -> 'QWidget.RenderFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QWidget.RenderFlags': ... # type: ignore[override, misc] + DrawWindowBackground = ... # type: QWidget.RenderFlag DrawChildren = ... # type: QWidget.RenderFlag IgnoreMask = ... # type: QWidget.RenderFlag @@ -59,12 +62,20 @@ class QWidget(QtCore.QObject, QtGui.QPaintDevice): def __init__(self, f: typing.Union['QWidget.RenderFlags', 'QWidget.RenderFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QWidget.RenderFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QWidget.RenderFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QWidget.RenderFlags', 'QWidget.RenderFlag', int]) -> 'QWidget.RenderFlags': ... + def __and__(self, other: typing.Union['QWidget.RenderFlags', 'QWidget.RenderFlag', int]) -> 'QWidget.RenderFlags': ... + def __xor__(self, other: typing.Union['QWidget.RenderFlags', 'QWidget.RenderFlag', int]) -> 'QWidget.RenderFlags': ... + def __ror__ (self, other: 'QWidget.RenderFlag') -> 'QWidget.RenderFlags': ... + def __rand__(self, other: 'QWidget.RenderFlag') -> 'QWidget.RenderFlags': ... + def __rxor__(self, other: 'QWidget.RenderFlag') -> 'QWidget.RenderFlags': ... def __init__(self, parent: typing.Optional['QWidget'] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> None: ... @@ -690,6 +701,9 @@ class QAbstractItemView(QAbstractScrollArea): PositionAtCenter = ... # type: QAbstractItemView.ScrollHint class EditTrigger(int): + def __or__ (self, other: 'QAbstractItemView.EditTrigger') -> 'QAbstractItemView.EditTriggers': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QAbstractItemView.EditTriggers': ... # type: ignore[override, misc] + NoEditTriggers = ... # type: QAbstractItemView.EditTrigger CurrentChanged = ... # type: QAbstractItemView.EditTrigger DoubleClicked = ... # type: QAbstractItemView.EditTrigger @@ -727,12 +741,20 @@ class QAbstractItemView(QAbstractScrollArea): def __init__(self, f: typing.Union['QAbstractItemView.EditTriggers', 'QAbstractItemView.EditTrigger']) -> None: ... @typing.overload def __init__(self, a0: 'QAbstractItemView.EditTriggers') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QAbstractItemView.EditTriggers': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QAbstractItemView.EditTriggers', 'QAbstractItemView.EditTrigger', int]) -> 'QAbstractItemView.EditTriggers': ... + def __and__(self, other: typing.Union['QAbstractItemView.EditTriggers', 'QAbstractItemView.EditTrigger', int]) -> 'QAbstractItemView.EditTriggers': ... + def __xor__(self, other: typing.Union['QAbstractItemView.EditTriggers', 'QAbstractItemView.EditTrigger', int]) -> 'QAbstractItemView.EditTriggers': ... + def __ror__ (self, other: 'QAbstractItemView.EditTrigger') -> 'QAbstractItemView.EditTriggers': ... + def __rand__(self, other: 'QAbstractItemView.EditTrigger') -> 'QAbstractItemView.EditTriggers': ... + def __rxor__(self, other: 'QAbstractItemView.EditTrigger') -> 'QAbstractItemView.EditTriggers': ... def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -974,6 +996,9 @@ class QAbstractSpinBox(QWidget): NoButtons = ... # type: QAbstractSpinBox.ButtonSymbols class StepEnabledFlag(int): + def __or__ (self, other: 'QAbstractSpinBox.StepEnabledFlag') -> 'QAbstractSpinBox.StepEnabled': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QAbstractSpinBox.StepEnabled': ... # type: ignore[override, misc] + StepNone = ... # type: QAbstractSpinBox.StepEnabledFlag StepUpEnabled = ... # type: QAbstractSpinBox.StepEnabledFlag StepDownEnabled = ... # type: QAbstractSpinBox.StepEnabledFlag @@ -990,12 +1015,20 @@ class QAbstractSpinBox(QWidget): def __init__(self, f: typing.Union['QAbstractSpinBox.StepEnabled', 'QAbstractSpinBox.StepEnabledFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QAbstractSpinBox.StepEnabled') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QAbstractSpinBox.StepEnabled': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QAbstractSpinBox.StepEnabled', 'QAbstractSpinBox.StepEnabledFlag', int]) -> 'QAbstractSpinBox.StepEnabled': ... + def __and__(self, other: typing.Union['QAbstractSpinBox.StepEnabled', 'QAbstractSpinBox.StepEnabledFlag', int]) -> 'QAbstractSpinBox.StepEnabled': ... + def __xor__(self, other: typing.Union['QAbstractSpinBox.StepEnabled', 'QAbstractSpinBox.StepEnabledFlag', int]) -> 'QAbstractSpinBox.StepEnabled': ... + def __ror__ (self, other: 'QAbstractSpinBox.StepEnabledFlag') -> 'QAbstractSpinBox.StepEnabled': ... + def __rand__(self, other: 'QAbstractSpinBox.StepEnabledFlag') -> 'QAbstractSpinBox.StepEnabled': ... + def __rxor__(self, other: 'QAbstractSpinBox.StepEnabledFlag') -> 'QAbstractSpinBox.StepEnabled': ... def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -1515,10 +1548,10 @@ class QButtonGroup(QtCore.QObject): def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... - def idToggled(self, a0: int, a1: bool) -> None: ... - def idReleased(self, a0: int) -> None: ... - def idPressed(self, a0: int) -> None: ... - def idClicked(self, a0: int) -> None: ... + idToggled: typing.ClassVar[QtCore.pyqtSignal] + idReleased: typing.ClassVar[QtCore.pyqtSignal] + idPressed: typing.ClassVar[QtCore.pyqtSignal] + idClicked: typing.ClassVar[QtCore.pyqtSignal] buttonToggled: typing.ClassVar[QtCore.pyqtSignal] buttonReleased: typing.ClassVar[QtCore.pyqtSignal] buttonPressed: typing.ClassVar[QtCore.pyqtSignal] @@ -1685,6 +1718,9 @@ class QDialog(QWidget): class QColorDialog(QDialog): class ColorDialogOption(int): + def __or__ (self, other: 'QColorDialog.ColorDialogOption') -> 'QColorDialog.ColorDialogOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QColorDialog.ColorDialogOptions': ... # type: ignore[override, misc] + ShowAlphaChannel = ... # type: QColorDialog.ColorDialogOption NoButtons = ... # type: QColorDialog.ColorDialogOption DontUseNativeDialog = ... # type: QColorDialog.ColorDialogOption @@ -1701,12 +1737,20 @@ class QColorDialog(QDialog): def __init__(self, f: typing.Union['QColorDialog.ColorDialogOptions', 'QColorDialog.ColorDialogOption']) -> None: ... @typing.overload def __init__(self, a0: 'QColorDialog.ColorDialogOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QColorDialog.ColorDialogOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QColorDialog.ColorDialogOptions', 'QColorDialog.ColorDialogOption', int]) -> 'QColorDialog.ColorDialogOptions': ... + def __and__(self, other: typing.Union['QColorDialog.ColorDialogOptions', 'QColorDialog.ColorDialogOption', int]) -> 'QColorDialog.ColorDialogOptions': ... + def __xor__(self, other: typing.Union['QColorDialog.ColorDialogOptions', 'QColorDialog.ColorDialogOption', int]) -> 'QColorDialog.ColorDialogOptions': ... + def __ror__ (self, other: 'QColorDialog.ColorDialogOption') -> 'QColorDialog.ColorDialogOptions': ... + def __rand__(self, other: 'QColorDialog.ColorDialogOption') -> 'QColorDialog.ColorDialogOptions': ... + def __rxor__(self, other: 'QColorDialog.ColorDialogOption') -> 'QColorDialog.ColorDialogOptions': ... @typing.overload def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -1810,8 +1854,8 @@ class QComboBox(QWidget): def placeholderText(self) -> str: ... def setPlaceholderText(self, placeholderText: str) -> None: ... - def textHighlighted(self, a0: str) -> None: ... - def textActivated(self, a0: str) -> None: ... + textHighlighted: typing.ClassVar[QtCore.pyqtSignal] + textActivated: typing.ClassVar[QtCore.pyqtSignal] def currentData(self, role: int = ...) -> typing.Any: ... @typing.overload def inputMethodQuery(self, a0: QtCore.Qt.InputMethodQuery) -> typing.Any: ... @@ -1832,10 +1876,7 @@ class QComboBox(QWidget): def focusOutEvent(self, e: QtGui.QFocusEvent) -> None: ... def focusInEvent(self, e: QtGui.QFocusEvent) -> None: ... def initStyleOption(self, option: 'QStyleOptionComboBox') -> None: ... - @typing.overload - def highlighted(self, index: int) -> None: ... - @typing.overload - def highlighted(self, a0: str) -> None: ... + highlighted: typing.ClassVar[QtCore.pyqtSignal] currentTextChanged: typing.ClassVar[QtCore.pyqtSignal] currentIndexChanged: typing.ClassVar[QtCore.pyqtSignal] activated: typing.ClassVar[QtCore.pyqtSignal] @@ -2621,6 +2662,9 @@ class QStyle(QtCore.QObject): PM_CustomBase = ... # type: QStyle.PixelMetric class SubControl(int): + def __or__ (self, other: 'QStyle.SubControl') -> 'QStyle.SubControls': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QStyle.SubControls': ... # type: ignore[override, misc] + SC_None = ... # type: QStyle.SubControl SC_ScrollBarAddLine = ... # type: QStyle.SubControl SC_ScrollBarSubLine = ... # type: QStyle.SubControl @@ -3068,6 +3112,9 @@ class QStyle(QtCore.QObject): PE_CustomBase = ... # type: QStyle.PrimitiveElement class StateFlag(int): + def __or__ (self, other: 'QStyle.StateFlag') -> 'QStyle.State': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QStyle.State': ... # type: ignore[override, misc] + State_None = ... # type: QStyle.StateFlag State_Enabled = ... # type: QStyle.StateFlag State_Raised = ... # type: QStyle.StateFlag @@ -3134,12 +3181,20 @@ class QStyle(QtCore.QObject): def __init__(self, f: typing.Union['QStyle.State', 'QStyle.StateFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QStyle.State') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStyle.State': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStyle.State', 'QStyle.StateFlag', int]) -> 'QStyle.State': ... + def __and__(self, other: typing.Union['QStyle.State', 'QStyle.StateFlag', int]) -> 'QStyle.State': ... + def __xor__(self, other: typing.Union['QStyle.State', 'QStyle.StateFlag', int]) -> 'QStyle.State': ... + def __ror__ (self, other: 'QStyle.StateFlag') -> 'QStyle.State': ... + def __rand__(self, other: 'QStyle.StateFlag') -> 'QStyle.State': ... + def __rxor__(self, other: 'QStyle.StateFlag') -> 'QStyle.State': ... class SubControls(sip.simplewrapper): @@ -3149,12 +3204,20 @@ class QStyle(QtCore.QObject): def __init__(self, f: typing.Union['QStyle.SubControls', 'QStyle.SubControl']) -> None: ... @typing.overload def __init__(self, a0: 'QStyle.SubControls') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStyle.SubControls': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStyle.SubControls', 'QStyle.SubControl', int]) -> 'QStyle.SubControls': ... + def __and__(self, other: typing.Union['QStyle.SubControls', 'QStyle.SubControl', int]) -> 'QStyle.SubControls': ... + def __xor__(self, other: typing.Union['QStyle.SubControls', 'QStyle.SubControl', int]) -> 'QStyle.SubControls': ... + def __ror__ (self, other: 'QStyle.SubControl') -> 'QStyle.SubControls': ... + def __rand__(self, other: 'QStyle.SubControl') -> 'QStyle.SubControls': ... + def __rxor__(self, other: 'QStyle.SubControl') -> 'QStyle.SubControls': ... def __init__(self) -> None: ... @@ -3251,12 +3314,12 @@ class QCompleter(QtCore.QObject): UnfilteredPopupCompletion = ... # type: QCompleter.CompletionMode InlineCompletion = ... # type: QCompleter.CompletionMode - @typing.overload - def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @typing.overload def __init__(self, model: QtCore.QAbstractItemModel, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @typing.overload def __init__(self, list: typing.Iterable[str], parent: typing.Optional[QtCore.QObject] = ...) -> None: ... + @typing.overload + def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def filterMode(self) -> QtCore.Qt.MatchFlags: ... def setFilterMode(self, filterMode: typing.Union[QtCore.Qt.MatchFlags, QtCore.Qt.MatchFlag]) -> None: ... @@ -3342,6 +3405,9 @@ class QDataWidgetMapper(QtCore.QObject): class QDateTimeEdit(QAbstractSpinBox): class Section(int): + def __or__ (self, other: 'QDateTimeEdit.Section') -> 'QDateTimeEdit.Sections': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QDateTimeEdit.Sections': ... # type: ignore[override, misc] + NoSection = ... # type: QDateTimeEdit.Section AmPmSection = ... # type: QDateTimeEdit.Section MSecSection = ... # type: QDateTimeEdit.Section @@ -3374,12 +3440,20 @@ class QDateTimeEdit(QAbstractSpinBox): def __init__(self, f: typing.Union['QDateTimeEdit.Sections', 'QDateTimeEdit.Section']) -> None: ... @typing.overload def __init__(self, a0: 'QDateTimeEdit.Sections') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDateTimeEdit.Sections': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDateTimeEdit.Sections', 'QDateTimeEdit.Section', int]) -> 'QDateTimeEdit.Sections': ... + def __and__(self, other: typing.Union['QDateTimeEdit.Sections', 'QDateTimeEdit.Section', int]) -> 'QDateTimeEdit.Sections': ... + def __xor__(self, other: typing.Union['QDateTimeEdit.Sections', 'QDateTimeEdit.Section', int]) -> 'QDateTimeEdit.Sections': ... + def __ror__ (self, other: 'QDateTimeEdit.Section') -> 'QDateTimeEdit.Sections': ... + def __rand__(self, other: 'QDateTimeEdit.Section') -> 'QDateTimeEdit.Sections': ... + def __rxor__(self, other: 'QDateTimeEdit.Section') -> 'QDateTimeEdit.Sections': ... @typing.overload def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -3478,10 +3552,10 @@ class QDesktopWidget(QWidget): def __init__(self) -> None: ... def resizeEvent(self, e: QtGui.QResizeEvent) -> None: ... - def primaryScreenChanged(self) -> None: ... - def screenCountChanged(self, a0: int) -> None: ... - def workAreaResized(self, a0: int) -> None: ... - def resized(self, a0: int) -> None: ... + primaryScreenChanged: typing.ClassVar[QtCore.pyqtSignal] + screenCountChanged: typing.ClassVar[QtCore.pyqtSignal] + workAreaResized: typing.ClassVar[QtCore.pyqtSignal] + resized: typing.ClassVar[QtCore.pyqtSignal] @typing.overload def availableGeometry(self, screen: int = ...) -> QtCore.QRect: ... @typing.overload @@ -3530,6 +3604,9 @@ class QDial(QAbstractSlider): class QDialogButtonBox(QWidget): class StandardButton(int): + def __or__ (self, other: 'QDialogButtonBox.StandardButton') -> 'QDialogButtonBox.StandardButtons': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QDialogButtonBox.StandardButtons': ... # type: ignore[override, misc] + NoButton = ... # type: QDialogButtonBox.StandardButton Ok = ... # type: QDialogButtonBox.StandardButton Save = ... # type: QDialogButtonBox.StandardButton @@ -3614,12 +3691,20 @@ class QDialogButtonBox(QWidget): def __init__(self, f: typing.Union['QDialogButtonBox.StandardButtons', 'QDialogButtonBox.StandardButton']) -> None: ... @typing.overload def __init__(self, a0: 'QDialogButtonBox.StandardButtons') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDialogButtonBox.StandardButtons': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDialogButtonBox.StandardButtons', 'QDialogButtonBox.StandardButton', int]) -> 'QDialogButtonBox.StandardButtons': ... + def __and__(self, other: typing.Union['QDialogButtonBox.StandardButtons', 'QDialogButtonBox.StandardButton', int]) -> 'QDialogButtonBox.StandardButtons': ... + def __xor__(self, other: typing.Union['QDialogButtonBox.StandardButtons', 'QDialogButtonBox.StandardButton', int]) -> 'QDialogButtonBox.StandardButtons': ... + def __ror__ (self, other: 'QDialogButtonBox.StandardButton') -> 'QDialogButtonBox.StandardButtons': ... + def __rand__(self, other: 'QDialogButtonBox.StandardButton') -> 'QDialogButtonBox.StandardButtons': ... + def __rxor__(self, other: 'QDialogButtonBox.StandardButton') -> 'QDialogButtonBox.StandardButtons': ... @typing.overload def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -3720,6 +3805,9 @@ class QDirModel(QtCore.QAbstractItemModel): class QDockWidget(QWidget): class DockWidgetFeature(int): + def __or__ (self, other: 'QDockWidget.DockWidgetFeature') -> 'QDockWidget.DockWidgetFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QDockWidget.DockWidgetFeatures': ... # type: ignore[override, misc] + DockWidgetClosable = ... # type: QDockWidget.DockWidgetFeature DockWidgetMovable = ... # type: QDockWidget.DockWidgetFeature DockWidgetFloatable = ... # type: QDockWidget.DockWidgetFeature @@ -3742,12 +3830,20 @@ class QDockWidget(QWidget): def __init__(self, f: typing.Union['QDockWidget.DockWidgetFeatures', 'QDockWidget.DockWidgetFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QDockWidget.DockWidgetFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QDockWidget.DockWidgetFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QDockWidget.DockWidgetFeatures', 'QDockWidget.DockWidgetFeature', int]) -> 'QDockWidget.DockWidgetFeatures': ... + def __and__(self, other: typing.Union['QDockWidget.DockWidgetFeatures', 'QDockWidget.DockWidgetFeature', int]) -> 'QDockWidget.DockWidgetFeatures': ... + def __xor__(self, other: typing.Union['QDockWidget.DockWidgetFeatures', 'QDockWidget.DockWidgetFeature', int]) -> 'QDockWidget.DockWidgetFeatures': ... + def __ror__ (self, other: 'QDockWidget.DockWidgetFeature') -> 'QDockWidget.DockWidgetFeatures': ... + def __rand__(self, other: 'QDockWidget.DockWidgetFeature') -> 'QDockWidget.DockWidgetFeatures': ... + def __rxor__(self, other: 'QDockWidget.DockWidgetFeature') -> 'QDockWidget.DockWidgetFeatures': ... @typing.overload def __init__(self, title: str, parent: typing.Optional[QWidget] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> None: ... @@ -3795,6 +3891,9 @@ class QErrorMessage(QDialog): class QFileDialog(QDialog): class Option(int): + def __or__ (self, other: 'QFileDialog.Option') -> 'QFileDialog.Options': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QFileDialog.Options': ... # type: ignore[override, misc] + ShowDirsOnly = ... # type: QFileDialog.Option DontResolveSymlinks = ... # type: QFileDialog.Option DontConfirmOverwrite = ... # type: QFileDialog.Option @@ -3861,12 +3960,20 @@ class QFileDialog(QDialog): def __init__(self, f: typing.Union['QFileDialog.Options', 'QFileDialog.Option']) -> None: ... @typing.overload def __init__(self, a0: 'QFileDialog.Options') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QFileDialog.Options': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QFileDialog.Options', 'QFileDialog.Option', int]) -> 'QFileDialog.Options': ... + def __and__(self, other: typing.Union['QFileDialog.Options', 'QFileDialog.Option', int]) -> 'QFileDialog.Options': ... + def __xor__(self, other: typing.Union['QFileDialog.Options', 'QFileDialog.Option', int]) -> 'QFileDialog.Options': ... + def __ror__ (self, other: 'QFileDialog.Option') -> 'QFileDialog.Options': ... + def __rand__(self, other: 'QFileDialog.Option') -> 'QFileDialog.Options': ... + def __rxor__(self, other: 'QFileDialog.Option') -> 'QFileDialog.Options': ... @typing.overload def __init__(self, parent: QWidget, f: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType]) -> None: ... @@ -3963,6 +4070,9 @@ class QFileDialog(QDialog): class QFileIconProvider(sip.simplewrapper): class Option(int): + def __or__ (self, other: 'QFileIconProvider.Option') -> 'QFileIconProvider.Options': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QFileIconProvider.Options': ... # type: ignore[override, misc] + DontUseCustomDirectoryIcons = ... # type: QFileIconProvider.Option DontUseCustomDirectoryIcons = ... # type: QFileIconProvider.Option @@ -3992,12 +4102,20 @@ class QFileIconProvider(sip.simplewrapper): def __init__(self, f: typing.Union['QFileIconProvider.Options', 'QFileIconProvider.Option']) -> None: ... @typing.overload def __init__(self, a0: 'QFileIconProvider.Options') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QFileIconProvider.Options': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QFileIconProvider.Options', 'QFileIconProvider.Option', int]) -> 'QFileIconProvider.Options': ... + def __and__(self, other: typing.Union['QFileIconProvider.Options', 'QFileIconProvider.Option', int]) -> 'QFileIconProvider.Options': ... + def __xor__(self, other: typing.Union['QFileIconProvider.Options', 'QFileIconProvider.Option', int]) -> 'QFileIconProvider.Options': ... + def __ror__ (self, other: 'QFileIconProvider.Option') -> 'QFileIconProvider.Options': ... + def __rand__(self, other: 'QFileIconProvider.Option') -> 'QFileIconProvider.Options': ... + def __rxor__(self, other: 'QFileIconProvider.Option') -> 'QFileIconProvider.Options': ... def __init__(self) -> None: ... @@ -4013,6 +4131,9 @@ class QFileIconProvider(sip.simplewrapper): class QFileSystemModel(QtCore.QAbstractItemModel): class Option(int): + def __or__ (self, other: 'QFileSystemModel.Option') -> 'QFileSystemModel.Options': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QFileSystemModel.Options': ... # type: ignore[override, misc] + DontWatchForChanges = ... # type: QFileSystemModel.Option DontResolveSymlinks = ... # type: QFileSystemModel.Option DontUseCustomDirectoryIcons = ... # type: QFileSystemModel.Option @@ -4040,12 +4161,20 @@ class QFileSystemModel(QtCore.QAbstractItemModel): def __init__(self, f: typing.Union['QFileSystemModel.Options', 'QFileSystemModel.Option']) -> None: ... @typing.overload def __init__(self, a0: 'QFileSystemModel.Options') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QFileSystemModel.Options': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QFileSystemModel.Options', 'QFileSystemModel.Option', int]) -> 'QFileSystemModel.Options': ... + def __and__(self, other: typing.Union['QFileSystemModel.Options', 'QFileSystemModel.Option', int]) -> 'QFileSystemModel.Options': ... + def __xor__(self, other: typing.Union['QFileSystemModel.Options', 'QFileSystemModel.Option', int]) -> 'QFileSystemModel.Options': ... + def __ror__ (self, other: 'QFileSystemModel.Option') -> 'QFileSystemModel.Options': ... + def __rand__(self, other: 'QFileSystemModel.Option') -> 'QFileSystemModel.Options': ... + def __rxor__(self, other: 'QFileSystemModel.Option') -> 'QFileSystemModel.Options': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -4123,6 +4252,9 @@ class QFocusFrame(QWidget): class QFontComboBox(QComboBox): class FontFilter(int): + def __or__ (self, other: 'QFontComboBox.FontFilter') -> 'QFontComboBox.FontFilters': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QFontComboBox.FontFilters': ... # type: ignore[override, misc] + AllFonts = ... # type: QFontComboBox.FontFilter ScalableFonts = ... # type: QFontComboBox.FontFilter NonScalableFonts = ... # type: QFontComboBox.FontFilter @@ -4143,12 +4275,20 @@ class QFontComboBox(QComboBox): def __init__(self, f: typing.Union['QFontComboBox.FontFilters', 'QFontComboBox.FontFilter']) -> None: ... @typing.overload def __init__(self, a0: 'QFontComboBox.FontFilters') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QFontComboBox.FontFilters': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QFontComboBox.FontFilters', 'QFontComboBox.FontFilter', int]) -> 'QFontComboBox.FontFilters': ... + def __and__(self, other: typing.Union['QFontComboBox.FontFilters', 'QFontComboBox.FontFilter', int]) -> 'QFontComboBox.FontFilters': ... + def __xor__(self, other: typing.Union['QFontComboBox.FontFilters', 'QFontComboBox.FontFilter', int]) -> 'QFontComboBox.FontFilters': ... + def __ror__ (self, other: 'QFontComboBox.FontFilter') -> 'QFontComboBox.FontFilters': ... + def __rand__(self, other: 'QFontComboBox.FontFilter') -> 'QFontComboBox.FontFilters': ... + def __rxor__(self, other: 'QFontComboBox.FontFilter') -> 'QFontComboBox.FontFilters': ... def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -4166,6 +4306,9 @@ class QFontComboBox(QComboBox): class QFontDialog(QDialog): class FontDialogOption(int): + def __or__ (self, other: 'QFontDialog.FontDialogOption') -> 'QFontDialog.FontDialogOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QFontDialog.FontDialogOptions': ... # type: ignore[override, misc] + NoButtons = ... # type: QFontDialog.FontDialogOption DontUseNativeDialog = ... # type: QFontDialog.FontDialogOption ScalableFonts = ... # type: QFontDialog.FontDialogOption @@ -4188,12 +4331,20 @@ class QFontDialog(QDialog): def __init__(self, f: typing.Union['QFontDialog.FontDialogOptions', 'QFontDialog.FontDialogOption']) -> None: ... @typing.overload def __init__(self, a0: 'QFontDialog.FontDialogOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QFontDialog.FontDialogOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QFontDialog.FontDialogOptions', 'QFontDialog.FontDialogOption', int]) -> 'QFontDialog.FontDialogOptions': ... + def __and__(self, other: typing.Union['QFontDialog.FontDialogOptions', 'QFontDialog.FontDialogOption', int]) -> 'QFontDialog.FontDialogOptions': ... + def __xor__(self, other: typing.Union['QFontDialog.FontDialogOptions', 'QFontDialog.FontDialogOption', int]) -> 'QFontDialog.FontDialogOptions': ... + def __ror__ (self, other: 'QFontDialog.FontDialogOption') -> 'QFontDialog.FontDialogOptions': ... + def __rand__(self, other: 'QFontDialog.FontDialogOption') -> 'QFontDialog.FontDialogOptions': ... + def __rxor__(self, other: 'QFontDialog.FontDialogOption') -> 'QFontDialog.FontDialogOptions': ... @typing.overload def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -4396,12 +4547,20 @@ class QPinchGesture(QGesture): def __init__(self, f: typing.Union['QPinchGesture.ChangeFlags', 'QPinchGesture.ChangeFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QPinchGesture.ChangeFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QPinchGesture.ChangeFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QPinchGesture.ChangeFlags', 'QPinchGesture.ChangeFlag', int]) -> 'QPinchGesture.ChangeFlags': ... + def __and__(self, other: typing.Union['QPinchGesture.ChangeFlags', 'QPinchGesture.ChangeFlag', int]) -> 'QPinchGesture.ChangeFlags': ... + def __xor__(self, other: typing.Union['QPinchGesture.ChangeFlags', 'QPinchGesture.ChangeFlag', int]) -> 'QPinchGesture.ChangeFlags': ... + def __ror__ (self, other: 'QPinchGesture.ChangeFlag') -> 'QPinchGesture.ChangeFlags': ... + def __rand__(self, other: 'QPinchGesture.ChangeFlag') -> 'QPinchGesture.ChangeFlags': ... + def __rxor__(self, other: 'QPinchGesture.ChangeFlag') -> 'QPinchGesture.ChangeFlags': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -4514,6 +4673,9 @@ class QGestureEvent(QtCore.QEvent): class QGestureRecognizer(sip.wrapper): class ResultFlag(int): + def __or__ (self, other: 'QGestureRecognizer.ResultFlag') -> 'QGestureRecognizer.Result': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGestureRecognizer.Result': ... # type: ignore[override, misc] + Ignore = ... # type: QGestureRecognizer.ResultFlag MayBeGesture = ... # type: QGestureRecognizer.ResultFlag TriggerGesture = ... # type: QGestureRecognizer.ResultFlag @@ -4536,12 +4698,20 @@ class QGestureRecognizer(sip.wrapper): def __init__(self, f: typing.Union['QGestureRecognizer.Result', 'QGestureRecognizer.ResultFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QGestureRecognizer.Result') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGestureRecognizer.Result': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGestureRecognizer.Result', 'QGestureRecognizer.ResultFlag', int]) -> 'QGestureRecognizer.Result': ... + def __and__(self, other: typing.Union['QGestureRecognizer.Result', 'QGestureRecognizer.ResultFlag', int]) -> 'QGestureRecognizer.Result': ... + def __xor__(self, other: typing.Union['QGestureRecognizer.Result', 'QGestureRecognizer.ResultFlag', int]) -> 'QGestureRecognizer.Result': ... + def __ror__ (self, other: 'QGestureRecognizer.ResultFlag') -> 'QGestureRecognizer.Result': ... + def __rand__(self, other: 'QGestureRecognizer.ResultFlag') -> 'QGestureRecognizer.Result': ... + def __rxor__(self, other: 'QGestureRecognizer.ResultFlag') -> 'QGestureRecognizer.Result': ... @typing.overload def __init__(self) -> None: ... @@ -4669,6 +4839,9 @@ class QGraphicsEffect(QtCore.QObject): PadToEffectiveBoundingRect = ... # type: QGraphicsEffect.PixmapPadMode class ChangeFlag(int): + def __or__ (self, other: 'QGraphicsEffect.ChangeFlag') -> 'QGraphicsEffect.ChangeFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGraphicsEffect.ChangeFlags': ... # type: ignore[override, misc] + SourceAttached = ... # type: QGraphicsEffect.ChangeFlag SourceDetached = ... # type: QGraphicsEffect.ChangeFlag SourceBoundingRectChanged = ... # type: QGraphicsEffect.ChangeFlag @@ -4687,12 +4860,20 @@ class QGraphicsEffect(QtCore.QObject): def __init__(self, f: typing.Union['QGraphicsEffect.ChangeFlags', 'QGraphicsEffect.ChangeFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QGraphicsEffect.ChangeFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGraphicsEffect.ChangeFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGraphicsEffect.ChangeFlags', 'QGraphicsEffect.ChangeFlag', int]) -> 'QGraphicsEffect.ChangeFlags': ... + def __and__(self, other: typing.Union['QGraphicsEffect.ChangeFlags', 'QGraphicsEffect.ChangeFlag', int]) -> 'QGraphicsEffect.ChangeFlags': ... + def __xor__(self, other: typing.Union['QGraphicsEffect.ChangeFlags', 'QGraphicsEffect.ChangeFlag', int]) -> 'QGraphicsEffect.ChangeFlags': ... + def __ror__ (self, other: 'QGraphicsEffect.ChangeFlag') -> 'QGraphicsEffect.ChangeFlags': ... + def __rand__(self, other: 'QGraphicsEffect.ChangeFlag') -> 'QGraphicsEffect.ChangeFlags': ... + def __rxor__(self, other: 'QGraphicsEffect.ChangeFlag') -> 'QGraphicsEffect.ChangeFlags': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -4727,6 +4908,9 @@ class QGraphicsColorizeEffect(QGraphicsEffect): class QGraphicsBlurEffect(QGraphicsEffect): class BlurHint(int): + def __or__ (self, other: 'QGraphicsBlurEffect.BlurHint') -> 'QGraphicsBlurEffect.BlurHints': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGraphicsBlurEffect.BlurHints': ... # type: ignore[override, misc] + PerformanceHint = ... # type: QGraphicsBlurEffect.BlurHint QualityHint = ... # type: QGraphicsBlurEffect.BlurHint AnimationHint = ... # type: QGraphicsBlurEffect.BlurHint @@ -4743,12 +4927,20 @@ class QGraphicsBlurEffect(QGraphicsEffect): def __init__(self, f: typing.Union['QGraphicsBlurEffect.BlurHints', 'QGraphicsBlurEffect.BlurHint']) -> None: ... @typing.overload def __init__(self, a0: 'QGraphicsBlurEffect.BlurHints') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGraphicsBlurEffect.BlurHints': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGraphicsBlurEffect.BlurHints', 'QGraphicsBlurEffect.BlurHint', int]) -> 'QGraphicsBlurEffect.BlurHints': ... + def __and__(self, other: typing.Union['QGraphicsBlurEffect.BlurHints', 'QGraphicsBlurEffect.BlurHint', int]) -> 'QGraphicsBlurEffect.BlurHints': ... + def __xor__(self, other: typing.Union['QGraphicsBlurEffect.BlurHints', 'QGraphicsBlurEffect.BlurHint', int]) -> 'QGraphicsBlurEffect.BlurHints': ... + def __ror__ (self, other: 'QGraphicsBlurEffect.BlurHint') -> 'QGraphicsBlurEffect.BlurHints': ... + def __rand__(self, other: 'QGraphicsBlurEffect.BlurHint') -> 'QGraphicsBlurEffect.BlurHints': ... + def __rxor__(self, other: 'QGraphicsBlurEffect.BlurHint') -> 'QGraphicsBlurEffect.BlurHints': ... def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -4868,6 +5060,9 @@ class QGraphicsItem(sip.wrapper): SceneModal = ... # type: QGraphicsItem.PanelModality class GraphicsItemFlag(int): + def __or__ (self, other: 'QGraphicsItem.GraphicsItemFlag') -> 'QGraphicsItem.GraphicsItemFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGraphicsItem.GraphicsItemFlags': ... # type: ignore[override, misc] + ItemIsMovable = ... # type: QGraphicsItem.GraphicsItemFlag ItemIsSelectable = ... # type: QGraphicsItem.GraphicsItemFlag ItemIsFocusable = ... # type: QGraphicsItem.GraphicsItemFlag @@ -4992,12 +5187,20 @@ class QGraphicsItem(sip.wrapper): def __init__(self, f: typing.Union['QGraphicsItem.GraphicsItemFlags', 'QGraphicsItem.GraphicsItemFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QGraphicsItem.GraphicsItemFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGraphicsItem.GraphicsItemFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGraphicsItem.GraphicsItemFlags', 'QGraphicsItem.GraphicsItemFlag', int]) -> 'QGraphicsItem.GraphicsItemFlags': ... + def __and__(self, other: typing.Union['QGraphicsItem.GraphicsItemFlags', 'QGraphicsItem.GraphicsItemFlag', int]) -> 'QGraphicsItem.GraphicsItemFlags': ... + def __xor__(self, other: typing.Union['QGraphicsItem.GraphicsItemFlags', 'QGraphicsItem.GraphicsItemFlag', int]) -> 'QGraphicsItem.GraphicsItemFlags': ... + def __ror__ (self, other: 'QGraphicsItem.GraphicsItemFlag') -> 'QGraphicsItem.GraphicsItemFlags': ... + def __rand__(self, other: 'QGraphicsItem.GraphicsItemFlag') -> 'QGraphicsItem.GraphicsItemFlags': ... + def __rxor__(self, other: 'QGraphicsItem.GraphicsItemFlag') -> 'QGraphicsItem.GraphicsItemFlags': ... Type = ... # type: int UserType = ... # type: int @@ -5707,6 +5910,9 @@ class QGraphicsProxyWidget(QGraphicsWidget): class QGraphicsScene(QtCore.QObject): class SceneLayer(int): + def __or__ (self, other: 'QGraphicsScene.SceneLayer') -> 'QGraphicsScene.SceneLayers': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGraphicsScene.SceneLayers': ... # type: ignore[override, misc] + ItemLayer = ... # type: QGraphicsScene.SceneLayer BackgroundLayer = ... # type: QGraphicsScene.SceneLayer ForegroundLayer = ... # type: QGraphicsScene.SceneLayer @@ -5732,12 +5938,20 @@ class QGraphicsScene(QtCore.QObject): def __init__(self, f: typing.Union['QGraphicsScene.SceneLayers', 'QGraphicsScene.SceneLayer']) -> None: ... @typing.overload def __init__(self, a0: 'QGraphicsScene.SceneLayers') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGraphicsScene.SceneLayers': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGraphicsScene.SceneLayers', 'QGraphicsScene.SceneLayer', int]) -> 'QGraphicsScene.SceneLayers': ... + def __and__(self, other: typing.Union['QGraphicsScene.SceneLayers', 'QGraphicsScene.SceneLayer', int]) -> 'QGraphicsScene.SceneLayers': ... + def __xor__(self, other: typing.Union['QGraphicsScene.SceneLayers', 'QGraphicsScene.SceneLayer', int]) -> 'QGraphicsScene.SceneLayers': ... + def __ror__ (self, other: 'QGraphicsScene.SceneLayer') -> 'QGraphicsScene.SceneLayers': ... + def __rand__(self, other: 'QGraphicsScene.SceneLayer') -> 'QGraphicsScene.SceneLayers': ... + def __rxor__(self, other: 'QGraphicsScene.SceneLayer') -> 'QGraphicsScene.SceneLayers': ... @typing.overload def __init__(self, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... @@ -5747,8 +5961,8 @@ class QGraphicsScene(QtCore.QObject): def __init__(self, x: float, y: float, width: float, height: float, parent: typing.Optional[QtCore.QObject] = ...) -> None: ... def setFocusOnTouch(self, enabled: bool) -> None: ... - focusOnTouch: typing.ClassVar[QtCore.pyqtSignal] - def focusItemChanged(self, newFocus: QGraphicsItem, oldFocus: QGraphicsItem, reason: QtCore.Qt.FocusReason) -> None: ... + def focusOnTouch(self) -> bool: ... + focusItemChanged: typing.ClassVar[QtCore.pyqtSignal] def setMinimumRenderSize(self, minSize: float) -> None: ... def minimumRenderSize(self) -> float: ... def sendEvent(self, item: QGraphicsItem, event: QtCore.QEvent) -> bool: ... @@ -5991,7 +6205,7 @@ class QGraphicsScale(QGraphicsTransform): yScaleChanged: typing.ClassVar[QtCore.pyqtSignal] xScaleChanged: typing.ClassVar[QtCore.pyqtSignal] scaleChanged: typing.ClassVar[QtCore.pyqtSignal] - def originChanged(self) -> None: ... + originChanged: typing.ClassVar[QtCore.pyqtSignal] def applyTo(self, matrix: QtGui.QMatrix4x4) -> None: ... def setZScale(self, a0: float) -> None: ... def zScale(self) -> float: ... @@ -6025,6 +6239,9 @@ class QGraphicsRotation(QGraphicsTransform): class QGraphicsView(QAbstractScrollArea): class OptimizationFlag(int): + def __or__ (self, other: 'QGraphicsView.OptimizationFlag') -> 'QGraphicsView.OptimizationFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGraphicsView.OptimizationFlags': ... # type: ignore[override, misc] + DontClipPainter = ... # type: QGraphicsView.OptimizationFlag DontSavePainterState = ... # type: QGraphicsView.OptimizationFlag DontAdjustForAntialiasing = ... # type: QGraphicsView.OptimizationFlag @@ -6065,6 +6282,9 @@ class QGraphicsView(QAbstractScrollArea): RubberBandDrag = ... # type: QGraphicsView.DragMode class CacheModeFlag(int): + def __or__ (self, other: 'QGraphicsView.CacheModeFlag') -> 'QGraphicsView.CacheMode': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QGraphicsView.CacheMode': ... # type: ignore[override, misc] + CacheNone = ... # type: QGraphicsView.CacheModeFlag CacheBackground = ... # type: QGraphicsView.CacheModeFlag @@ -6079,12 +6299,20 @@ class QGraphicsView(QAbstractScrollArea): def __init__(self, f: typing.Union['QGraphicsView.CacheMode', 'QGraphicsView.CacheModeFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QGraphicsView.CacheMode') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGraphicsView.CacheMode': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGraphicsView.CacheMode', 'QGraphicsView.CacheModeFlag', int]) -> 'QGraphicsView.CacheMode': ... + def __and__(self, other: typing.Union['QGraphicsView.CacheMode', 'QGraphicsView.CacheModeFlag', int]) -> 'QGraphicsView.CacheMode': ... + def __xor__(self, other: typing.Union['QGraphicsView.CacheMode', 'QGraphicsView.CacheModeFlag', int]) -> 'QGraphicsView.CacheMode': ... + def __ror__ (self, other: 'QGraphicsView.CacheModeFlag') -> 'QGraphicsView.CacheMode': ... + def __rand__(self, other: 'QGraphicsView.CacheModeFlag') -> 'QGraphicsView.CacheMode': ... + def __rxor__(self, other: 'QGraphicsView.CacheModeFlag') -> 'QGraphicsView.CacheMode': ... class OptimizationFlags(sip.simplewrapper): @@ -6094,12 +6322,20 @@ class QGraphicsView(QAbstractScrollArea): def __init__(self, f: typing.Union['QGraphicsView.OptimizationFlags', 'QGraphicsView.OptimizationFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QGraphicsView.OptimizationFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QGraphicsView.OptimizationFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QGraphicsView.OptimizationFlags', 'QGraphicsView.OptimizationFlag', int]) -> 'QGraphicsView.OptimizationFlags': ... + def __and__(self, other: typing.Union['QGraphicsView.OptimizationFlags', 'QGraphicsView.OptimizationFlag', int]) -> 'QGraphicsView.OptimizationFlags': ... + def __xor__(self, other: typing.Union['QGraphicsView.OptimizationFlags', 'QGraphicsView.OptimizationFlag', int]) -> 'QGraphicsView.OptimizationFlags': ... + def __ror__ (self, other: 'QGraphicsView.OptimizationFlag') -> 'QGraphicsView.OptimizationFlags': ... + def __rand__(self, other: 'QGraphicsView.OptimizationFlag') -> 'QGraphicsView.OptimizationFlags': ... + def __rxor__(self, other: 'QGraphicsView.OptimizationFlag') -> 'QGraphicsView.OptimizationFlags': ... @typing.overload def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -6482,6 +6718,9 @@ class QInputDialog(QDialog): DoubleInput = ... # type: QInputDialog.InputMode class InputDialogOption(int): + def __or__ (self, other: 'QInputDialog.InputDialogOption') -> 'QInputDialog.InputDialogOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QInputDialog.InputDialogOptions': ... # type: ignore[override, misc] + NoButtons = ... # type: QInputDialog.InputDialogOption UseListViewForComboBoxItems = ... # type: QInputDialog.InputDialogOption UsePlainTextEditForTextInput = ... # type: QInputDialog.InputDialogOption @@ -6498,12 +6737,20 @@ class QInputDialog(QDialog): def __init__(self, f: typing.Union['QInputDialog.InputDialogOptions', 'QInputDialog.InputDialogOption']) -> None: ... @typing.overload def __init__(self, a0: 'QInputDialog.InputDialogOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QInputDialog.InputDialogOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QInputDialog.InputDialogOptions', 'QInputDialog.InputDialogOption', int]) -> 'QInputDialog.InputDialogOptions': ... + def __and__(self, other: typing.Union['QInputDialog.InputDialogOptions', 'QInputDialog.InputDialogOption', int]) -> 'QInputDialog.InputDialogOptions': ... + def __xor__(self, other: typing.Union['QInputDialog.InputDialogOptions', 'QInputDialog.InputDialogOption', int]) -> 'QInputDialog.InputDialogOptions': ... + def __ror__ (self, other: 'QInputDialog.InputDialogOption') -> 'QInputDialog.InputDialogOptions': ... + def __rand__(self, other: 'QInputDialog.InputDialogOption') -> 'QInputDialog.InputDialogOptions': ... + def __rxor__(self, other: 'QInputDialog.InputDialogOption') -> 'QInputDialog.InputDialogOptions': ... def __init__(self, parent: typing.Optional[QWidget] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> None: ... @@ -6839,7 +7086,7 @@ class QLineEdit(QWidget): @typing.overload def __init__(self, contents: str, parent: typing.Optional[QWidget] = ...) -> None: ... - def inputRejected(self) -> None: ... + inputRejected: typing.ClassVar[QtCore.pyqtSignal] def selectionLength(self) -> int: ... def selectionEnd(self) -> int: ... @typing.overload @@ -6900,7 +7147,7 @@ class QLineEdit(QWidget): def undo(self) -> None: ... def selectAll(self) -> None: ... def clear(self) -> None: ... - def setText(self, a0: str) -> None: ... + def setText(self, a0: typing.Optional[str]) -> None: ... def hasAcceptableInput(self) -> bool: ... def setInputMask(self, inputMask: str) -> None: ... def inputMask(self) -> str: ... @@ -7111,15 +7358,15 @@ class QListWidget(QListView): def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... - def isPersistentEditorOpen(self, item: QListWidgetItem) -> bool: ... # type: ignore[override] + def isPersistentEditorOpen(self, item: typing.Optional[QListWidgetItem]) -> bool: ... # type: ignore[override] def setSelectionModel(self, selectionModel: QtCore.QItemSelectionModel) -> None: ... - def removeItemWidget(self, aItem: QListWidgetItem) -> None: ... + def removeItemWidget(self, aItem: typing.Optional[QListWidgetItem]) -> None: ... def dropEvent(self, event: QtGui.QDropEvent) -> None: ... def isSortingEnabled(self) -> bool: ... def setSortingEnabled(self, enable: bool) -> None: ... def event(self, e: QtCore.QEvent) -> bool: ... - def itemFromIndex(self, index: QtCore.QModelIndex) -> QListWidgetItem: ... - def indexFromItem(self, item: QListWidgetItem) -> QtCore.QModelIndex: ... + def itemFromIndex(self, index: QtCore.QModelIndex) -> typing.Optional[QListWidgetItem]: ... + def indexFromItem(self, item: typing.Optional[QListWidgetItem]) -> QtCore.QModelIndex: ... def items(self, data: QtCore.QMimeData) -> typing.List[QListWidgetItem]: ... def supportedDropActions(self) -> QtCore.Qt.DropActions: ... def dropMimeData(self, index: int, data: QtCore.QMimeData, action: QtCore.Qt.DropAction) -> bool: ... @@ -7135,51 +7382,54 @@ class QListWidget(QListView): itemDoubleClicked: typing.ClassVar[QtCore.pyqtSignal] itemClicked: typing.ClassVar[QtCore.pyqtSignal] itemPressed: typing.ClassVar[QtCore.pyqtSignal] - def scrollToItem(self, item: QListWidgetItem, hint: QAbstractItemView.ScrollHint = ...) -> None: ... + def scrollToItem(self, item: typing.Optional[QListWidgetItem], hint: QAbstractItemView.ScrollHint = ...) -> None: ... def clear(self) -> None: ... def findItems(self, text: str, flags: typing.Union[QtCore.Qt.MatchFlags, QtCore.Qt.MatchFlag]) -> typing.List[QListWidgetItem]: ... def selectedItems(self) -> typing.List[QListWidgetItem]: ... - def closePersistentEditor(self, item: QListWidgetItem) -> None: ... # type: ignore[override] - def openPersistentEditor(self, item: QListWidgetItem) -> None: ... # type: ignore[override] - def editItem(self, item: QListWidgetItem) -> None: ... + def closePersistentEditor(self, item: typing.Optional[QListWidgetItem]) -> None: ... # type: ignore[override] + def openPersistentEditor(self, item: typing.Optional[QListWidgetItem]) -> None: ... # type: ignore[override] + def editItem(self, item: typing.Optional[QListWidgetItem]) -> None: ... def sortItems(self, order: QtCore.Qt.SortOrder = ...) -> None: ... - def visualItemRect(self, item: QListWidgetItem) -> QtCore.QRect: ... - def setItemWidget(self, item: QListWidgetItem, widget: QWidget) -> None: ... - def itemWidget(self, item: QListWidgetItem) -> QWidget: ... + def visualItemRect(self, item: typing.Optional[QListWidgetItem]) -> QtCore.QRect: ... + def setItemWidget(self, item: typing.Optional[QListWidgetItem], widget: QWidget) -> None: ... + def itemWidget(self, item: typing.Optional[QListWidgetItem]) -> QWidget: ... @typing.overload - def itemAt(self, p: QtCore.QPoint) -> QListWidgetItem: ... + def itemAt(self, p: QtCore.QPoint) -> typing.Optional[QListWidgetItem]: ... @typing.overload - def itemAt(self, ax: int, ay: int) -> QListWidgetItem: ... + def itemAt(self, ax: int, ay: int) -> typing.Optional[QListWidgetItem]: ... @typing.overload def setCurrentRow(self, row: int) -> None: ... @typing.overload def setCurrentRow(self, row: int, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... def currentRow(self) -> int: ... @typing.overload - def setCurrentItem(self, item: QListWidgetItem) -> None: ... + def setCurrentItem(self, item: typing.Optional[QListWidgetItem]) -> None: ... @typing.overload - def setCurrentItem(self, item: QListWidgetItem, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... - def currentItem(self) -> QListWidgetItem: ... + def setCurrentItem(self, item: typing.Optional[QListWidgetItem], command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... + def currentItem(self) -> typing.Optional[QListWidgetItem]: ... def __len__(self) -> int: ... def count(self) -> int: ... - def takeItem(self, row: int) -> QListWidgetItem: ... - def addItems(self, labels: typing.Iterable[str]) -> None: ... + def takeItem(self, row: int) -> typing.Optional[QListWidgetItem]: ... + def addItems(self, labels: typing.Iterable[typing.Optional[str]]) -> None: ... @typing.overload - def addItem(self, aitem: QListWidgetItem) -> None: ... + def addItem(self, aitem: typing.Optional[QListWidgetItem]) -> None: ... @typing.overload - def addItem(self, label: str) -> None: ... + def addItem(self, label: typing.Optional[str]) -> None: ... def insertItems(self, row: int, labels: typing.Iterable[str]) -> None: ... @typing.overload - def insertItem(self, row: int, item: QListWidgetItem) -> None: ... + def insertItem(self, row: int, item: typing.Optional[QListWidgetItem]) -> None: ... @typing.overload def insertItem(self, row: int, label: str) -> None: ... - def row(self, item: QListWidgetItem) -> int: ... - def item(self, row: int) -> QListWidgetItem: ... + def row(self, item: typing.Optional[QListWidgetItem]) -> int: ... + def item(self, row: int) -> typing.Optional[QListWidgetItem]: ... class QMainWindow(QWidget): class DockOption(int): + def __or__ (self, other: 'QMainWindow.DockOption') -> 'QMainWindow.DockOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QMainWindow.DockOptions': ... # type: ignore[override, misc] + AnimatedDocks = ... # type: QMainWindow.DockOption AllowNestedDocks = ... # type: QMainWindow.DockOption AllowTabbedDocks = ... # type: QMainWindow.DockOption @@ -7202,12 +7452,20 @@ class QMainWindow(QWidget): def __init__(self, f: typing.Union['QMainWindow.DockOptions', 'QMainWindow.DockOption']) -> None: ... @typing.overload def __init__(self, a0: 'QMainWindow.DockOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QMainWindow.DockOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QMainWindow.DockOptions', 'QMainWindow.DockOption', int]) -> 'QMainWindow.DockOptions': ... + def __and__(self, other: typing.Union['QMainWindow.DockOptions', 'QMainWindow.DockOption', int]) -> 'QMainWindow.DockOptions': ... + def __xor__(self, other: typing.Union['QMainWindow.DockOptions', 'QMainWindow.DockOption', int]) -> 'QMainWindow.DockOptions': ... + def __ror__ (self, other: 'QMainWindow.DockOption') -> 'QMainWindow.DockOptions': ... + def __rand__(self, other: 'QMainWindow.DockOption') -> 'QMainWindow.DockOptions': ... + def __rxor__(self, other: 'QMainWindow.DockOption') -> 'QMainWindow.DockOptions': ... def __init__(self, parent: typing.Optional[QWidget] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> None: ... @@ -7294,6 +7552,9 @@ class QMdiArea(QAbstractScrollArea): TabbedView = ... # type: QMdiArea.ViewMode class AreaOption(int): + def __or__ (self, other: 'QMdiArea.AreaOption') -> 'QMdiArea.AreaOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QMdiArea.AreaOptions': ... # type: ignore[override, misc] + DontMaximizeSubWindowOnActivation = ... # type: QMdiArea.AreaOption DontMaximizeSubWindowOnActivation = ... # type: QMdiArea.AreaOption @@ -7306,12 +7567,20 @@ class QMdiArea(QAbstractScrollArea): def __init__(self, f: typing.Union['QMdiArea.AreaOptions', 'QMdiArea.AreaOption']) -> None: ... @typing.overload def __init__(self, a0: 'QMdiArea.AreaOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QMdiArea.AreaOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QMdiArea.AreaOptions', 'QMdiArea.AreaOption', int]) -> 'QMdiArea.AreaOptions': ... + def __and__(self, other: typing.Union['QMdiArea.AreaOptions', 'QMdiArea.AreaOption', int]) -> 'QMdiArea.AreaOptions': ... + def __xor__(self, other: typing.Union['QMdiArea.AreaOptions', 'QMdiArea.AreaOption', int]) -> 'QMdiArea.AreaOptions': ... + def __ror__ (self, other: 'QMdiArea.AreaOption') -> 'QMdiArea.AreaOptions': ... + def __rand__(self, other: 'QMdiArea.AreaOption') -> 'QMdiArea.AreaOptions': ... + def __rxor__(self, other: 'QMdiArea.AreaOption') -> 'QMdiArea.AreaOptions': ... def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -7363,6 +7632,9 @@ class QMdiArea(QAbstractScrollArea): class QMdiSubWindow(QWidget): class SubWindowOption(int): + def __or__ (self, other: 'QMdiSubWindow.SubWindowOption') -> 'QMdiSubWindow.SubWindowOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QMdiSubWindow.SubWindowOptions': ... # type: ignore[override, misc] + RubberBandResize = ... # type: QMdiSubWindow.SubWindowOption RubberBandMove = ... # type: QMdiSubWindow.SubWindowOption @@ -7377,12 +7649,20 @@ class QMdiSubWindow(QWidget): def __init__(self, f: typing.Union['QMdiSubWindow.SubWindowOptions', 'QMdiSubWindow.SubWindowOption']) -> None: ... @typing.overload def __init__(self, a0: 'QMdiSubWindow.SubWindowOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QMdiSubWindow.SubWindowOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QMdiSubWindow.SubWindowOptions', 'QMdiSubWindow.SubWindowOption', int]) -> 'QMdiSubWindow.SubWindowOptions': ... + def __and__(self, other: typing.Union['QMdiSubWindow.SubWindowOptions', 'QMdiSubWindow.SubWindowOption', int]) -> 'QMdiSubWindow.SubWindowOptions': ... + def __xor__(self, other: typing.Union['QMdiSubWindow.SubWindowOptions', 'QMdiSubWindow.SubWindowOption', int]) -> 'QMdiSubWindow.SubWindowOptions': ... + def __ror__ (self, other: 'QMdiSubWindow.SubWindowOption') -> 'QMdiSubWindow.SubWindowOptions': ... + def __rand__(self, other: 'QMdiSubWindow.SubWindowOption') -> 'QMdiSubWindow.SubWindowOptions': ... + def __rxor__(self, other: 'QMdiSubWindow.SubWindowOption') -> 'QMdiSubWindow.SubWindowOptions': ... def __init__(self, parent: typing.Optional[QWidget] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> None: ... @@ -7580,11 +7860,10 @@ class QMenuBar(QWidget): class QMessageBox(QDialog): class StandardButton(int): - @typing.overload # type: ignore[override] - def __or__(self, other: typing.Union['QMessageBox.StandardButton', 'QMessageBox.StandardButtons']) -> 'QMessageBox.StandardButtons': ... # type: ignore[misc] - @typing.overload - def __or__(self, other: int) -> int: ... + def __or__ (self, other: 'QMessageBox.StandardButton') -> 'QMessageBox.StandardButtons': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QMessageBox.StandardButtons': ... # type: ignore[override, misc] + NoButton = ... # type: 'QMessageBox.StandardButton' Ok = ... # type: 'QMessageBox.StandardButton' Save = ... # type: 'QMessageBox.StandardButton' @@ -7685,13 +7964,20 @@ class QMessageBox(QDialog): def __init__(self, f: typing.Union['QMessageBox.StandardButtons', 'QMessageBox.StandardButton']) -> None: ... @typing.overload def __init__(self, a0: 'QMessageBox.StandardButtons') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QMessageBox.StandardButtons': ... def __index__(self) -> int: ... def __int__(self) -> int: ... - def __or__(self, other: typing.Union[int, 'QMessageBox.StandardButtons', 'QMessageBox.StandardButton']) -> 'QMessageBox.StandardButtons': ... + def __or__ (self, other: typing.Union['QMessageBox.StandardButtons', 'QMessageBox.StandardButton', int]) -> 'QMessageBox.StandardButtons': ... + def __and__(self, other: typing.Union['QMessageBox.StandardButtons', 'QMessageBox.StandardButton', int]) -> 'QMessageBox.StandardButtons': ... + def __xor__(self, other: typing.Union['QMessageBox.StandardButtons', 'QMessageBox.StandardButton', int]) -> 'QMessageBox.StandardButtons': ... + def __ror__ (self, other: 'QMessageBox.StandardButton') -> 'QMessageBox.StandardButtons': ... + def __rand__(self, other: 'QMessageBox.StandardButton') -> 'QMessageBox.StandardButtons': ... + def __rxor__(self, other: 'QMessageBox.StandardButton') -> 'QMessageBox.StandardButtons': ... @typing.overload def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -7702,7 +7988,7 @@ class QMessageBox(QDialog): def setCheckBox(self, cb: QCheckBox) -> None: ... def textInteractionFlags(self) -> QtCore.Qt.TextInteractionFlags: ... def setTextInteractionFlags(self, flags: typing.Union[QtCore.Qt.TextInteractionFlags, QtCore.Qt.TextInteractionFlag]) -> None: ... - def buttonClicked(self, button: QAbstractButton) -> None: ... + buttonClicked: typing.ClassVar[QtCore.pyqtSignal] def buttonRole(self, button: QAbstractButton) -> 'QMessageBox.ButtonRole': ... def buttons(self) -> typing.List[QAbstractButton]: ... @typing.overload @@ -8386,6 +8672,9 @@ class QSizeGrip(QWidget): class QSizePolicy(sip.simplewrapper): class ControlType(int): + def __or__ (self, other: 'QSizePolicy.ControlType') -> 'QSizePolicy.ControlTypes': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QSizePolicy.ControlTypes': ... # type: ignore[override, misc] + DefaultType = ... # type: QSizePolicy.ControlType ButtonBox = ... # type: QSizePolicy.ControlType CheckBox = ... # type: QSizePolicy.ControlType @@ -8454,12 +8743,20 @@ class QSizePolicy(sip.simplewrapper): def __init__(self, f: typing.Union['QSizePolicy.ControlTypes', 'QSizePolicy.ControlType']) -> None: ... @typing.overload def __init__(self, a0: 'QSizePolicy.ControlTypes') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QSizePolicy.ControlTypes': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QSizePolicy.ControlTypes', 'QSizePolicy.ControlType', int]) -> 'QSizePolicy.ControlTypes': ... + def __and__(self, other: typing.Union['QSizePolicy.ControlTypes', 'QSizePolicy.ControlType', int]) -> 'QSizePolicy.ControlTypes': ... + def __xor__(self, other: typing.Union['QSizePolicy.ControlTypes', 'QSizePolicy.ControlType', int]) -> 'QSizePolicy.ControlTypes': ... + def __ror__ (self, other: 'QSizePolicy.ControlType') -> 'QSizePolicy.ControlTypes': ... + def __rand__(self, other: 'QSizePolicy.ControlType') -> 'QSizePolicy.ControlTypes': ... + def __rxor__(self, other: 'QSizePolicy.ControlType') -> 'QSizePolicy.ControlTypes': ... @typing.overload def __init__(self) -> None: ... @@ -8536,7 +8833,7 @@ class QSpinBox(QAbstractSpinBox): def stepType(self) -> QAbstractSpinBox.StepType: ... def setDisplayIntegerBase(self, base: int) -> None: ... def displayIntegerBase(self) -> int: ... - def textChanged(self, a0: str) -> None: ... + textChanged: typing.ClassVar[QtCore.pyqtSignal] valueChanged: typing.ClassVar[QtCore.pyqtSignal] def setValue(self, val: int) -> None: ... def event(self, e: QtCore.QEvent) -> bool: ... @@ -8565,7 +8862,7 @@ class QDoubleSpinBox(QAbstractSpinBox): def setStepType(self, stepType: QAbstractSpinBox.StepType) -> None: ... def stepType(self) -> QAbstractSpinBox.StepType: ... - def textChanged(self, a0: str) -> None: ... + textChanged: typing.ClassVar[QtCore.pyqtSignal] valueChanged: typing.ClassVar[QtCore.pyqtSignal] def setValue(self, val: float) -> None: ... def fixup(self, str: str) -> str: ... @@ -8897,6 +9194,9 @@ class QStyleOptionFocusRect(QStyleOption): class QStyleOptionFrame(QStyleOption): class FrameFeature(int): + def __or__ (self, other: 'QStyleOptionFrame.FrameFeature') -> 'QStyleOptionFrame.FrameFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QStyleOptionFrame.FrameFeatures': ... # type: ignore[override, misc] + None_ = ... # type: QStyleOptionFrame.FrameFeature Flat = ... # type: QStyleOptionFrame.FrameFeature Rounded = ... # type: QStyleOptionFrame.FrameFeature @@ -8923,12 +9223,20 @@ class QStyleOptionFrame(QStyleOption): def __init__(self, f: typing.Union['QStyleOptionFrame.FrameFeatures', 'QStyleOptionFrame.FrameFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QStyleOptionFrame.FrameFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStyleOptionFrame.FrameFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStyleOptionFrame.FrameFeatures', 'QStyleOptionFrame.FrameFeature', int]) -> 'QStyleOptionFrame.FrameFeatures': ... + def __and__(self, other: typing.Union['QStyleOptionFrame.FrameFeatures', 'QStyleOptionFrame.FrameFeature', int]) -> 'QStyleOptionFrame.FrameFeatures': ... + def __xor__(self, other: typing.Union['QStyleOptionFrame.FrameFeatures', 'QStyleOptionFrame.FrameFeature', int]) -> 'QStyleOptionFrame.FrameFeatures': ... + def __ror__ (self, other: 'QStyleOptionFrame.FrameFeature') -> 'QStyleOptionFrame.FrameFeatures': ... + def __rand__(self, other: 'QStyleOptionFrame.FrameFeature') -> 'QStyleOptionFrame.FrameFeatures': ... + def __rxor__(self, other: 'QStyleOptionFrame.FrameFeature') -> 'QStyleOptionFrame.FrameFeatures': ... features = ... # type: typing.Union['QStyleOptionFrame.FrameFeatures', 'QStyleOptionFrame.FrameFeature'] frameShape = ... # type: QFrame.Shape @@ -9053,6 +9361,9 @@ class QStyleOptionHeader(QStyleOption): class QStyleOptionButton(QStyleOption): class ButtonFeature(int): + def __or__ (self, other: 'QStyleOptionButton.ButtonFeature') -> 'QStyleOptionButton.ButtonFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QStyleOptionButton.ButtonFeatures': ... # type: ignore[override, misc] + None_ = ... # type: QStyleOptionButton.ButtonFeature Flat = ... # type: QStyleOptionButton.ButtonFeature HasMenu = ... # type: QStyleOptionButton.ButtonFeature @@ -9085,12 +9396,20 @@ class QStyleOptionButton(QStyleOption): def __init__(self, f: typing.Union['QStyleOptionButton.ButtonFeatures', 'QStyleOptionButton.ButtonFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QStyleOptionButton.ButtonFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStyleOptionButton.ButtonFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStyleOptionButton.ButtonFeatures', 'QStyleOptionButton.ButtonFeature', int]) -> 'QStyleOptionButton.ButtonFeatures': ... + def __and__(self, other: typing.Union['QStyleOptionButton.ButtonFeatures', 'QStyleOptionButton.ButtonFeature', int]) -> 'QStyleOptionButton.ButtonFeatures': ... + def __xor__(self, other: typing.Union['QStyleOptionButton.ButtonFeatures', 'QStyleOptionButton.ButtonFeature', int]) -> 'QStyleOptionButton.ButtonFeatures': ... + def __ror__ (self, other: 'QStyleOptionButton.ButtonFeature') -> 'QStyleOptionButton.ButtonFeatures': ... + def __rand__(self, other: 'QStyleOptionButton.ButtonFeature') -> 'QStyleOptionButton.ButtonFeatures': ... + def __rxor__(self, other: 'QStyleOptionButton.ButtonFeature') -> 'QStyleOptionButton.ButtonFeatures': ... features = ... # type: typing.Union['QStyleOptionButton.ButtonFeatures', 'QStyleOptionButton.ButtonFeature'] icon = ... # type: QtGui.QIcon @@ -9113,6 +9432,9 @@ class QStyleOptionTab(QStyleOption): HasFrame = ... # type: QStyleOptionTab.TabFeature class CornerWidget(int): + def __or__ (self, other: 'QStyleOptionTab.CornerWidget') -> 'QStyleOptionTab.CornerWidgets': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QStyleOptionTab.CornerWidgets': ... # type: ignore[override, misc] + NoCornerWidgets = ... # type: QStyleOptionTab.CornerWidget LeftCornerWidget = ... # type: QStyleOptionTab.CornerWidget RightCornerWidget = ... # type: QStyleOptionTab.CornerWidget @@ -9159,12 +9481,20 @@ class QStyleOptionTab(QStyleOption): def __init__(self, f: typing.Union['QStyleOptionTab.CornerWidgets', 'QStyleOptionTab.CornerWidget']) -> None: ... @typing.overload def __init__(self, a0: 'QStyleOptionTab.CornerWidgets') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStyleOptionTab.CornerWidgets': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStyleOptionTab.CornerWidgets', 'QStyleOptionTab.CornerWidget', int]) -> 'QStyleOptionTab.CornerWidgets': ... + def __and__(self, other: typing.Union['QStyleOptionTab.CornerWidgets', 'QStyleOptionTab.CornerWidget', int]) -> 'QStyleOptionTab.CornerWidgets': ... + def __xor__(self, other: typing.Union['QStyleOptionTab.CornerWidgets', 'QStyleOptionTab.CornerWidget', int]) -> 'QStyleOptionTab.CornerWidgets': ... + def __ror__ (self, other: 'QStyleOptionTab.CornerWidget') -> 'QStyleOptionTab.CornerWidgets': ... + def __rand__(self, other: 'QStyleOptionTab.CornerWidget') -> 'QStyleOptionTab.CornerWidgets': ... + def __rxor__(self, other: 'QStyleOptionTab.CornerWidget') -> 'QStyleOptionTab.CornerWidgets': ... class TabFeatures(sip.simplewrapper): @@ -9174,12 +9504,20 @@ class QStyleOptionTab(QStyleOption): def __init__(self, f: typing.Union['QStyleOptionTab.TabFeatures', 'QStyleOptionTab.TabFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QStyleOptionTab.TabFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStyleOptionTab.TabFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStyleOptionTab.TabFeatures', 'QStyleOptionTab.TabFeature', int]) -> 'QStyleOptionTab.TabFeatures': ... + def __and__(self, other: typing.Union['QStyleOptionTab.TabFeatures', 'QStyleOptionTab.TabFeature', int]) -> 'QStyleOptionTab.TabFeatures': ... + def __xor__(self, other: typing.Union['QStyleOptionTab.TabFeatures', 'QStyleOptionTab.TabFeature', int]) -> 'QStyleOptionTab.TabFeatures': ... + def __ror__ (self, other: 'QStyleOptionTab.TabFeature') -> 'QStyleOptionTab.TabFeatures': ... + def __rand__(self, other: 'QStyleOptionTab.TabFeature') -> 'QStyleOptionTab.TabFeatures': ... + def __rxor__(self, other: 'QStyleOptionTab.TabFeature') -> 'QStyleOptionTab.TabFeatures': ... cornerWidgets = ... # type: typing.Union['QStyleOptionTab.CornerWidgets', 'QStyleOptionTab.CornerWidget'] documentMode = ... # type: bool @@ -9340,6 +9678,9 @@ class QStyleOptionViewItem(QStyleOption): OnlyOne = ... # type: QStyleOptionViewItem.ViewItemPosition class ViewItemFeature(int): + def __or__ (self, other: 'QStyleOptionViewItem.ViewItemFeature') -> 'QStyleOptionViewItem.ViewItemFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QStyleOptionViewItem.ViewItemFeatures': ... # type: ignore[override, misc] + None_ = ... # type: QStyleOptionViewItem.ViewItemFeature WrapText = ... # type: QStyleOptionViewItem.ViewItemFeature Alternate = ... # type: QStyleOptionViewItem.ViewItemFeature @@ -9383,12 +9724,20 @@ class QStyleOptionViewItem(QStyleOption): def __init__(self, f: typing.Union['QStyleOptionViewItem.ViewItemFeatures', 'QStyleOptionViewItem.ViewItemFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QStyleOptionViewItem.ViewItemFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStyleOptionViewItem.ViewItemFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStyleOptionViewItem.ViewItemFeatures', 'QStyleOptionViewItem.ViewItemFeature', int]) -> 'QStyleOptionViewItem.ViewItemFeatures': ... + def __and__(self, other: typing.Union['QStyleOptionViewItem.ViewItemFeatures', 'QStyleOptionViewItem.ViewItemFeature', int]) -> 'QStyleOptionViewItem.ViewItemFeatures': ... + def __xor__(self, other: typing.Union['QStyleOptionViewItem.ViewItemFeatures', 'QStyleOptionViewItem.ViewItemFeature', int]) -> 'QStyleOptionViewItem.ViewItemFeatures': ... + def __ror__ (self, other: 'QStyleOptionViewItem.ViewItemFeature') -> 'QStyleOptionViewItem.ViewItemFeatures': ... + def __rand__(self, other: 'QStyleOptionViewItem.ViewItemFeature') -> 'QStyleOptionViewItem.ViewItemFeatures': ... + def __rxor__(self, other: 'QStyleOptionViewItem.ViewItemFeature') -> 'QStyleOptionViewItem.ViewItemFeatures': ... backgroundBrush = ... # type: typing.Union[QtGui.QBrush, QtGui.QColor, QtCore.Qt.GlobalColor, QtGui.QGradient] checkState = ... # type: QtCore.Qt.CheckState @@ -9554,6 +9903,9 @@ class QStyleOptionSpinBox(QStyleOptionComplex): class QStyleOptionToolButton(QStyleOptionComplex): class ToolButtonFeature(int): + def __or__ (self, other: 'QStyleOptionToolButton.ToolButtonFeature') -> 'QStyleOptionToolButton.ToolButtonFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QStyleOptionToolButton.ToolButtonFeatures': ... # type: ignore[override, misc] + None_ = ... # type: QStyleOptionToolButton.ToolButtonFeature Arrow = ... # type: QStyleOptionToolButton.ToolButtonFeature Menu = ... # type: QStyleOptionToolButton.ToolButtonFeature @@ -9586,12 +9938,20 @@ class QStyleOptionToolButton(QStyleOptionComplex): def __init__(self, f: typing.Union['QStyleOptionToolButton.ToolButtonFeatures', 'QStyleOptionToolButton.ToolButtonFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QStyleOptionToolButton.ToolButtonFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStyleOptionToolButton.ToolButtonFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStyleOptionToolButton.ToolButtonFeatures', 'QStyleOptionToolButton.ToolButtonFeature', int]) -> 'QStyleOptionToolButton.ToolButtonFeatures': ... + def __and__(self, other: typing.Union['QStyleOptionToolButton.ToolButtonFeatures', 'QStyleOptionToolButton.ToolButtonFeature', int]) -> 'QStyleOptionToolButton.ToolButtonFeatures': ... + def __xor__(self, other: typing.Union['QStyleOptionToolButton.ToolButtonFeatures', 'QStyleOptionToolButton.ToolButtonFeature', int]) -> 'QStyleOptionToolButton.ToolButtonFeatures': ... + def __ror__ (self, other: 'QStyleOptionToolButton.ToolButtonFeature') -> 'QStyleOptionToolButton.ToolButtonFeatures': ... + def __rand__(self, other: 'QStyleOptionToolButton.ToolButtonFeature') -> 'QStyleOptionToolButton.ToolButtonFeatures': ... + def __rxor__(self, other: 'QStyleOptionToolButton.ToolButtonFeature') -> 'QStyleOptionToolButton.ToolButtonFeatures': ... arrowType = ... # type: QtCore.Qt.ArrowType features = ... # type: typing.Union['QStyleOptionToolButton.ToolButtonFeatures', 'QStyleOptionToolButton.ToolButtonFeature'] @@ -9709,6 +10069,9 @@ class QStyleHintReturnMask(QStyleHintReturn): class QStyleOptionToolBar(QStyleOption): class ToolBarFeature(int): + def __or__ (self, other: 'QStyleOptionToolBar.ToolBarFeature') -> 'QStyleOptionToolBar.ToolBarFeatures': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QStyleOptionToolBar.ToolBarFeatures': ... # type: ignore[override, misc] + None_ = ... # type: QStyleOptionToolBar.ToolBarFeature Movable = ... # type: QStyleOptionToolBar.ToolBarFeature @@ -9744,12 +10107,20 @@ class QStyleOptionToolBar(QStyleOption): def __init__(self, f: typing.Union['QStyleOptionToolBar.ToolBarFeatures', 'QStyleOptionToolBar.ToolBarFeature']) -> None: ... @typing.overload def __init__(self, a0: 'QStyleOptionToolBar.ToolBarFeatures') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QStyleOptionToolBar.ToolBarFeatures': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QStyleOptionToolBar.ToolBarFeatures', 'QStyleOptionToolBar.ToolBarFeature', int]) -> 'QStyleOptionToolBar.ToolBarFeatures': ... + def __and__(self, other: typing.Union['QStyleOptionToolBar.ToolBarFeatures', 'QStyleOptionToolBar.ToolBarFeature', int]) -> 'QStyleOptionToolBar.ToolBarFeatures': ... + def __xor__(self, other: typing.Union['QStyleOptionToolBar.ToolBarFeatures', 'QStyleOptionToolBar.ToolBarFeature', int]) -> 'QStyleOptionToolBar.ToolBarFeatures': ... + def __ror__ (self, other: 'QStyleOptionToolBar.ToolBarFeature') -> 'QStyleOptionToolBar.ToolBarFeatures': ... + def __rand__(self, other: 'QStyleOptionToolBar.ToolBarFeature') -> 'QStyleOptionToolBar.ToolBarFeatures': ... + def __rxor__(self, other: 'QStyleOptionToolBar.ToolBarFeature') -> 'QStyleOptionToolBar.ToolBarFeatures': ... features = ... # type: typing.Union['QStyleOptionToolBar.ToolBarFeatures', 'QStyleOptionToolBar.ToolBarFeature'] lineWidth = ... # type: int @@ -10217,11 +10588,11 @@ class QTableWidget(QTableView): @typing.overload def __init__(self, rows: int, columns: int, parent: typing.Optional[QWidget] = ...) -> None: ... - def isPersistentEditorOpen(self, item: QTableWidgetItem) -> bool: ... # type: ignore[override] + def isPersistentEditorOpen(self, item: typing.Optional[QTableWidgetItem]) -> bool: ... # type: ignore[override] def dropEvent(self, event: QtGui.QDropEvent) -> None: ... def event(self, e: QtCore.QEvent) -> bool: ... - def itemFromIndex(self, index: QtCore.QModelIndex) -> QTableWidgetItem: ... - def indexFromItem(self, item: QTableWidgetItem) -> QtCore.QModelIndex: ... + def itemFromIndex(self, index: QtCore.QModelIndex) -> typing.Optional[QTableWidgetItem]: ... + def indexFromItem(self, item: typing.Optional[QTableWidgetItem]) -> QtCore.QModelIndex: ... def items(self, data: QtCore.QMimeData) -> typing.List[QTableWidgetItem]: ... def supportedDropActions(self) -> QtCore.Qt.DropActions: ... def dropMimeData(self, row: int, column: int, data: QtCore.QMimeData, action: QtCore.Qt.DropAction) -> bool: ... @@ -10248,14 +10619,14 @@ class QTableWidget(QTableView): def removeRow(self, row: int) -> None: ... def insertColumn(self, column: int) -> None: ... def insertRow(self, row: int) -> None: ... - def scrollToItem(self, item: QTableWidgetItem, hint: QAbstractItemView.ScrollHint = ...) -> None: ... - def setItemPrototype(self, item: QTableWidgetItem) -> None: ... - def itemPrototype(self) -> QTableWidgetItem: ... - def visualItemRect(self, item: QTableWidgetItem) -> QtCore.QRect: ... + def scrollToItem(self, item: typing.Optional[QTableWidgetItem], hint: QAbstractItemView.ScrollHint = ...) -> None: ... + def setItemPrototype(self, item: typing.Optional[QTableWidgetItem]) -> None: ... + def itemPrototype(self) -> typing.Optional[QTableWidgetItem]: ... + def visualItemRect(self, item: typing.Optional[QTableWidgetItem]) -> QtCore.QRect: ... @typing.overload - def itemAt(self, p: QtCore.QPoint) -> QTableWidgetItem: ... + def itemAt(self, p: QtCore.QPoint) -> typing.Optional[QTableWidgetItem]: ... @typing.overload - def itemAt(self, ax: int, ay: int) -> QTableWidgetItem: ... + def itemAt(self, ax: int, ay: int) -> typing.Optional[QTableWidgetItem]: ... def visualColumn(self, logicalColumn: int) -> int: ... def visualRow(self, logicalRow: int) -> int: ... def findItems(self, text: str, flags: typing.Union[QtCore.Qt.MatchFlags, QtCore.Qt.MatchFlag]) -> typing.List[QTableWidgetItem]: ... @@ -10264,10 +10635,10 @@ class QTableWidget(QTableView): def setRangeSelected(self, range: QTableWidgetSelectionRange, select: bool) -> None: ... def removeCellWidget(self, arow: int, acolumn: int) -> None: ... def setCellWidget(self, row: int, column: int, widget: QWidget) -> None: ... - def cellWidget(self, row: int, column: int) -> QWidget: ... - def closePersistentEditor(self, item: QTableWidgetItem) -> None: ... # type: ignore[override] - def openPersistentEditor(self, item: QTableWidgetItem) -> None: ... # type: ignore[override] - def editItem(self, item: QTableWidgetItem) -> None: ... + def cellWidget(self, row: int, column: int) -> typing.List[QWidget]: ... + def closePersistentEditor(self, item: typing.Optional[QTableWidgetItem]) -> None: ... # type: ignore[override] + def openPersistentEditor(self, item: typing.Optional[QTableWidgetItem]) -> None: ... # type: ignore[override] + def editItem(self, item: typing.Optional[QTableWidgetItem]) -> None: ... def isSortingEnabled(self) -> bool: ... def setSortingEnabled(self, enable: bool) -> None: ... def sortItems(self, column: int, order: QtCore.Qt.SortOrder = ...) -> None: ... @@ -10276,25 +10647,25 @@ class QTableWidget(QTableView): @typing.overload def setCurrentCell(self, row: int, column: int, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... @typing.overload - def setCurrentItem(self, item: QTableWidgetItem) -> None: ... + def setCurrentItem(self, item: typing.Optional[QTableWidgetItem]) -> None: ... @typing.overload - def setCurrentItem(self, item: QTableWidgetItem, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... - def currentItem(self) -> QTableWidgetItem: ... + def setCurrentItem(self, item: typing.Optional[QTableWidgetItem], command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... + def currentItem(self) -> typing.Optional[QTableWidgetItem]: ... def currentColumn(self) -> int: ... def currentRow(self) -> int: ... def setHorizontalHeaderLabels(self, labels: typing.Iterable[str]) -> None: ... def setVerticalHeaderLabels(self, labels: typing.Iterable[str]) -> None: ... - def takeHorizontalHeaderItem(self, column: int) -> QTableWidgetItem: ... - def setHorizontalHeaderItem(self, column: int, item: QTableWidgetItem) -> None: ... - def horizontalHeaderItem(self, column: int) -> QTableWidgetItem: ... - def takeVerticalHeaderItem(self, row: int) -> QTableWidgetItem: ... - def setVerticalHeaderItem(self, row: int, item: QTableWidgetItem) -> None: ... - def verticalHeaderItem(self, row: int) -> QTableWidgetItem: ... - def takeItem(self, row: int, column: int) -> QTableWidgetItem: ... - def setItem(self, row: int, column: int, item: QTableWidgetItem) -> None: ... - def item(self, row: int, column: int) -> QTableWidgetItem: ... - def column(self, item: QTableWidgetItem) -> int: ... - def row(self, item: QTableWidgetItem) -> int: ... + def takeHorizontalHeaderItem(self, column: int) -> typing.Optional[QTableWidgetItem]: ... + def setHorizontalHeaderItem(self, column: int, item: typing.Optional[QTableWidgetItem]) -> None: ... + def horizontalHeaderItem(self, column: int) -> typing.Optional[QTableWidgetItem]: ... + def takeVerticalHeaderItem(self, row: int) -> typing.Optional[QTableWidgetItem]: ... + def setVerticalHeaderItem(self, row: int, item: typing.Optional[QTableWidgetItem]) -> None: ... + def verticalHeaderItem(self, row: int) -> typing.Optional[QTableWidgetItem]: ... + def takeItem(self, row: int, column: int) -> typing.Optional[QTableWidgetItem]: ... + def setItem(self, row: int, column: int, item: typing.Optional[QTableWidgetItem]) -> None: ... + def item(self, row: int, column: int) -> typing.Optional[QTableWidgetItem]: ... + def column(self, item: typing.Optional[QTableWidgetItem]) -> int: ... + def row(self, item: typing.Optional[QTableWidgetItem]) -> int: ... def columnCount(self) -> int: ... def setColumnCount(self, columns: int) -> None: ... def rowCount(self) -> int: ... @@ -10396,6 +10767,9 @@ class QTabWidget(QWidget): class QTextEdit(QAbstractScrollArea): class AutoFormattingFlag(int): + def __or__ (self, other: 'QTextEdit.AutoFormattingFlag') -> 'QTextEdit.AutoFormatting': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTextEdit.AutoFormatting': ... # type: ignore[override, misc] + AutoNone = ... # type: QTextEdit.AutoFormattingFlag AutoBulletList = ... # type: QTextEdit.AutoFormattingFlag AutoAll = ... # type: QTextEdit.AutoFormattingFlag @@ -10433,12 +10807,20 @@ class QTextEdit(QAbstractScrollArea): def __init__(self, f: typing.Union['QTextEdit.AutoFormatting', 'QTextEdit.AutoFormattingFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QTextEdit.AutoFormatting') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTextEdit.AutoFormatting': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTextEdit.AutoFormatting', 'QTextEdit.AutoFormattingFlag', int]) -> 'QTextEdit.AutoFormatting': ... + def __and__(self, other: typing.Union['QTextEdit.AutoFormatting', 'QTextEdit.AutoFormattingFlag', int]) -> 'QTextEdit.AutoFormatting': ... + def __xor__(self, other: typing.Union['QTextEdit.AutoFormatting', 'QTextEdit.AutoFormattingFlag', int]) -> 'QTextEdit.AutoFormatting': ... + def __ror__ (self, other: 'QTextEdit.AutoFormattingFlag') -> 'QTextEdit.AutoFormatting': ... + def __rand__(self, other: 'QTextEdit.AutoFormattingFlag') -> 'QTextEdit.AutoFormatting': ... + def __rxor__(self, other: 'QTextEdit.AutoFormattingFlag') -> 'QTextEdit.AutoFormatting': ... @typing.overload def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... @@ -11001,22 +11383,22 @@ class QTreeWidget(QTreeView): def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... - def isPersistentEditorOpen(self, item: QTreeWidgetItem, column: int = ...) -> bool: ... # type: ignore[override] + def isPersistentEditorOpen(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> bool: ... # type: ignore[override] def setSelectionModel(self, selectionModel: QtCore.QItemSelectionModel) -> None: ... - def removeItemWidget(self, item: QTreeWidgetItem, column: int) -> None: ... - def itemBelow(self, item: QTreeWidgetItem) -> QTreeWidgetItem: ... - def itemAbove(self, item: QTreeWidgetItem) -> QTreeWidgetItem: ... - def setFirstItemColumnSpanned(self, item: QTreeWidgetItem, span: bool) -> None: ... - def isFirstItemColumnSpanned(self, item: QTreeWidgetItem) -> bool: ... + def removeItemWidget(self, item: typing.Optional[QTreeWidgetItem], column: int) -> None: ... + def itemBelow(self, item: typing.Optional[QTreeWidgetItem]) -> typing.Optional[QTreeWidgetItem]: ... + def itemAbove(self, item: typing.Optional[QTreeWidgetItem]) -> typing.Optional[QTreeWidgetItem]: ... + def setFirstItemColumnSpanned(self, item: typing.Optional[QTreeWidgetItem], span: bool) -> None: ... + def isFirstItemColumnSpanned(self, item: typing.Optional[QTreeWidgetItem]) -> bool: ... def setHeaderLabel(self, alabel: str) -> None: ... def invisibleRootItem(self) -> QTreeWidgetItem: ... def dropEvent(self, event: QtGui.QDropEvent) -> None: ... def event(self, e: QtCore.QEvent) -> bool: ... - def itemFromIndex(self, index: QtCore.QModelIndex) -> QTreeWidgetItem: ... - def indexFromItem(self, item: QTreeWidgetItem, column: int = ...) -> QtCore.QModelIndex: ... + def itemFromIndex(self, index: QtCore.QModelIndex) -> typing.Optional[QTreeWidgetItem]: ... + def indexFromItem(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> QtCore.QModelIndex: ... def supportedDropActions(self) -> QtCore.Qt.DropActions: ... - def dropMimeData(self, parent: QTreeWidgetItem, index: int, data: QtCore.QMimeData, action: QtCore.Qt.DropAction) -> bool: ... - def mimeData(self, items: typing.Iterable[QTreeWidgetItem]) -> QtCore.QMimeData: ... + def dropMimeData(self, parent: typing.Optional[QTreeWidgetItem], index: int, data: QtCore.QMimeData, action: QtCore.Qt.DropAction) -> bool: ... + def mimeData(self, items: typing.Iterable[typing.Optional[QTreeWidgetItem]]) -> QtCore.QMimeData: ... def mimeTypes(self) -> typing.List[str]: ... itemSelectionChanged: typing.ClassVar[QtCore.pyqtSignal] currentItemChanged: typing.ClassVar[QtCore.pyqtSignal] @@ -11029,42 +11411,42 @@ class QTreeWidget(QTreeView): itemClicked: typing.ClassVar[QtCore.pyqtSignal] itemPressed: typing.ClassVar[QtCore.pyqtSignal] def clear(self) -> None: ... - def collapseItem(self, item: QTreeWidgetItem) -> None: ... - def expandItem(self, item: QTreeWidgetItem) -> None: ... - def scrollToItem(self, item: QTreeWidgetItem, hint: QAbstractItemView.ScrollHint = ...) -> None: ... + def collapseItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... + def expandItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... + def scrollToItem(self, item: typing.Optional[QTreeWidgetItem], hint: QAbstractItemView.ScrollHint = ...) -> None: ... def findItems(self, text: str, flags: typing.Union[QtCore.Qt.MatchFlags, QtCore.Qt.MatchFlag], column: int = ...) -> typing.List[QTreeWidgetItem]: ... def selectedItems(self) -> typing.List[QTreeWidgetItem]: ... - def setItemWidget(self, item: QTreeWidgetItem, column: int, widget: QWidget) -> None: ... - def itemWidget(self, item: QTreeWidgetItem, column: int) -> QWidget: ... - def closePersistentEditor(self, item: QTreeWidgetItem, column: int = ...) -> None: ... # type: ignore[override] - def openPersistentEditor(self, item: QTreeWidgetItem, column: int = ...) -> None: ... # type: ignore[override] - def editItem(self, item: QTreeWidgetItem, column: int = ...) -> None: ... + def setItemWidget(self, item: typing.Optional[QTreeWidgetItem], column: int, widget: QWidget) -> None: ... + def itemWidget(self, item: typing.Optional[QTreeWidgetItem], column: int) -> QWidget: ... + def closePersistentEditor(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> None: ... # type: ignore[override] + def openPersistentEditor(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> None: ... # type: ignore[override] + def editItem(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> None: ... def sortItems(self, column: int, order: QtCore.Qt.SortOrder) -> None: ... def sortColumn(self) -> int: ... - def visualItemRect(self, item: QTreeWidgetItem) -> QtCore.QRect: ... + def visualItemRect(self, item: typing.Optional[QTreeWidgetItem]) -> QtCore.QRect: ... @typing.overload - def itemAt(self, p: QtCore.QPoint) -> QTreeWidgetItem: ... + def itemAt(self, p: QtCore.QPoint) -> typing.Optional[QTreeWidgetItem]: ... @typing.overload - def itemAt(self, ax: int, ay: int) -> QTreeWidgetItem: ... + def itemAt(self, ax: int, ay: int) -> typing.Optional[QTreeWidgetItem]: ... @typing.overload - def setCurrentItem(self, item: QTreeWidgetItem) -> None: ... + def setCurrentItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... @typing.overload - def setCurrentItem(self, item: QTreeWidgetItem, column: int) -> None: ... + def setCurrentItem(self, item: typing.Optional[QTreeWidgetItem], column: int) -> None: ... @typing.overload - def setCurrentItem(self, item: QTreeWidgetItem, column: int, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... + def setCurrentItem(self, item: typing.Optional[QTreeWidgetItem], column: int, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... def currentColumn(self) -> int: ... - def currentItem(self) -> QTreeWidgetItem: ... + def currentItem(self) -> typing.Optional[QTreeWidgetItem]: ... def setHeaderLabels(self, labels: typing.Iterable[str]) -> None: ... - def setHeaderItem(self, item: QTreeWidgetItem) -> None: ... - def headerItem(self) -> QTreeWidgetItem: ... + def setHeaderItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... + def headerItem(self) -> typing.Optional[QTreeWidgetItem]: ... def addTopLevelItems(self, items: typing.Iterable[QTreeWidgetItem]) -> None: ... def insertTopLevelItems(self, index: int, items: typing.Iterable[QTreeWidgetItem]) -> None: ... - def indexOfTopLevelItem(self, item: QTreeWidgetItem) -> int: ... - def takeTopLevelItem(self, index: int) -> QTreeWidgetItem: ... - def addTopLevelItem(self, item: QTreeWidgetItem) -> None: ... - def insertTopLevelItem(self, index: int, item: QTreeWidgetItem) -> None: ... + def indexOfTopLevelItem(self, item: typing.Optional[QTreeWidgetItem]) -> int: ... + def takeTopLevelItem(self, index: int) -> typing.Optional[QTreeWidgetItem]: ... + def addTopLevelItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... + def insertTopLevelItem(self, index: int, item: typing.Optional[QTreeWidgetItem]) -> None: ... def topLevelItemCount(self) -> int: ... - def topLevelItem(self, index: int) -> QTreeWidgetItem: ... + def topLevelItem(self, index: int) -> typing.Optional[QTreeWidgetItem]: ... def setColumnCount(self, columns: int) -> None: ... def columnCount(self) -> int: ... @@ -11072,6 +11454,9 @@ class QTreeWidget(QTreeView): class QTreeWidgetItemIterator(sip.simplewrapper): class IteratorFlag(int): + def __or__ (self, other: 'QTreeWidgetItemIterator.IteratorFlag') -> 'QTreeWidgetItemIterator.IteratorFlags': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QTreeWidgetItemIterator.IteratorFlags': ... # type: ignore[override, misc] + All = ... # type: QTreeWidgetItemIterator.IteratorFlag Hidden = ... # type: QTreeWidgetItemIterator.IteratorFlag NotHidden = ... # type: QTreeWidgetItemIterator.IteratorFlag @@ -11122,12 +11507,20 @@ class QTreeWidgetItemIterator(sip.simplewrapper): def __init__(self, f: typing.Union['QTreeWidgetItemIterator.IteratorFlags', 'QTreeWidgetItemIterator.IteratorFlag']) -> None: ... @typing.overload def __init__(self, a0: 'QTreeWidgetItemIterator.IteratorFlags') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QTreeWidgetItemIterator.IteratorFlags': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QTreeWidgetItemIterator.IteratorFlags', 'QTreeWidgetItemIterator.IteratorFlag', int]) -> 'QTreeWidgetItemIterator.IteratorFlags': ... + def __and__(self, other: typing.Union['QTreeWidgetItemIterator.IteratorFlags', 'QTreeWidgetItemIterator.IteratorFlag', int]) -> 'QTreeWidgetItemIterator.IteratorFlags': ... + def __xor__(self, other: typing.Union['QTreeWidgetItemIterator.IteratorFlags', 'QTreeWidgetItemIterator.IteratorFlag', int]) -> 'QTreeWidgetItemIterator.IteratorFlags': ... + def __ror__ (self, other: 'QTreeWidgetItemIterator.IteratorFlag') -> 'QTreeWidgetItemIterator.IteratorFlags': ... + def __rand__(self, other: 'QTreeWidgetItemIterator.IteratorFlag') -> 'QTreeWidgetItemIterator.IteratorFlags': ... + def __rxor__(self, other: 'QTreeWidgetItemIterator.IteratorFlag') -> 'QTreeWidgetItemIterator.IteratorFlags': ... @typing.overload def __init__(self, it: 'QTreeWidgetItemIterator') -> None: ... @@ -11279,6 +11672,9 @@ class QWidgetAction(QAction): class QWizard(QDialog): class WizardOption(int): + def __or__ (self, other: 'QWizard.WizardOption') -> 'QWizard.WizardOptions': ... # type: ignore[override] + def __ror__ (self, other: int) -> 'QWizard.WizardOptions': ... # type: ignore[override, misc] + IndependentPages = ... # type: QWizard.WizardOption IgnoreSubTitles = ... # type: QWizard.WizardOption ExtendedWatermarkPixmap = ... # type: QWizard.WizardOption @@ -11368,12 +11764,20 @@ class QWizard(QDialog): def __init__(self, f: typing.Union['QWizard.WizardOptions', 'QWizard.WizardOption']) -> None: ... @typing.overload def __init__(self, a0: 'QWizard.WizardOptions') -> None: ... + @typing.overload + def __init__(self, f: int) -> None: ... def __hash__(self) -> int: ... def __bool__(self) -> int: ... def __invert__(self) -> 'QWizard.WizardOptions': ... def __index__(self) -> int: ... def __int__(self) -> int: ... + def __or__ (self, other: typing.Union['QWizard.WizardOptions', 'QWizard.WizardOption', int]) -> 'QWizard.WizardOptions': ... + def __and__(self, other: typing.Union['QWizard.WizardOptions', 'QWizard.WizardOption', int]) -> 'QWizard.WizardOptions': ... + def __xor__(self, other: typing.Union['QWizard.WizardOptions', 'QWizard.WizardOption', int]) -> 'QWizard.WizardOptions': ... + def __ror__ (self, other: 'QWizard.WizardOption') -> 'QWizard.WizardOptions': ... + def __rand__(self, other: 'QWizard.WizardOption') -> 'QWizard.WizardOptions': ... + def __rxor__(self, other: 'QWizard.WizardOption') -> 'QWizard.WizardOptions': ... def __init__(self, parent: typing.Optional[QWidget] = ..., flags: typing.Union[QtCore.Qt.WindowFlags, QtCore.Qt.WindowType] = ...) -> None: ... diff --git a/PyQt5-stubs/QtX11Extras.pyi b/PyQt5-stubs/QtX11Extras.pyi index 76962d0b..2a6a10b5 100644 --- a/PyQt5-stubs/QtX11Extras.pyi +++ b/PyQt5-stubs/QtX11Extras.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtX11Extras module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # diff --git a/PyQt5-stubs/QtXml.pyi b/PyQt5-stubs/QtXml.pyi index 6c04dfca..f140efa4 100644 --- a/PyQt5-stubs/QtXml.pyi +++ b/PyQt5-stubs/QtXml.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtXml module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # diff --git a/PyQt5-stubs/QtXmlPatterns.pyi b/PyQt5-stubs/QtXmlPatterns.pyi index df7f0f6f..c32185d7 100644 --- a/PyQt5-stubs/QtXmlPatterns.pyi +++ b/PyQt5-stubs/QtXmlPatterns.pyi @@ -1,6 +1,6 @@ # The PEP 484 type hints stub file for the QtXmlPatterns module. # -# Generated by SIP 6.0.2 +# Generated by SIP 6.4.0 # # Copyright (c) 2021 Riverbank Computing Limited # diff --git a/PyQt5-stubs/__init__.pyi b/PyQt5-stubs/__init__.pyi index 919d9b67..968f13c7 100644 --- a/PyQt5-stubs/__init__.pyi +++ b/PyQt5-stubs/__init__.pyi @@ -1 +1 @@ -__version__ = "5.15.3.0" +__version__ = "5.15.6.0" diff --git a/requirements/develop.in b/requirements/develop.in deleted file mode 100644 index 8669f94f..00000000 --- a/requirements/develop.in +++ /dev/null @@ -1,3 +0,0 @@ --r production.txt -mypy -pytest diff --git a/requirements/develop.txt b/requirements/develop.txt deleted file mode 100644 index 24d709ce..00000000 --- a/requirements/develop.txt +++ /dev/null @@ -1,37 +0,0 @@ -# -# This file is autogenerated by pip-compile -# To update, run: -# -# pip-compile --output-file=develop.txt develop.in -# -atomicwrites==1.2.1 - # via pytest -attrs==18.2.0 - # via pytest -more-itertools==4.3.0 - # via pytest -mypy-extensions==0.4.1 - # via mypy -mypy==0.641 - # via -r develop.in -pluggy==0.8.0 - # via pytest -py==1.10.0 - # via pytest -pyqt5-sip==12.7.0 - # via - # -r production.txt - # pyqt5 -pyqt5==5.14.2 - # via -r production.txt -pytest==4.0.1 - # via -r develop.in -six==1.11.0 - # via - # more-itertools - # pytest -typed-ast==1.1.0 - # via mypy - -# The following packages are considered to be unsafe in a requirements file: -# setuptools diff --git a/requirements/production.in b/requirements/production.in deleted file mode 100644 index a5292533..00000000 --- a/requirements/production.in +++ /dev/null @@ -1 +0,0 @@ -PyQt5==5.14.* diff --git a/requirements/production.txt b/requirements/production.txt deleted file mode 100644 index 4d7f38af..00000000 --- a/requirements/production.txt +++ /dev/null @@ -1,8 +0,0 @@ -# -# This file is autogenerated by pip-compile -# To update, run: -# -# pip-compile --output-file=production.txt production.in -# -pyqt5-sip==12.7.0 # via pyqt5 -pyqt5==5.14.2 # via -r production.in diff --git a/setup.py b/setup.py index 6d97f94d..83938fe4 100644 --- a/setup.py +++ b/setup.py @@ -50,8 +50,10 @@ def find_version(*file_paths): python_requires=">= 3.5", package_data={"PyQt5-stubs": ['*.pyi']}, packages=["PyQt5-stubs"], - tests_require=["PyQt5==5.14.*"], - extras_require={"build": ["docker==4.2.0"]}, + extras_require={ + "build": ["docker==4.2.0"], + "dev": ["mypy", "pytest"], + }, classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", diff --git a/signal_fixer.py b/signal_fixer.py new file mode 100644 index 00000000..dbd5cf29 --- /dev/null +++ b/signal_fixer.py @@ -0,0 +1,107 @@ +"""Script that will check stub files and fix signal annotations.""" +import importlib +import os +from types import ModuleType +from typing import List, Optional, Union, cast, Iterable + +import libcst as cst + +from PyQt5 import QtCore + + +def is_signal(module: ModuleType, cls_name: str, func_name: str) -> bool: + """Check if a method of the given Qt class is a signal.""" + if cls_name == "QGeoPositionInfoSource" and func_name == "error": + # this is a fix for the broken error method. + return False + cls = getattr(module, cls_name) + try: + func = getattr(cls, func_name) + except AttributeError: + print(f"Warning! Could not find {cls_name}.{func_name}") + return False + return isinstance(func, QtCore.pyqtSignal) + + +class TypingTransformer(cst.CSTTransformer): + """TypingTransformer that visits classes and methods.""" + + def __init__(self, mod_name: str): + super().__init__() + self._last_class: List[cst.ClassDef] = [] + self._fixed_signals: List[str] = [] + self._module: ModuleType = importlib.import_module(f"PyQt5.{mod_name}") + + def visit_ClassDef(self, node: cst.ClassDef) -> Optional[bool]: + """Put a class on top of the stack when visiting.""" + self._last_class.append(node) + return True + + def leave_FunctionDef( + self, original_node: cst.FunctionDef, _: cst.FunctionDef + ) -> Union[ + cst.BaseStatement, + cst.FlattenSentinel[cst.BaseStatement], + cst.RemovalSentinel, + ]: + """Leave the method and change signature if a signal.""" + if not self._last_class: + return original_node + if len(self._last_class) > 1: + return original_node + + f_name = original_node.name.value + if is_signal(self._module, self._last_class[-1].name.value, f_name): + full_name = f"{self._last_class[-1].name.value}.{f_name}" + if full_name in self._fixed_signals: + # Handle the use-case of overloaded signals, that are defined + # multiple time because of their different signal arguments + # i.e.: QComboBox.highlighted + return cst.RemovalSentinel.REMOVE + self._fixed_signals.append(full_name) + stmt = f"{f_name}: typing.ClassVar[QtCore.pyqtSignal]" + node = cst.parse_statement(stmt) + if original_node.leading_lines: + # Copy the leading lines and return them with a + # FlattenSentinel. Just adding a newline char results in an + # indented EmptyLine which isn't bad but clutters the diff + # unnecessarily + empty_nodes = [ + line.deep_clone() for line in original_node.leading_lines + ] + return cst.FlattenSentinel( + cast(Iterable[cst.BaseStatement], [*empty_nodes, node]) + ) + return node + return original_node + + def leave_ClassDef( + self, original_node: cst.ClassDef, updated_node: cst.ClassDef + ) -> Union[ + cst.BaseStatement, + cst.FlattenSentinel[cst.BaseStatement], + cst.RemovalSentinel, + ]: + """Remove a class from the stack and return the updated node.""" + self._last_class.pop() + return updated_node + + +if __name__ == "__main__": + for file in os.listdir("PyQt5-stubs"): + if file.startswith("QtWebKit") or file in [ + "QtX11Extras.pyi", + "sip.pyi", + "__init__.pyi", + ]: + continue + print("Fixing signals in " + file) + path = os.path.join("PyQt5-stubs", file) + with open(path, "r", encoding="utf-8") as fhandle: + stub_tree = cst.parse_module(fhandle.read()) + + transformer = TypingTransformer(file.replace(".pyi", "")) + modified_tree = stub_tree.visit(transformer) + + with open(path, "w", encoding="utf-8") as fhandle: + fhandle.write(modified_tree.code) diff --git a/stubtest.allowlist.linux b/stubtest.allowlist.linux new file mode 100644 index 00000000..e69de29b diff --git a/stubtest.allowlist.macos b/stubtest.allowlist.macos new file mode 100644 index 00000000..40df1961 --- /dev/null +++ b/stubtest.allowlist.macos @@ -0,0 +1,7 @@ +# Linux only +PyQt5.QtX11Extras + +# To review +PyQt5.QtGui.QDrag.cancel +PyQt5.QtWidgets.QMacCocoaViewContainer +PyQt5.QtWidgets.QMenu.setAsDockMenu diff --git a/stubtest.allowlist.to_review b/stubtest.allowlist.to_review index cd96ad59..fc51be1f 100644 --- a/stubtest.allowlist.to_review +++ b/stubtest.allowlist.to_review @@ -24,3 +24,5 @@ PyQt5.QtTest.QAbstractItemModelTester.FailureReportingMode.__new__ PyQt5.QtWebEngineCore.QWebEngineUrlScheme.Syntax.__new__ PyQt5.QtWebEngineWidgets.QWebEnginePage.LifecycleState.__new__ PyQt5.QtWidgets.QActionGroup.ExclusionPolicy.__new__ +PyQt5.QtCore.pyqtProperty +PyQt5.QtQml.QQmlListProperty diff --git a/stubtest.allowlist.windows b/stubtest.allowlist.windows new file mode 100644 index 00000000..44191d3d --- /dev/null +++ b/stubtest.allowlist.windows @@ -0,0 +1,21 @@ +# stubs which are Windows specific, missing from the stub definition and to be added +PyQt5.QtCore.QWinEventNotifier +PyQt5.QtCore.QAbstractEventDispatcher.registerEventNotifier +PyQt5.QtCore.QAbstractEventDispatcher.unregisterEventNotifier + +# Stubs which are missing because not supported on Windows +PyQt5.QtX11Extras + +# stubs missing because of pyqt5 bugs +PyQt5.QtPrintSupport.QPrinter.printerSelectionOption +PyQt5.QtPrintSupport.QPrinter.setPrinterSelectionOption +PyQt5.QtNetworkAuth.QAbstractOAuth.callback +PyQt5.QtNetworkAuth.QAbstractOAuth.generateRandomString +PyQt5.QtNetworkAuth.QAbstractOAuth.resourceOwnerAuthorization +PyQt5.QtNetworkAuth.QAbstractOAuth.setStatus +PyQt5.QtGui.QPaintDeviceWindow.paintEvent +PyQt5.Qt3DAnimation.QAbstractAnimation.setDuration +PyQt5.Qt3DExtras.QAbstractCameraController.keyboardDevice +PyQt5.Qt3DExtras.QAbstractCameraController.mouseDevice +PyQt5.Qt3DRender.QAbstractTextureImage.dataGenerator +PyQt5.Qt3DRender.QAbstractTextureImage.notifyDataGeneratorChanged diff --git a/tests/qdialogbuttonbox.py b/tests/qdialogbuttonbox.py new file mode 100644 index 00000000..2ab3bd7e --- /dev/null +++ b/tests/qdialogbuttonbox.py @@ -0,0 +1,7 @@ +from PyQt5 import QtWidgets + +a = QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Ok # type: QtWidgets.QDialogButtonBox.StandardButtons +b = QtWidgets.QDialogButtonBox.Ok | 0 # type: int +c = a | 0 # type: QtWidgets.QDialogButtonBox.StandardButtons +d = a | QtWidgets.QDialogButtonBox.Ok # type: QtWidgets.QDialogButtonBox.StandardButtons +e = a | a # type: QtWidgets.QDialogButtonBox.StandardButtons diff --git a/tests/qflags/README_qflags.md b/tests/qflags/README_qflags.md new file mode 100644 index 00000000..16725c22 --- /dev/null +++ b/tests/qflags/README_qflags.md @@ -0,0 +1,76 @@ +# QFlag stubs semi-automatic generation process + +This directory is dedicated to helping with the generation of stubs related to all QFlags used in PyQt5. + +## Overview + +The general idea of the generation is: +* Grep Qt sources, looking for all QFlag based classes and store the result in a text file +* Process the grep text file to identify the QFlag names and their module. Generates a `qflags_modules_analysis.json` +* Using `qflags_modules_analysis.json` , extract the QFlags where the module is cleary identified and put + them into a `qflags_to_process.json` file. +* Process each flag one by one from `qflags_to_process.json` and output a `qflags_process_result.json` . For + each QFlag: + ** verify with code analysis if the QFlag is indeed present in this module + ** check if the stubs for all qflags operation are already present. If yes, stops. + ** if not, add the missing stubs to the module and generate a test file in the form test__.py + ** run `pytest` and `mypy` on the generated test file + ** if successful, stage the changes to git + ** if there is any error in the process, stops. + + +## Details + +To run all the above steps, proceed with the following steps. + + +### Grep the Qt sources + +The command-line to use is: + + qt-src\qt5\qtbase>rg --type-add "headers:*.h" -t headers Q_DECLARE_FLAGS --no-heading > qt-qflag-grep-result.txt + + +### Analyse the QFlags module location + +Run: + + python generate_qflags_stubs_and_tests.py analyse_grep_results qt-qflag-grep-result.txt + +You get two files: + * qflags_modules_analysis.json + * qflags_to_process.json + +With human verification, you can add more QFlags to the `qflags_to_process.json` file. You +can also point the exact full class name for the QFlags in case where this program does +not identify it correctly. The fields `human_hint_qflag_full_class_name` and +`human_hint_enum_full_class_name` are available for this purpose. + +### Generate and test the new stubs + +Run: + python generate_qflags_stubs_and_tests.py gen_qflag_stub 5 --auto-commit + +This will process 5 QFlags from qflags_to_process.json . The result of the processing is: +* the file `qflags_to_process.json` is read to find the list of items to process +* the list is compared with the already processed items in `qflags_process_result.json` + to find the items needing processing. +* the file `qflags_process_result.json` is updated with the results of the processing. +* when the generation and test is successful: + ** the qt module is updated + ** a new test file is added in the format test__.py + ** a git commit with the test file and updated module is performed (only if you specifed --auto-commit) + +To process all qflags: + + python generate_qflags_stubs_and_tests.py gen_qflag_stub all --auto-commit + +## Conclusion + +The process is semi-manual at the moment. The tool will process QFlags in batches and let the user perform +the final git commit and push. + +Note that more intelligence shall be put in the future to handle QFlags with identical names located in +multiple classes or modules. + + diff --git a/tests/qflags/generate_qflags_stubs_and_tests.py b/tests/qflags/generate_qflags_stubs_and_tests.py new file mode 100644 index 00000000..5b11ea95 --- /dev/null +++ b/tests/qflags/generate_qflags_stubs_and_tests.py @@ -0,0 +1,1281 @@ +from typing import List, Tuple, Dict, Union, Any, Optional, cast + +import dataclasses +import functools +import json +import os +import sys +import subprocess +import traceback +from enum import Enum + +from PyQt5 import (QtCore, QtWidgets, QtGui, QtNetwork, QtDBus, QtOpenGL, + QtPrintSupport, QtSql, QtTest, QtXml, + Qt3DAnimation, Qt3DCore, Qt3DExtras, Qt3DInput, Qt3DLogic, Qt3DRender, + QtChart, + QtBluetooth, QtNfc, + QtDataVisualization, + QtQuick, QtQml, + QtPositioning, QtLocation, + QtMultimedia, + QtSerialPort, + QtDesigner, + QtWebEngineWidgets, QtWebEngineCore, + ) +try: + import libcst as cst + import libcst.matchers as matchers +except ImportError: + raise ImportError('You need libcst to run the missing stubs generation\n' + 'Please run the command:\n\tpython -m pip install libcst') + +MODULE_GROUPS = { + 'qtbase': [ + 'QtCore', + 'QtWidgets', + 'QtGui', + 'QtNetwork', + 'QtDBus', + 'QtOpenGL', + 'QtPrintSupport', + 'QtSql', + 'QtTest', + 'QtXml', + ], + 'qt3d': [ + 'Qt3DAnimation', + 'Qt3DCore', + 'Qt3DExtras', + 'Qt3DInput', + 'Qt3DLogic', + 'Qt3DRender', + ], + 'qtchart': [ + 'QtChart', + ], + 'qtconnectivity': [ + 'QtBluetooth', + 'QtNfc', + ], + 'qtdatavisualization': [ + 'QtDataVisualization', + ], + 'qtquick': [ + 'QtQuick', + 'QtQml', + ], + 'qtlocation': [ + 'QtPositioning', + 'QtLocation', + ], + 'qtmultimedia': [ + 'QtMultimedia', + ], + 'qtserialport': [ + 'QtSerialPort', + ], +} + + +USAGE = '''Usage 1: {prog} analyse_grep_results --group + Process the to extract all the qflag location information. + + Generates two output: + - qflags_modules_analysis.json : a general file describing which qflag are suitable for processing + - qflags_to_process.json: a list of qflag ready to process with the next command. + + The is the name of a group of modules to see where to look for for the exact name + of the qflags. Possible modules groups are: + - {groups} + +Usage 2: {prog} gen_qflag_stub (|all) (--auto-commit) + Using file qflag_to_process.json, process qflags and modify the PyQt modules. + The output of this processing is available in qflags_process_result.json + + If is not provided, defaults to 1. If "all" is provied, all qflags + are processed. + + If --auto-commit is specified, a git commit is performed after each successful QFlag validation + +'''.format(prog=sys.argv[0], groups='\n - '.join(MODULE_GROUPS.keys())) + + + +def log_progress(s: str) -> None: + print('>>>>>>>>>>>>>>', s) + +@dataclasses.dataclass +class QFlagLocationInfo: + + # qflag and enum name used in the QDECLARE() grep line + qflag_class: str + enum_class: str + + # sometimes, human help is needed to identify a qflag/enum pair + human_hint_qflag_full_class_name: str = '' + human_hint_enum_full_class_name: str = '' + + # one or more grep lines where this qflag name has been found + grep_line: Tuple[str] = dataclasses.field(default_factory=tuple) + + # full class name (including nesting classes) generated in a second pass + qflag_full_class_name: str = '' + enum_full_class_name: str = '' + enum_value1: str = '' + enum_value2: str = '' + + # number of occurence in this module + module_count: int = 0 + + # index of occurence in this module + module_idx: int = -1 + + # module name and path + module_name: str = '' + module_path: str = '' + + def key(self) -> Tuple[str, str, str]: + '''Mostly unique description of the QFlagInfo''' + return (self.module_name, self.qflag_class, self.enum_class) + + # specific behavior of some QFlag classes varies slightly + # this helps to define the exact behavior + or_converts_to_multi: bool = True + or_int_converts_to_multi: bool = False + int_or_converts_to_multi: bool = True + supports_one_op_multi: bool = True + + +def json_encode_qflaglocationinfo(flag_loc_info: object) -> Union[object, Dict[str, Any]]: + """Encode the QFlagClassLoationInfo into a format suitable for json export (a dict)""" + if not isinstance(flag_loc_info, QFlagLocationInfo): + # oups, we don't know how to encode that + return flag_loc_info + + d = dataclasses.asdict(flag_loc_info) + # when returning the result of the grep analysis, we want only a specific subset + # of the datablass fields + del d["or_converts_to_multi"] + del d["or_int_converts_to_multi"] + del d["int_or_converts_to_multi"] + del d["supports_one_op_multi"] + + return d + + +def identify_qflag_location(fname_grep_result: str, + qt_modules: List[str] + ) -> List[ QFlagLocationInfo ]: + """Parses the grep results to extract each qflag, and then look into all Qt modules + to see where the flag is located. + + Return a list of QFlagLocationInfo indicating in which module the flag has been located. + """ + # the file defining the qflag implementation, to be skipped when performing QDECLARE analysis + QFLAG_SRC = 'src\\corelib\\global\\qflags.h' + + parsed_qflags = {} # type: Dict[ Tuple[str, str], QFlagLocationInfo ] + with open(fname_grep_result) as f: + for l in f.readlines()[:]: + grep_line = l.strip() + if len(grep_line) == 0: + continue + qflag_fname, qflag_declare_stmt = [s.strip(' \t\n') for s in grep_line.split(':')] + if qflag_fname == QFLAG_SRC: + # do not include actual implementation of qflags + continue + assert 'Q_DECLARE_FLAGS' in qflag_declare_stmt + s = qflag_declare_stmt[qflag_declare_stmt.index('(')+1:qflag_declare_stmt.index(')')] + qflag_class, enum_class = [v.strip(' ') for v in s.split(',')] + if (qflag_class, enum_class) in parsed_qflags: + # we already have one similar name in our DB + # just extend the grep line then + parsed_qflags[(qflag_class, enum_class)].grep_line += (grep_line,) + else: + parsed_qflags[(qflag_class, enum_class)] = QFlagLocationInfo(qflag_class, enum_class, grep_line=(grep_line,)) + + # fill up modules with content + qt_modules_content = [ (mod_name, open('../../PyQt5-stubs/%s.pyi' % mod_name, encoding='utf8').read()) + for mod_name in qt_modules] + + # associate a qflag enum/class with a mapping from module to QFlagLocationInfo + module_mapping: Dict[ Tuple[str, str], Dict[str, QFlagLocationInfo]] = {} + flag_not_found = [] + + for qflag_key, flag_info in parsed_qflags.items(): + decl_qflag_class = 'class %s(sip.simplewrapper' % flag_info.qflag_class + decl_qflag_class2 = 'class %s(sip.wrapper' % flag_info.qflag_class + decl_enum_class = 'class %s(int' % flag_info.enum_class + module_found = False + for mod_name, mod_content in qt_modules_content: + + if (decl_qflag_class in mod_content or decl_qflag_class2 in mod_content) \ + and decl_enum_class in mod_content: + # we have found one module + module_found = True + # print('Adding QFlags %s to module %s' % (flag_info.qflag_class, mod_name)) + if qflag_key not in module_mapping: + module_mapping[qflag_key] = {} + else: + pass + mod_map = module_mapping[qflag_key] + + if mod_name in mod_map: + raise ValueError('Not supposed to happen!') + + # register the number of time where this flag happens in this specific module + mod_map[mod_name] = dataclasses.replace(flag_info) # this means a fresh copy of flag_info + mod_map[mod_name].module_count = 1 + + count_qflag_class = mod_content.count(decl_qflag_class) + count_enum_class = mod_content.count(decl_enum_class) + if count_qflag_class > 1 and count_enum_class > 1: + # print('QFlag present more than once, adding it more than once') + mod_map[mod_name].module_count += min(count_qflag_class, count_enum_class) - 1 + + if not module_found: + flag_not_found.append(qflag_key) + + # now, we flatten the structure by recreating one QFlagLocationInfo per module location + + all_qflags: List[QFlagLocationInfo] = [] + for mod_map in module_mapping.values(): + for mod_name, flag_info in mod_map.items(): + idx = 0 + while idx < flag_info.module_count: + all_qflags.append(dataclasses.replace(flag_info, module_idx=idx, + module_name=mod_name, + module_path='../../PyQt5-stubs/%s.pyi' % mod_name)) + idx += 1 + + for qflag_key in flag_not_found: + all_qflags.append(parsed_qflags[qflag_key]) + + return all_qflags + + +def group_qflags(qflag_location: List[QFlagLocationInfo], + qflags_group_initial: Optional[Dict[str, List[QFlagLocationInfo]]]) -> Dict[str, List[QFlagLocationInfo]]: + """Group the QFlags into the following groups (inside a dictionnary): + * flag_and_module_identified: this flag is present once in one module exactly. + * flag_without_module: this flag is not present in any modules at all. + + The first group is suitable for automatic processing. + The last group reflects the QFlags not exported to PyQt or coming from modules not present in PyQt + """ + if not qflags_group_initial: + qflags_group_initial = { + 'flag_and_module_identified': [], + 'flag_without_module': [], + } + + qflag_already_present = [ + (loc.module_name, loc.qflag_class, loc.enum_class) + for loc in qflags_group_initial['flag_and_module_identified'] + ] + + for flag_info in qflag_location: + qflag_key = flag_info.key() + + if flag_info.module_name != '': + if qflag_key in qflag_already_present: + print('QFlag already analysed: ', qflag_key) + continue + + qflags_group_initial['flag_and_module_identified'].append(flag_info) + else: + qflags_group_initial['flag_without_module'].append(flag_info) + + return qflags_group_initial + + +def extract_qflags_to_process(qflags_modules_analysis_json: str, + qflags_to_process_json: str, + module_group: str, + ) -> None: + """Take the json file as input describing qflags and their modules and output a json file of qflags planned to be processed. + + The qflags which are located in a single module will be selected for further processing. + The others are marked as skipped with a proper reason. + """ + with open(qflags_modules_analysis_json) as f: + d = json.load(f) + + if os.path.exists(qflags_to_process_json): + with open(qflags_to_process_json) as f: + result = json.load(f) + else: + result = { + '__': 'This file can be adjusted manually by a human prior to being processed by the tool', + 'qflags_to_process': [], + 'qflags_to_skip': [], + } + + skip_already_present = set( (d['qflag_class'], d['enum_class']) + for d in result['qflags_to_skip'] + ) + for flag_info in d['flag_without_module']: + key = (flag_info['qflag_class'], flag_info['enum_class']) + if key in skip_already_present: + continue + cast(List, result['qflags_to_skip']).append( + { + 'qflag_class': flag_info['qflag_class'], + 'enum_class': flag_info['enum_class'], + 'skip_reason': 'QFlag not found in module group %s' % module_group, + } + ) + + already_present = set((flag_info_d['module_name'], flag_info_d['qflag_class'], flag_info_d['enum_class']) + for flag_info_d in result['qflags_to_process']) + + for flag_info_d in d['flag_and_module_identified']: + key = (flag_info_d['module_name'], flag_info_d['qflag_class'], flag_info_d['enum_class']) + if key in already_present: + print('QFlag to process already present: ', key ) + continue + cast(List, result['qflags_to_process']).append( flag_info_d ) + + with open(qflags_to_process_json, 'w') as f: + json.dump(result, f, indent=4) + + +def process_qflag(qflag_to_process_json: str, qflag_result_json: str, auto_commit: bool) -> int: + """Read the qflags to process from the json file + + Process one qflag, by either: + * identifying that this flag is already processed and add the flag to qflags_alraedy_done + * identifying a reason why this flag can't be processed and adding the flag to qflags_processed_error + * performing the qflag ajustment process: + * generate a test file for this qflag usage + * change the .pyi module for this qflag for supporting all the qflag operations + * run pytest on the result + * run mypy on the result + * run the tox on result + * add the flag to qflag_processed_done + + * auto_commit: if True, a git commit is performed after each successful QFlag validation + + Return number of remaining flags to process (0 when everything done) + """ + + with open(qflag_to_process_json) as f: + d = json.load(f) + + qflags_to_process = d['qflags_to_process'] + + result_json: Dict[str, List[Dict]] = { + 'qflag_already_done': [], + 'qflag_processed_done': [], + 'qflag_process_error': [], + } + + if os.path.exists(qflag_result_json): + with open(qflag_result_json, 'r') as f: + result_json = json.loads(f.read()) + + def qflag_already_processed(flag_info: QFlagLocationInfo) -> bool: + """Return True if the qflag is already included in one of the result lists + of result_json""" + flag_desc = (flag_info.module_name, flag_info.module_idx, + flag_info.qflag_class, flag_info.enum_class) + already_done_set = set( (flag_info_dict['module_name'], + flag_info_dict['module_idx'], + flag_info_dict['qflag_class'], + flag_info_dict['enum_class']) + for flag_info_dict in result_json['qflag_already_done']) + processed_done_set = set( (flag_info_dict['module_name'], + flag_info_dict['module_idx'], + flag_info_dict['qflag_class'], + flag_info_dict['enum_class']) + for flag_info_dict in result_json['qflag_processed_done']) + process_error_set = set( (flag_info_dict['module_name'], + flag_info_dict['module_idx'], + flag_info_dict['qflag_class'], + flag_info_dict['enum_class']) + for flag_info_dict in result_json['qflag_process_error']) + if flag_desc in already_done_set or flag_desc in processed_done_set or flag_desc in process_error_set: + return True + return False + + while len(qflags_to_process) != 0: + flag_info_dict = qflags_to_process.pop(0) + flag_info = QFlagLocationInfo(**flag_info_dict) + flag_info.grep_line = tuple(flag_info.grep_line) # to make it hashable + if not qflag_already_processed(flag_info): + break + else: + # we have exhausted the list of qflag to process + return 0 + + log_progress('Processing %s and %s in module %s, index %d' % + (flag_info.qflag_class, flag_info.enum_class, flag_info.module_name, flag_info.module_idx)) + + # check that the qflag is actually in the module + gen_result, error_msg, old_mod_content = generate_missing_stubs(flag_info) + flag_info_dict = dataclasses.asdict(flag_info) + test_qflag_fname = gen_test_fname(flag_info) + + # Note that flag_info has been modified in-place with additional info: + # enum_value1, enum_value2, full_enum_class_name, full_qflag_class_name + if gen_result == QFlagGenResult.CodeModifiedSuccessfully: + generate_qflag_test_file(flag_info) + log_progress('Running pytest %s' % test_qflag_fname) + p = subprocess.run(['pytest', '-v', '--capture=no', test_qflag_fname]) + if p.returncode != 0: + error_msg += 'pytest failed:\n' + # Re-run the same command to capture the output in the error message + # in the first run, the stdout/stderr was simply displayed and not captured + # here, we want to capture it and not display it + p = subprocess.run(['pytest', '-v', '--capture=no', test_qflag_fname], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf8') + error_msg += p.stdout + gen_result = QFlagGenResult.ErrorDuringProcessing + log_progress('Restoring module content') + with open(flag_info.module_path, 'w') as f: + f.write(old_mod_content) + os.unlink(test_qflag_fname) + else: + log_progress('Running mypy %s' % test_qflag_fname) + p = subprocess.run(['mypy', test_qflag_fname]) + if p.returncode != 0: + error_msg += 'mypy failed\n' + # Re-run the same command to capture the output in the error message + # in the first run, the stdout/stderr was simply displayed and not captured + # here, we want to capture it and not display it + p = subprocess.run(['mypy', test_qflag_fname], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf8') + error_msg += p.stdout + gen_result = QFlagGenResult.ErrorDuringProcessing + log_progress('Restoring module content') + with open(flag_info.module_path, 'w') as f: + f.write(old_mod_content) + os.unlink(test_qflag_fname) + else: + log_progress('validation completed successfully') + result_json['qflag_processed_done'].append(flag_info_dict) + + if auto_commit: + log_progress('Performing git commit') + subprocess.run(['git', 'add', test_qflag_fname, flag_info.module_path]) + subprocess.run(['git', 'commit', '-m', 'QFlag operations for %s, %s in module %s' % + (flag_info.qflag_full_class_name, flag_info.enum_full_class_name, flag_info.module_name)]) + + if gen_result == QFlagGenResult.CodeAlreadyModified: + # qflag methods are already there, check that the test filename is here too + if os.path.exists(test_qflag_fname): + log_progress('QFlag %s %s already supported by %s' % (flag_info.qflag_class, + flag_info.enum_class, + flag_info.module_name)) + result_json['qflag_already_done'].append(flag_info_dict) + else: + error_msg += 'QFlag methods presents but test file %s is missing\n' % test_qflag_fname + gen_result = QFlagGenResult.ErrorDuringProcessing + + if gen_result == QFlagGenResult.ErrorDuringProcessing: + log_progress('Error during processing of QFlag %s %s' % (flag_info.qflag_class, + flag_info.enum_class)) + print(error_msg) + flag_info_dict['error'] = error_msg.splitlines() + result_json['qflag_process_error'].append(flag_info_dict) + + # save our processing result + with open(qflag_result_json, 'w') as f: + json.dump(result_json, f, indent=4) + + # return True to indicate that more flags may be processed + log_progress('.') + return len(qflags_to_process) + +local_cst_module_cache: Dict[str, Tuple[str, cst.Module]] = {} + +def retrieve_cst_parsed_module(mod_name: str, mod_content: str) -> cst.Module: + '''Return the cst parsed module and cache the result for each module name''' + if mod_name in local_cst_module_cache: + cached_mod_content, cached_parsed_module = local_cst_module_cache[mod_name] + if cached_mod_content == mod_content: + log_progress('Returning cached %s parse results' % mod_name) + return cached_parsed_module + else: + log_progress('Updating cache for module %s' % mod_name) + else: + log_progress('Parsing module %s and adding it to cache' % mod_name) + + parsed_module = cst.parse_module(mod_content) + local_cst_module_cache[mod_name] = (mod_content, parsed_module) + return parsed_module + + +class QFlagGenResult(Enum): + """Enum indicating the result of generating the possibly missing stubs on the qflag classes""" + CodeModifiedSuccessfully = 0 + CodeAlreadyModified = 1 + ErrorDuringProcessing = 2 + + +def generate_missing_stubs(flag_info: 'QFlagLocationInfo') -> Tuple[QFlagGenResult, str, str]: + """ + Check that the QFlag enum+class are present in the module and check whether they support + all the advanced QFlag operations. + + If they do not, generate the missing methods. + + The flag_info input is also extended with additional information: + * full qflag class name + * full enum class name + * enum value 1 + * enum value 2 + These are needed for generating a proper test file. I don't like in-place modification + but here, it's the simplest. + + The generation consists of: + + 1. On the enum class, add two methods: + class KeyboardModifier(int): + + def __or__ (self, other: 'Qt.KeyboardModifier') -> 'Qt.KeyboardModifiers': ... # type: ignore[override] + + def __ror__ (self, other: int) -> 'Qt.KeyboardModifiers': ... # type: ignore[override, misc] + + 2. On the qflag class, add one more overload of __init__() + + @typing.overload + + def __init__(self, f: int) -> None: ... + + 3. On the qflag class, add more methods: + + def __or__ (self, other: typing.Union['Qt.KeyboardModifiers', 'Qt.KeyboardModifier', int]) -> 'Qt.KeyboardModifiers': ... + + def __and__(self, other: typing.Union['Qt.KeyboardModifiers', 'Qt.KeyboardModifier', int]) -> 'Qt.KeyboardModifiers': ... + + def __xor__(self, other: typing.Union['Qt.KeyboardModifiers', 'Qt.KeyboardModifier', int]) -> 'Qt.KeyboardModifiers': ... + + def __ror__ (self, other: 'Qt.KeyboardModifier') -> 'Qt.KeyboardModifiers': ... + + def __rand__(self, other: 'Qt.KeyboardModifier') -> 'Qt.KeyboardModifiers': ... + + def __rxor__(self, other: 'Qt.KeyboardModifier') -> 'Qt.KeyboardModifiers': ... + + Returns a tuple of (QFlagGenResult, error_msg, mod_content): + * CodeModifiedSuccessfully: + All modifications to the code of the module have been performed successfully. + Error message is empty. + mod_content contains the full text of the module. If when performing verifications on this + change, it turns out that the change is not valid, you can restore the module to its + previous content using mod_content + + * CodeAlreadyModified: + All modifications to the code were already done, no processing done. + Error message also indicates this information. + mod_content is empty (not useful) + + * ErrorDuringProcessing: + Some error occured during the processing, such as some modifications were partially done, + class not found, class found multiple times, ... + + The detail of the error is provided in the second argument of the return value. + mod_content is empty (not useful) +""" + log_progress('Opening module %s' % flag_info.module_name) + with open(flag_info.module_path) as f: + mod_content = f.read() + + mod_cst = retrieve_cst_parsed_module(flag_info.module_name, mod_content) + + log_progress('Looking for class %s and %s in module %s, index %d' % + (flag_info.qflag_class, flag_info.enum_class, flag_info.module_name, flag_info.module_idx)) + if len(flag_info.human_hint_enum_full_class_name) and len(flag_info.human_hint_qflag_full_class_name): + log_progress('Using hints: %s and %s' % (flag_info.human_hint_enum_full_class_name, flag_info.human_hint_qflag_full_class_name)) + visitor = QFlagAndEnumFinder(flag_info.enum_class, flag_info.qflag_class, + flag_info.module_count, flag_info.module_idx, + flag_info.human_hint_enum_full_class_name, + flag_info.human_hint_qflag_full_class_name, + ) + mod_cst.visit(visitor) + + # storing the enum_values + full class name for further usage + flag_info.enum_full_class_name = visitor.enum_class_full_name + flag_info.enum_value1 = visitor.enum_value1 + flag_info.enum_value2 = visitor.enum_value2 + flag_info.qflag_full_class_name = visitor.qflag_class_full_name + + if visitor.enum_class_full_name == '': + return (QFlagGenResult.ErrorDuringProcessing, 'Could not locate class %s' % visitor.enum_class_name, '') + + if visitor.qflag_class_full_name == '': + return (QFlagGenResult.ErrorDuringProcessing, 'Could not locate class %s' % visitor.qflag_class_name, '') + + # evaluate exact behavior of QFlag + try: + flag_info.or_converts_to_multi = not eval('''type({qtmodule}.{oneFlagName}.{value1} | {qtmodule}.{oneFlagName}.{value2}) == int'''.format( + value1=flag_info.enum_value1, value2=flag_info.enum_value2, + qtmodule=flag_info.module_name, + oneFlagName=flag_info.enum_full_class_name)) + except Exception as exc: + return (QFlagGenResult.ErrorDuringProcessing, traceback.format_exc(), '') + + flag_info.or_int_converts_to_multi = not eval('''type({qtmodule}.{oneFlagName}.{value1} | 33) == int'''.format( + value1=flag_info.enum_value1, qtmodule = flag_info.module_name, oneFlagName = flag_info.enum_full_class_name)) + flag_info.int_or_converts_to_multi = not eval('''type(33 | {qtmodule}.{oneFlagName}.{value1}) == int'''.format( + value1=flag_info.enum_value1, qtmodule = flag_info.module_name, oneFlagName = flag_info.enum_full_class_name)) + + try: + flag_info.supports_one_op_multi = True + eval('''{qtmodule}.{oneFlagName}.{enumValue} | {qtmodule}.{multiFlagName}()'''.format( + oneFlagName=flag_info.enum_full_class_name, + enumValue=flag_info.enum_value1, + multiFlagName=flag_info.qflag_full_class_name, + qtmodule=flag_info.module_name + )) + except TypeError: + flag_info.supports_one_op_multi = False + + if (visitor.enum_methods_present, visitor.qflag_method_present) == (MethodPresent.All, MethodPresent.All): + return (QFlagGenResult.CodeAlreadyModified, visitor.error_msg, '') + + if (visitor.enum_methods_present, visitor.qflag_method_present) == (MethodPresent.All, MethodPresent.Not): + visitor.error_msg += 'Enum methods are present but not QFlag methods\n' + + if (visitor.enum_methods_present, visitor.qflag_method_present) == (MethodPresent.Not, MethodPresent.All): + # this is ok if enum does not need any special method + if (flag_info.or_converts_to_multi + or flag_info.int_or_converts_to_multi + or flag_info.or_int_converts_to_multi): + # this means __or__ or __ror__ must be present, we have an error + visitor.error_msg += 'QFlag methods are present but not Enum methods\n' + else: + # it's ok + return (QFlagGenResult.CodeAlreadyModified, visitor.error_msg, '') + + if visitor.error_msg: + return (QFlagGenResult.ErrorDuringProcessing, visitor.error_msg, '') + + log_progress('Found %s and %s' % (flag_info.qflag_full_class_name, flag_info.enum_full_class_name)) + + print('enum behavior:') + print('- or_converts_to_multi: ', flag_info.or_converts_to_multi) + print('- or_int_converts_to_multi: ', flag_info.or_int_converts_to_multi) + print('- int_or_converts_to_multi: ', flag_info.int_or_converts_to_multi) + print('- supports_one_op_multi: ', flag_info.supports_one_op_multi) + + log_progress('Updating module %s by adding new methods' % flag_info.module_name) + transformer = QFlagAndEnumUpdater(visitor.enum_class_name, visitor.enum_class_full_name, + visitor.qflag_class_name, visitor.qflag_class_full_name, flag_info.module_idx, + flag_info.human_hint_enum_full_class_name, + flag_info.human_hint_qflag_full_class_name, + flag_info.or_converts_to_multi, + flag_info.or_int_converts_to_multi, + flag_info.int_or_converts_to_multi) + updated_mod_cst = mod_cst.visit(transformer) + + if transformer.error_msg: + return (QFlagGenResult.ErrorDuringProcessing, visitor.error_msg, '') + + log_progress('Saving updated module %s' % flag_info.module_name) + with open(flag_info.module_path, 'w') as f: + f.write(updated_mod_cst.code) + + return (QFlagGenResult.CodeModifiedSuccessfully, '', mod_content) + + +class MethodPresent(Enum): + """An enum to reflect if a method is already present or not""" + Unset = 0 + All = 1 + Not = 2 + Partial = 3 + + +class QFlagAndEnumFinder(cst.CSTVisitor): + + def __init__(self, enum_class: str, qflag_class: str, + module_count: int, module_idx: int, + human_hint_enum_full_class_name: str = '', + human_hint_qflag_full_class_name: str = '', + ) -> None: + super().__init__() + + # used internally to generate the full class name + self.full_name_stack: List[str] = [] + + # the class name we are looking for + self.enum_class_name = enum_class + self.qflag_class_name = qflag_class + + # human help for finding the class + if human_hint_enum_full_class_name: + self.human_hint_enum_full_class_name = human_hint_enum_full_class_name.split('.') + else: + self.human_hint_enum_full_class_name = '' + + if human_hint_qflag_full_class_name: + self.human_hint_qflag_full_class_name = human_hint_qflag_full_class_name.split('.') + else: + self.human_hint_qflag_full_class_name = human_hint_qflag_full_class_name + + # the number of expected occurences in this module of this flag + self.module_count = module_count + + # the index of the flag in the module which we are looking for + # useful if there are multiple same name flags + self.module_idx = module_idx + + # our internal index for finding this class + self.visit_enum_idx = -1 + self.visit_qflag_idx = -1 + + # the class full name + self.enum_class_full_name = '' + self.qflag_class_full_name = '' + + # the name of two values of the enum class + self.enum_value1 = '' + self.enum_value2 = '' + + # the node of the class, for debugging purpose + + # when filled, set to one of the MethodPresent values + self.enum_methods_present = MethodPresent.Unset + self.qflag_method_present = MethodPresent.Unset + + # set when enum_methods_present is set to partial, to add more contect information + self.error_msg = '' + + + def visit_ClassDef(self, node: cst.ClassDef) -> Optional[bool]: + self.full_name_stack.append( node.name.value ) + if node.name.value == self.enum_class_name: + self.visit_enum_idx += 1 + found_enum_class = False + if self.human_hint_enum_full_class_name: + if self.human_hint_enum_full_class_name == self.full_name_stack: + found_enum_class = True + else: + if self.visit_enum_idx > self.module_count: + self.error_msg = 'class %s found too many times: %d\n' % (self.enum_class_name, self.visit_enum_idx) + return None + + if self.visit_enum_idx == self.module_idx: + # we found the index we are looking for + found_enum_class = True + + if found_enum_class: + if self.check_enum_method_present(node): + self.enum_class_full_name = '.'.join(self.full_name_stack) + self.collect_enum_values(node) + return None + + elif node.name.value == self.qflag_class_name: + self.visit_qflag_idx += 1 + found_qflag_class = False + if self.human_hint_qflag_full_class_name: + if self.human_hint_qflag_full_class_name == self.full_name_stack: + found_qflag_class = True + else: + if self.visit_qflag_idx > self.module_count: + self.error_msg = 'class %s found too times: %d\n' % (self.qflag_class_name, self.visit_qflag_idx) + return None + + if self.visit_qflag_idx == self.module_idx: + # we found the index we are looking for + found_qflag_class = True + + if found_qflag_class: + if self.check_qflag_method_present(node): + self.qflag_class_full_name = '.'.join(self.full_name_stack) + return None + + return None + + + def check_enum_method_present(self, enum_node: cst.ClassDef) -> bool: + """Check if the class contains method __or__ and __ror__ with one argument and if class + inherit from int""" + if len(enum_node.bases) == 0 or enum_node.bases[0].value.value != 'int': + # class does not inherit from int, not the one we are looking for + return False + has_or = matchers.findall(enum_node.body, matchers.FunctionDef(name=matchers.Name('__or__'))) + has_ror = matchers.findall(enum_node.body, matchers.FunctionDef(name=matchers.Name('__ror__'))) + self.enum_methods_present = { + 0: MethodPresent.Not, + 1: MethodPresent.Partial, + 2: MethodPresent.All + }[len(has_or) + len(has_ror)] + + if self.enum_methods_present == MethodPresent.Partial: + if has_or: + args = ('__or__', '__ror__') + else: + args = ('__ror__', '__or__') + + self.error_msg += 'class %s, method %s present without method %s\n' % ((self.enum_class_full_name,)+args) + + return True + + + def collect_enum_values(self, enum_node: cst.ClassDef) -> None: + """Collect two actual values for the enum and store them into self.enum_value1 and enum_value2 + """ + # find all lines consisting of an assignment to an ellipsis, like "AlignLeft = ..." + enum_values = matchers.findall(enum_node.body, matchers.SimpleStatementLine( + body=[matchers.Assign(value=matchers.Ellipsis())])) + if len(enum_values) == 0: + self.error_msg += 'class %s, could not find any enum values\n' % self.enum_class_full_name + return + + self.enum_value1 = enum_values[0].body[0].targets[0].target.value + if len(enum_values) > 1: + self.enum_value2 = enum_values[1].body[0].targets[0].target.value + else: + # it works find if both values are the same so don't bother + self.enum_value2 = self.enum_value1 + + + def check_qflag_method_present(self, qflag_node: cst.ClassDef) -> bool: + """Check if the class contains method: + def __or__ + def __and__ + def __xor__ + def __ror__ + def __rand__ + def __rxor__ + + with one argument. + + def __init__(self, f: typing.Union['Qt.KeyboardModifiers', 'Qt.KeyboardModifier']) -> None: + def __init__(self, f: typing.Union['Qt.KeyboardModifiers', 'Qt.KeyboardModifier', int]) -> None: + """ + if (len(qflag_node.bases) == 0 + or not (matchers.matches(qflag_node.bases[0], + matchers.Arg(value=matchers.Attribute(value=matchers.Name('sip'), + attr=matchers.Name('simplewrapper') + ) + ) + ) + or matchers.matches(qflag_node.bases[0], + matchers.Arg(value=matchers.Attribute(value=matchers.Name('sip'), + attr=matchers.Name('wrapper') + ) + ) + ) + ) + ): + # 'Class does not inherit from sip.simplewrapper' or sip.wrapper + return False + + has_method = [ + (m, matchers.findall(qflag_node.body, matchers.FunctionDef(name=matchers.Name(m)))) + for m in ('__or__', '__and__', '__xor__', '__ror__', '__rxor__', '__rand__') + ] + + if all(has_info[1] for has_info in has_method): + # all method presents + self.qflag_method_present = MethodPresent.All + return True + + if all(not has_info[1] for has_info in has_method): + # all method absent + self.qflag_method_present = MethodPresent.Not + return True + + self.qflag_method_present = MethodPresent.Partial + + for m_name, m_has in has_method: + if m_has: + self.error_msg += 'class %s, method %s present without all others\n' \ + % ((self.qflag_class_full_name, m_name)) + else: + self.error_msg += 'class %s, method %s missing\n' \ + % ((self.qflag_class_full_name, m_name)) + return True + + + def visit_FunctionDef(self, node: cst.FunctionDef) -> Optional[bool]: + self.full_name_stack.append( node.name.value ) + return None + + def leave_ClassDef(self, node: cst.ClassDef) -> None: + self.full_name_stack.pop() + + def leave_FunctionDef(self, node: cst.FunctionDef) -> None: + self.full_name_stack.pop() + + +class QFlagAndEnumUpdater(cst.CSTTransformer): + + def __init__(self, enum_class: str, enum_full_name: str, qflag_class: str, qflag_full_name: str, + module_idx: int, + human_hint_enum_full_class_name: str, + human_hint_qflag_full_class_name: str, + or_converts_to_multi: bool, + or_int_converts_to_multi: bool, + int_or_converts_to_multi: bool) -> None: + super().__init__() + + # used internally to generate the full class name + self.full_name_stack: List[str] = [] + + self.error_msg = '' + + # the class name we are looking for + self.enum_class = enum_class + self.qflag_class = qflag_class + self.enum_full_name = enum_full_name + self.qflag_full_name = qflag_full_name + + # human help for finding the class + self.human_hint_enum_full_class_name = '' + if human_hint_enum_full_class_name: + self.human_hint_enum_full_class_name = human_hint_enum_full_class_name.split('.') + self.human_hint_qflag_full_class_name = '' + if human_hint_qflag_full_class_name: + self.human_hint_qflag_full_class_name = human_hint_qflag_full_class_name.split('.') + + # the index in this module of the class we are looking for + self.module_idx = module_idx + + # our current count of visit + self.visit_enum_idx = -1 + self.visit_qflag_idx = -1 + + self.or_converts_to_multi = or_converts_to_multi + self.or_int_converts_to_multi = or_int_converts_to_multi + self.int_or_converts_to_multi = int_or_converts_to_multi + + # set when enum_methods_present is set to partial, to add more contect information + self.error_msg = '' + + def visit_ClassDef(self, node: cst.ClassDef) -> Optional[bool]: + self.full_name_stack.append( node.name.value ) + return None + + def visit_FunctionDef(self, node: cst.FunctionDef) -> Optional[bool]: + self.full_name_stack.append( node.name.value ) + return None + + def leave_FunctionDef(self, node: cst.FunctionDef, updated_node: cst.FunctionDef) -> cst.FunctionDef: + self.full_name_stack.pop() + return updated_node + + def leave_ClassDef(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef: + found_enum_class = False + found_qflag_class = False + + if self.human_hint_enum_full_class_name: + if self.human_hint_enum_full_class_name == self.full_name_stack: + found_enum_class = True + else: + if original_node.name.value == self.enum_class: + self.visit_enum_idx += 1 + if self.visit_enum_idx == self.module_idx: + found_enum_class = True + + if self.human_hint_qflag_full_class_name: + if self.human_hint_qflag_full_class_name == self.full_name_stack: + found_qflag_class = True + else: + if original_node.name.value == self.qflag_class: + self.visit_qflag_idx += 1 + if self.visit_qflag_idx == self.module_idx: + found_qflag_class = True + + self.full_name_stack.pop() + + if found_enum_class: + return self.transform_enum_class(original_node, updated_node) + + if found_qflag_class: + return self.transform_qflag_class(original_node, updated_node) + + return updated_node + + + def transform_enum_class(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef: + """Add the two methods __or__ and __ror__ to the class body""" + + # we keep comments separated to align them properly in the final file + or_behavior = (self.or_converts_to_multi, self.or_int_converts_to_multi, self.int_or_converts_to_multi) + if or_behavior == (True, False, True): + new_methods_parts = ( + ("def __or__ (self, other: '{enum}') -> '{qflag}': ...", "# type: ignore[override]\n"), + ("def __ror__ (self, other: int) -> '{qflag}': ...", "# type: ignore[override, misc]\n\n") + ) + elif or_behavior == (True, True, True): + new_methods_parts = ( + ("def __or__ (self, other: typing.Union[int, '{enum}']) -> '{qflag}': ...", "# type: ignore[override]\n"), + ("def __ror__ (self, other: int) -> '{qflag}': ...", "# type: ignore[override, misc]\n\n") + ) + elif or_behavior == (False, False, False): + # no changes needed + return updated_node + else: + raise ValueError('Unsupported or behavior:', or_behavior) + + + # fill the class names + new_methods_filled = tuple( + (code.format(enum=self.enum_full_name, qflag=self.qflag_full_name), comment) + for code, comment in new_methods_parts + ) + + # now calculate the proper spacing to have aligned comments + max_code_len = max(len(code) for code, comment in new_methods_filled) + new_methods_spaced = tuple( + code + ' '*(4+max_code_len-len(code)) + comment + for code, comment in new_methods_filled + ) + new_methods_cst = tuple(cst.parse_statement(s) for s in new_methods_spaced) + return updated_node.with_changes(body=updated_node.body.with_changes(body= + new_methods_cst \ + + (updated_node.body.body[0].with_changes(leading_lines= + updated_node.body.body[0].leading_lines + + (cst.EmptyLine(),)),) \ + + updated_node.body.body[1:] ) ) + + + def transform_qflag_class(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef: + """ + On the qflag class, add one more overload __init__() and add more methods + + @typing.overload + + def __init__(self, f: int) -> None: ... + """ + init_methods = matchers.findall(updated_node.body, matchers.FunctionDef(name=matchers.Name('__init__'))) + if len(init_methods) == 1: + # we do not handle the case where there is only one init function + # to handle it, we would need to do the following: + # * add an @typing.overload to the current init function + # * add a new init function + # + # This is not difficult, it's just that I don't think we have such cases + self.error_msg += 'Only one __init__ method in QFlag class %s, do not know how to transform it\n' % self.qflag_full_name + return updated_node + + # find the last __init__() method index + last_init_idx = 0 + nb_init_found = 0 + for i, body_element in enumerate(updated_node.body.body): + if matchers.matches(body_element, matchers.FunctionDef(name=matchers.Name('__init__'))): + nb_init_found += 1 + if nb_init_found == len(init_methods): + last_init_idx = i + break + + if last_init_idx == 0: + self.error_msg += 'No __init__ method found in class %s' % self.qflag_full_name + return updated_node + + + cst_init = cst.parse_statement( '@typing.overload\ndef __init__(self, f: int) -> None: ...' ) + updated_node = updated_node.with_changes(body=updated_node.body.with_changes(body= + tuple(updated_node.body.body[:last_init_idx+1]) + + (cst_init,) + + tuple(updated_node.body.body[last_init_idx+1:]) + ) + ) + + new_methods = ( + "def __or__ (self, other: typing.Union['{qflag}', '{enum}', int]) -> '{qflag}': ...", + "def __and__(self, other: typing.Union['{qflag}', '{enum}', int]) -> '{qflag}': ...", + "def __xor__(self, other: typing.Union['{qflag}', '{enum}', int]) -> '{qflag}': ...", + "def __ror__ (self, other: '{enum}') -> '{qflag}': ...", + "def __rand__(self, other: '{enum}') -> '{qflag}': ...", + "def __rxor__(self, other: '{enum}') -> '{qflag}': ...", + ) + new_methods_cst = tuple( + cst.parse_statement(s.format(enum=self.enum_full_name, qflag=self.qflag_full_name)) + for s in new_methods + ) + return updated_node.with_changes(body=updated_node.body.with_changes(body= + tuple(updated_node.body.body) + new_methods_cst ) ) + + + +@functools.lru_cache(maxsize=1) +def read_qflag_test_template(template_fname: str) -> Tuple[List[str], List[str], List[str]]: + """Return the source of the template for generating qflags test. + + Return 3 parts as a list of strings: + - the first part should be unmodified + - the second part should be replaced for a specific QFlag class + - the third part should be unmodified + """ + + # the markers inside the above template to identify the parts to replace + MARKER_SPECIFIC_START = '### Specific part' + MARKER_SPECIFIC_END = '### End of specific part' + + with open(template_fname) as f: + lines = f.readlines() + + source_part_before, source_part_middle, source_part_after = [], [], [] + fill_middle, fill_after = False, False + for l in lines: + if fill_after: + source_part_after.append(l) + continue + + if fill_middle: + if MARKER_SPECIFIC_END in l: + fill_after = True + source_part_after.append(l) + continue + + source_part_middle.append(l) + continue + + source_part_before.append(l) + if MARKER_SPECIFIC_START in l: + fill_middle = True + + return source_part_before, source_part_middle, source_part_after + + +def gen_test_fname(fli: QFlagLocationInfo) -> str: + """Generate the name of the test file which will verify this qflag""" + return 'test_{fli.module_name}_{fli.qflag_class}_{fli.enum_class}.py'.format(fli=fli) + + +def generate_qflag_test_file(flag_info: QFlagLocationInfo) -> None: + """Generate a qflag test file. + + The filename is inferred from flag_info using gen_test_fname() + """ + + # the template after which we model all generated qflag tests + TEMPLATE_QFLAGS_TESTS = 'qflags_test_template.py' + + test_qflag_fname = gen_test_fname(flag_info) + generic_part_before, _replacable_part, generic_part_after = read_qflag_test_template(TEMPLATE_QFLAGS_TESTS) + + with open(test_qflag_fname, 'w') as f: + f.writelines(generic_part_before) + + # replace the repplacable_part with code dedicated to our qflag + f.write('''# file generated from {source} for QFlags class "{multiFlagName}" and flag class "{oneFlagName}" +from PyQt5 import {qtmodule} + +OneFlagClass = {qtmodule}.{oneFlagName} +MultiFlagClass = {qtmodule}.{multiFlagName} + +oneFlagRefValue1 = {qtmodule}.{oneFlagName}.{oneFlagValue1} +oneFlagRefValue2 = {qtmodule}.{oneFlagName}.{oneFlagValue2} + +OR_CONVERTS_TO_MULTI: Literal[{or_converts_to_multi}] = {or_converts_to_multi} +OR_INT_CONVERTS_TO_MULTI: Literal[{or_int_converts_to_multi}] = {or_int_converts_to_multi} +INT_OR_CONVERTS_TO_MULTI: Literal[{int_or_converts_to_multi}] = {int_or_converts_to_multi} +SUPPORTS_ONE_OP_MULTI: Literal[{supports_one_op_multi}] = {supports_one_op_multi} +'''.format(source=TEMPLATE_QFLAGS_TESTS, + multiFlagName=flag_info.qflag_full_class_name, + oneFlagName=flag_info.enum_full_class_name, + oneFlagValue1=flag_info.enum_value1, + oneFlagValue2=flag_info.enum_value2, + qtmodule=flag_info.module_name, + or_converts_to_multi=flag_info.or_converts_to_multi, + or_int_converts_to_multi=flag_info.or_int_converts_to_multi, + int_or_converts_to_multi=flag_info.int_or_converts_to_multi, + supports_one_op_multi=flag_info.supports_one_op_multi + )) + f.writelines(generic_part_after) + log_progress('Test file generated: %s' % test_qflag_fname) + + +def generate_qflags_to_process(qt_qflag_grep_result_fname: str, module_group: str) -> None: + """Run the generation process from the grep output parsing to the generation of json file listing the flags to process""" + location_qflags = identify_qflag_location(qt_qflag_grep_result_fname, MODULE_GROUPS[module_group]) + log_progress('%d qflags extracted from grep file' % len(location_qflags)) + + qflags_modules_analysis_json = 'qflags_modules_analysis.json' + # put our intermediate classification into a json file for human review + if os.path.exists(qflags_modules_analysis_json): + with open(qflags_modules_analysis_json) as f: + d = json.load(f) + qflag_groups_initial = { + 'flag_and_module_identified': [QFlagLocationInfo(**v) for v in d['flag_and_module_identified']], + 'flag_without_module': [QFlagLocationInfo(**v) for v in d['flag_without_module']] + } + else: + qflag_groups_initial = None + + + initial_len = len(qflag_groups_initial['flag_and_module_identified']) + qflags_groups = group_qflags(location_qflags, qflag_groups_initial) + new_len = len(qflag_groups_initial['flag_and_module_identified']) + log_progress('%d qflags ready to be processed' % (new_len - initial_len)) + + with open(qflags_modules_analysis_json, 'w') as f: + json.dump(qflags_groups, f, indent=4, default=json_encode_qflaglocationinfo) + log_progress('QFlag analysis saved to: %s' % qflags_modules_analysis_json) + + qflags_to_process_json = 'qflags_to_process.json' + extract_qflags_to_process(qflags_modules_analysis_json, qflags_to_process_json, module_group) + log_progress('qflag file ready to process: %s' % qflags_to_process_json) + + +def regen_test_files(qflag_process_results: str) -> None: + with open(qflag_process_results) as f: + results_content = f.read() + results = json.loads(results_content) + + flags_to_process = results['qflag_processed_done'] + results['qflag_already_done'] + log_progress('%d test files to regenerate' % len(flags_to_process)) + for flag_info_dict in flags_to_process: + flag_info = QFlagLocationInfo(**flag_info_dict) + test_qflag_fname = gen_test_fname(flag_info) + print('Updating', test_qflag_fname) + generate_qflag_test_file(flag_info) + + + +if __name__ == '__main__': + + if len(sys.argv) <= 1: + print(USAGE) + sys.exit(1) + + auto_commit = False + if '--auto-commit' in sys.argv: + auto_commit = True + + + if sys.argv[1] == 'gen_qflag_stub': + nb = 1 + process_all = False + if len(sys.argv) > 2: + if sys.argv[2] == 'all': + process_all = True + else: + nb = int(sys.argv[2]) + + qflags_to_process_json = 'qflags_to_process.json' + qflag_result_json = 'qflags_process_result.json' + more_available = -1 + while (nb > 0 or process_all) and (more_available == -1 or more_available > 0): + nb -= 1 + more_available = process_qflag(qflags_to_process_json, qflag_result_json, auto_commit) + if more_available: + log_progress('Still %d flags to process' % more_available) + log_progress('All qflags are processed.') + + elif sys.argv[1] == 'analyse_grep_results': + if len(sys.argv) <= 4 or sys.argv[3] != '--group': + print('Error, you must provide the filename of the grep results and the group of modules to use\n') + print(USAGE) + sys.exit(1) + + grep_fname = sys.argv[2] + module_group = sys.argv[4] + if not module_group in MODULE_GROUPS: + print('Unknown module group: %s' % module_group) + print('Possible choices are:\n-', '\n- '.join(MODULE_GROUPS.keys())) + sys.exit(0) + + generate_qflags_to_process(grep_fname, module_group) + + + elif sys.argv[1] == 'regen_test_files': + + if len(sys.argv) <= 2: + print('Error, you must provide the filename of the qflag-process-results\n') + print(USAGE) + sys.exit(1) + + qflag_process_results = sys.argv[2] + regen_test_files(qflag_process_results) + + else: + print('Error, invalid command line arguments\n') + print(USAGE) + sys.exit(1) + + diff --git a/tests/qflags/grep-results/qt3d-qflag-grep-result.txt b/tests/qflags/grep-results/qt3d-qflag-grep-result.txt new file mode 100644 index 00000000..be153459 --- /dev/null +++ b/tests/qflags/grep-results/qt3d-qflag-grep-result.txt @@ -0,0 +1,8 @@ +src\animation\frontend\qanimationcallback.h: Q_DECLARE_FLAGS(Flags, Flag) +src\core\changes\qscenechange.h:Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag) +src\core\changes\qscenechange.h: Q_DECLARE_FLAGS(DeliveryFlags, DeliveryFlag) +src\render\backend\abstractrenderer_p.h: Q_DECLARE_FLAGS(BackendNodeDirtySet, BackendNodeDirtyFlag) +src\render\framegraph\qclearbuffers.h: Q_DECLARE_FLAGS(BufferTypeFlags, BufferType) +src\render\framegraph\qmemorybarrier.h: Q_DECLARE_FLAGS(Operations, Operation) +src\render\texture\texture_p.h: Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag) +src\quick3d\imports\scene3d\scene3dview_p.h: Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag) diff --git a/tests/qflags/grep-results/qtactiveqt-qflag-grep-result.txt b/tests/qflags/grep-results/qtactiveqt-qflag-grep-result.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/qflags/grep-results/qtbase-qflag-grep-result.txt b/tests/qflags/grep-results/qtbase-qflag-grep-result.txt new file mode 100644 index 00000000..e92d42a0 --- /dev/null +++ b/tests/qflags/grep-results/qtbase-qflag-grep-result.txt @@ -0,0 +1,227 @@ +qmake\library\qmakeevaluator.h: Q_DECLARE_FLAGS(LoadFlags, LoadFlag) +qmake\library\qmakeparser.h: Q_DECLARE_FLAGS(ParseFlags, ParseFlag) +qmake\library\qmakevfs.h: Q_DECLARE_FLAGS(VfsFlags, VfsFlag) +qmake\generators\makefile.h: Q_DECLARE_FLAGS(FileFixifyTypes, FileFixifyType) +src\concurrent\qtconcurrentreducekernel.h:Q_DECLARE_FLAGS(ReduceOptions, ReduceOption) +src\dbus\qdbusconnection.h: Q_DECLARE_FLAGS(RegisterOptions, RegisterOption) +src\dbus\qdbusconnection.h: Q_DECLARE_FLAGS(VirtualObjectRegisterOptions, VirtualObjectRegisterOption) +src\dbus\qdbusconnection.h: Q_DECLARE_FLAGS(ConnectionCapabilities, ConnectionCapability) +src\opengl\qgl.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption) +src\opengl\qgl.h: Q_DECLARE_FLAGS(OpenGLVersionFlags, OpenGLVersionFlag) +src\opengl\qgl.h: Q_DECLARE_FLAGS(BindOptions, BindOption) +src\opengl\qglfunctions.h: Q_DECLARE_FLAGS(OpenGLFeatures, OpenGLFeature) +src\opengl\qglshaderprogram.h: Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit) +src\dbus\qdbusservicewatcher.h: Q_DECLARE_FLAGS(WatchMode, WatchModeFlag) +examples\network\torrent\peerwireclient.h: Q_DECLARE_FLAGS(PeerWireState, PeerWireStateFlag) +src\corelib\codecs\qtextcodec.h: Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag) +src\corelib\codecs\qtextcodec_p.h: Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag) +src\gui\accessible\qaccessible.h: Q_DECLARE_FLAGS(Relation, RelationFlag) +src\corelib\io\qabstractfileengine_p.h: Q_DECLARE_FLAGS(FileFlags, FileFlag) +src\corelib\global\qflags.h:#define Q_DECLARE_FLAGS(Flags, Enum)\ +src\corelib\global\qflags.h:#define Q_DECLARE_FLAGS(Flags, Enum)\ +src\corelib\itemmodels\qabstractitemmodel.h: Q_DECLARE_FLAGS(CheckIndexOptions, CheckIndexOption) +src\corelib\io\qdir.h: Q_DECLARE_FLAGS(Filters, Filter) +src\corelib\io\qdir.h: Q_DECLARE_FLAGS(SortFlags, SortFlag) +src\corelib\io\qdiriterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag) +src\corelib\io\qdir_p.h: Q_DECLARE_FLAGS(PathNormalizations, PathNormalization) +src\corelib\io\qfiledevice.h: Q_DECLARE_FLAGS(Permissions, Permission) +src\corelib\io\qfiledevice.h: Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag) +src\corelib\itemmodels\qitemselectionmodel.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(KeyboardModifiers, KeyboardModifier) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(MouseButtons, MouseButton) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(Orientations, Orientation) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(SplitBehavior, SplitBehaviorFlags) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(Alignment, AlignmentFlag) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(WindowFlags, WindowType) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(WindowStates, WindowState) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(ApplicationStates, ApplicationState) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(ScreenOrientations, ScreenOrientation) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(ImageConversionFlags, ImageConversionFlag) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(ToolBarAreas, ToolBarArea) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(Edges, Edge) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(InputMethodQueries, InputMethodQuery) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(InputMethodHints, InputMethodHint) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(FindChildOptions, FindChildOption) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(DropActions, DropAction) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(ItemFlags, ItemFlag) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(MatchFlags, MatchFlag) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(TextInteractionFlags, TextInteractionFlag) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(TouchPointStates, TouchPointState) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(GestureFlags, GestureFlag) +src\corelib\global\qnamespace.h: Q_DECLARE_FLAGS(MouseEventFlags, MouseEventFlag) +src\corelib\io\qfilesystemmetadata_p.h: Q_DECLARE_FLAGS(MetaDataFlags, MetaDataFlag) +src\gui\image\qimageiohandler.h: Q_DECLARE_FLAGS(Transformations, Transformation) +src\gui\image\qimageiohandler.h: Q_DECLARE_FLAGS(Capabilities, Capability) +src\corelib\kernel\qeventloop.h: Q_DECLARE_FLAGS(ProcessEventsFlags, ProcessEventsFlag) +src\corelib\io\qiodevice.h: Q_DECLARE_FLAGS(OpenMode, OpenModeFlag) +src\gui\kernel\qevent.h: Q_DECLARE_FLAGS(InfoFlags, InfoFlag) +src\corelib\io\qloggingregistry_p.h: Q_DECLARE_FLAGS(PatternFlags, PatternFlag) +src\corelib\plugin\qlibrary.h: Q_DECLARE_FLAGS(LoadHints, LoadHint) +src\gui\opengl\qopenglbuffer.h: Q_DECLARE_FLAGS(RangeAccessFlags, RangeAccessFlag) +src\corelib\kernel\qmetaobjectbuilder_p.h: Q_DECLARE_FLAGS(AddMembers, AddMember) +src\corelib\kernel\qmetaobjectbuilder_p.h: Q_DECLARE_FLAGS(MetaObjectFlags, MetaObjectFlag) +src\gui\opengl\qopengldebug.h: Q_DECLARE_FLAGS(Sources, Source) +src\gui\opengl\qopengldebug.h: Q_DECLARE_FLAGS(Types, Type) +src\gui\opengl\qopengldebug.h: Q_DECLARE_FLAGS(Severities, Severity) +src\corelib\kernel\qmetatype.h: Q_DECLARE_FLAGS(TypeFlags, TypeFlag) +src\gui\opengl\qopenglextensions_p.h: Q_DECLARE_FLAGS(OpenGLExtensions, OpenGLExtension) +src\corelib\io\qstandardpaths.h: Q_DECLARE_FLAGS(LocateOptions, LocateOption) +src\gui\opengl\qopenglfunctions.h: Q_DECLARE_FLAGS(OpenGLFeatures, OpenGLFeature) +src\corelib\kernel\qppsattribute_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\corelib\kernel\qppsobject_p.h: Q_DECLARE_FLAGS(OpenModes, OpenMode) +src\gui\kernel\qplatformcursor.h: Q_DECLARE_FLAGS(Capabilities, Capability) +src\network\access\qhstspolicy.h: Q_DECLARE_FLAGS(PolicyFlags, PolicyFlag) +src\gui\kernel\qplatformdialoghelper.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton) +src\gui\kernel\qplatformdialoghelper.h: Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption) +src\gui\kernel\qplatformdialoghelper.h: Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption) +src\gui\kernel\qplatformdialoghelper.h: Q_DECLARE_FLAGS(FileDialogOptions, FileDialogOption) +src\gui\kernel\qplatformgraphicsbuffer.h: Q_DECLARE_FLAGS(AccessTypes, AccessType); +src\gui\painting\qblittable_p.h: Q_DECLARE_FLAGS (Capabilities, Capability) +src\corelib\io\qurl.h: Q_DECLARE_FLAGS(ComponentFormattingOptions, ComponentFormattingOption) +src\corelib\io\qurl.h: Q_DECLARE_FLAGS(FormattingOptions, UrlFormattingOption) +src\corelib\io\qurl.h: Q_DECLARE_FLAGS(UserInputResolutionOptions, UserInputResolutionOption) +src\gui\painting\qcolortransform_p.h: Q_DECLARE_FLAGS(TransformFlags, TransformFlag) +src\gui\kernel\qplatformtheme.h: Q_DECLARE_FLAGS(IconOptions, IconOption) +src\network\bearer\qnetworkconfigmanager.h: Q_DECLARE_FLAGS(Capabilities, Capability) +src\network\bearer\qnetworkconfiguration.h: Q_DECLARE_FLAGS(StateFlags, StateFlag) +src\gui\kernel\qsurfaceformat.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption) +src\network\bearer\qnetworksession.h: Q_DECLARE_FLAGS(UsagePolicies, UsagePolicy) +src\gui\painting\qpaintengine.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag) +src\gui\painting\qpaintengine.h: Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature) +src\gui\painting\qpaintengine.h: Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag) +src\gui\kernel\qtouchdevice.h: Q_DECLARE_FLAGS(Capabilities, CapabilityFlag) +src\gui\opengl\qopenglshaderprogram.h: Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit) +src\gui\opengl\qopengltexture.h: Q_DECLARE_FLAGS(Features, Feature) +src\gui\painting\qpainter.h: Q_DECLARE_FLAGS(RenderHints, RenderHint) +src\gui\painting\qpainter.h: Q_DECLARE_FLAGS(PixmapFragmentHints, PixmapFragmentHint) +src\gui\opengl\qopengltextureuploader_p.h: Q_DECLARE_FLAGS(BindOptions, BindOption) +src\network\access\qspdyprotocolhandler_p.h: Q_DECLARE_FLAGS(DataFrameFlags, DataFrameFlag) +src\network\access\qspdyprotocolhandler_p.h: Q_DECLARE_FLAGS(ControlFrameFlags, ControlFrameFlag) +src\network\access\qspdyprotocolhandler_p.h: Q_DECLARE_FLAGS(SETTINGS_Flags, SETTINGS_Flag) +src\network\access\qspdyprotocolhandler_p.h: Q_DECLARE_FLAGS(SETTINGS_ID_Flags, SETTINGS_ID_Flag) +src\gui\painting\qplatformbackingstore.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\painting\qplatformbackingstore.h: Q_DECLARE_FLAGS(TextureFlags, TextureFlag) +src\gui\text\qfontengine_p.h: Q_DECLARE_FLAGS(ShaperFlags, ShaperFlag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(StageFlags, StageFlag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(UsageFlags, UsageFlag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(BeginFrameFlags, BeginFrameFlag) +src\gui\rhi\qrhi_p.h: Q_DECLARE_FLAGS(EndFrameFlags, EndFrameFlag) +src\gui\rhi\qshaderdescription_p.h: Q_DECLARE_FLAGS(ImageFlags, ImageFlag) +src\gui\vulkan\qvulkaninstance.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\rhi\qshader_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\util\qlayoutpolicy_p.h: Q_DECLARE_FLAGS(ControlTypes, ControlType) +src\gui\vulkan\qvulkanwindow.h: Q_DECLARE_FLAGS(Flags, Flag) +src\gui\text\qglyphrun.h: Q_DECLARE_FLAGS(GlyphRunFlags, GlyphRunFlag) +src\gui\text\qrawfont.h: Q_DECLARE_FLAGS(LayoutFlags, LayoutFlag) +src\gui\text\qtextdocument.h: Q_DECLARE_FLAGS(MarkdownFeatures, MarkdownFeature) +src\gui\text\qtextdocument.h: Q_DECLARE_FLAGS(FindFlags, FindFlag) +src\network\kernel\qhostaddress.h: Q_DECLARE_FLAGS(ConversionMode, ConversionModeFlag) +src\network\socket\qabstractsocket.h: Q_DECLARE_FLAGS(BindMode, BindFlag) +src\network\socket\qabstractsocket.h: Q_DECLARE_FLAGS(PauseModes, PauseMode) +src\network\socket\qabstractsocketengine_p.h: Q_DECLARE_FLAGS(PacketHeaderOptions, PacketHeaderOption) +src\gui\text\qtextformat.h: Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag) +src\network\socket\qlocalserver.h: Q_DECLARE_FLAGS(SocketOptions, SocketOption) +src\gui\text\qtextmarkdownimporter_p.h: Q_DECLARE_FLAGS(Features, Feature) +src\network\kernel\qnetworkinterface.h: Q_DECLARE_FLAGS(InterfaceFlags, InterfaceFlag) +src\gui\text\qtextoption.h: Q_DECLARE_FLAGS(Flags, Flag) +src\network\ssl\qssl.h: Q_DECLARE_FLAGS(SslOptions, SslOption) +src\network\kernel\qnetworkproxy.h: Q_DECLARE_FLAGS(Capabilities, Capability) +src\corelib\text\qbytearray.h: Q_DECLARE_FLAGS(Base64Options, Base64Option) +src\corelib\text\qlocale.h: Q_DECLARE_FLAGS(NumberOptions, NumberOption) +src\corelib\text\qlocale.h: Q_DECLARE_FLAGS(DataSizeFormats, DataSizeFormat) +src\corelib\serialization\qcborvalue.h: Q_DECLARE_FLAGS(EncodingOptions, EncodingOption) +src\corelib\serialization\qcborvalue.h: Q_DECLARE_FLAGS(DiagnosticNotationOptions, DiagnosticNotationOption) +src\corelib\serialization\qcborvalue_p.h: Q_DECLARE_FLAGS(ValueFlags, ValueFlag) +src\corelib\time\qdatetimeparser_p.h: Q_DECLARE_FLAGS(Sections, Section) +src\corelib\time\qdatetimeparser_p.h: Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag) +src\corelib\time\qdatetime_p.h: Q_DECLARE_FLAGS(StatusFlags, StatusFlag) +src\corelib\text\qregularexpression.h: Q_DECLARE_FLAGS(PatternOptions, PatternOption) +src\corelib\text\qregularexpression.h: Q_DECLARE_FLAGS(MatchOptions, MatchOption) +src\corelib\text\qstring.h: Q_DECLARE_FLAGS(SectionFlags, SectionFlag) +src\corelib\serialization\qtextstream.h: Q_DECLARE_FLAGS(NumberFlags, NumberFlag) +src\corelib\text\qtextboundaryfinder.h: Q_DECLARE_FLAGS( BoundaryReasons, BoundaryReason ) +src\corelib\text\qunicodetools_p.h:Q_DECLARE_FLAGS(CharAttributeOptions, CharAttributeOption) +src\corelib\tools\qarraydata.h: Q_DECLARE_FLAGS(AllocationOptions, AllocationOption) +src\corelib\tools\qcommandlineoption.h: Q_DECLARE_FLAGS(Flags, Flag) +src\platformheaders\windowsfunctions\qwindowswindowfunctions.h: Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType) +src\platformheaders\xcbfunctions\qxcbwindowfunctions.h: Q_DECLARE_FLAGS(WmWindowTypes, WmWindowType) +src\platformsupport\devicediscovery\qdevicediscovery_p.h: Q_DECLARE_FLAGS(QDeviceTypes, QDeviceType) +src\platformsupport\eglconvenience\qeglplatformcontext_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\platformsupport\fbconvenience\qfbscreen_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\printsupport\dialogs\qabstractprintdialog.h: Q_DECLARE_FLAGS(PrintDialogOptions, PrintDialogOption) +src\platformsupport\kmsconvenience\qkmsdevice_p.h: Q_DECLARE_FLAGS(Rotations, Rotation) +src\sql\kernel\qtsqlglobal.h: Q_DECLARE_FLAGS(ParamType, ParamTypeFlag) +src\widgets\dialogs\qcolordialog.h: Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption) +src\widgets\dialogs\qfiledialog.h: Q_DECLARE_FLAGS(Options, Option) +src\widgets\dialogs\qfilesystemmodel.h: Q_DECLARE_FLAGS(Options, Option) +src\widgets\dialogs\qfontdialog.h: Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption) +src\widgets\effects\qgraphicseffect.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag) +src\widgets\effects\qgraphicseffect.h: Q_DECLARE_FLAGS(BlurHints, BlurHint) +src\widgets\dialogs\qinputdialog.h: Q_DECLARE_FLAGS(InputDialogOptions, InputDialogOption) +src\widgets\dialogs\qmessagebox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton) +src\widgets\dialogs\qwizard.h: Q_DECLARE_FLAGS(WizardOptions, WizardOption) +src\widgets\itemviews\qabstractitemview.h: Q_DECLARE_FLAGS(EditTriggers, EditTrigger) +src\widgets\graphicsview\qgraphicsitem.h: Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag) +src\widgets\itemviews\qfileiconprovider.h: Q_DECLARE_FLAGS(Options, Option) +src\widgets\kernel\qgesture.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag) +src\widgets\kernel\qgesturerecognizer.h: Q_DECLARE_FLAGS(Result, ResultFlag) +src\widgets\graphicsview\qgraphicsscene.h: Q_DECLARE_FLAGS(SceneLayers, SceneLayer) +src\widgets\graphicsview\qgraphicsview.h: Q_DECLARE_FLAGS(CacheMode, CacheModeFlag) +src\widgets\graphicsview\qgraphicsview.h: Q_DECLARE_FLAGS(OptimizationFlags, OptimizationFlag) +src\widgets\kernel\qsizepolicy.h: Q_DECLARE_FLAGS(ControlTypes, ControlType) +src\widgets\itemviews\qtreewidgetitemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag) +src\widgets\kernel\qwidget.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag) +src\widgets\kernel\qwidget_p.h: Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag) +src\widgets\styles\qdrawutil.h: Q_DECLARE_FLAGS(DrawingHints, DrawingHint) +src\widgets\styles\qstyle.h: Q_DECLARE_FLAGS(State, StateFlag) +src\widgets\styles\qstyle.h: Q_DECLARE_FLAGS(SubControls, SubControl) +src\widgets\widgets\qabstractspinbox.h: Q_DECLARE_FLAGS(StepEnabled, StepEnabledFlag) +src\widgets\styles\qstyleoption.h: Q_DECLARE_FLAGS(FrameFeatures, FrameFeature) +src\widgets\styles\qstyleoption.h: Q_DECLARE_FLAGS(ButtonFeatures, ButtonFeature) +src\widgets\styles\qstyleoption.h: Q_DECLARE_FLAGS(CornerWidgets, CornerWidget) +src\widgets\styles\qstyleoption.h: Q_DECLARE_FLAGS(TabFeatures, TabFeature) +src\widgets\styles\qstyleoption.h: Q_DECLARE_FLAGS(ToolBarFeatures, ToolBarFeature) +src\widgets\styles\qstyleoption.h: Q_DECLARE_FLAGS(ViewItemFeatures, ViewItemFeature) +src\widgets\styles\qstyleoption.h: Q_DECLARE_FLAGS(ToolButtonFeatures, ToolButtonFeature) +src\widgets\widgets\qdialogbuttonbox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton) +src\widgets\widgets\qdockwidget.h: Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature) +src\widgets\widgets\qfontcombobox.h: Q_DECLARE_FLAGS(FontFilters, FontFilter) +src\widgets\widgets\qdatetimeedit.h: Q_DECLARE_FLAGS(Sections, Section) +src\widgets\widgets\qmdiarea.h: Q_DECLARE_FLAGS(AreaOptions, AreaOption) +src\widgets\widgets\qmdisubwindow.h: Q_DECLARE_FLAGS(SubWindowOptions, SubWindowOption) +src\widgets\widgets\qmainwindow.h: Q_DECLARE_FLAGS(DockOptions, DockOption) +tests\manual\diaglib\eventfilter.h: Q_DECLARE_FLAGS(EventCategories, EventCategory) +tests\manual\diaglib\eventfilter.h: Q_DECLARE_FLAGS(ObjectTypes, ObjectType) +src\widgets\widgets\qtextedit.h: Q_DECLARE_FLAGS(AutoFormatting, AutoFormattingFlag) +tests\manual\diaglib\qwindowdump.h:Q_DECLARE_FLAGS(FormatWindowOptions, FormatWindowOption) +src\network\access\http2\http2protocol_p.h:Q_DECLARE_FLAGS(FrameFlags, FrameFlag) +src\plugins\bearer\networkmanager\qnetworkmanagerservice.h: Q_DECLARE_FLAGS(ApFlags, ApFlag) +src\plugins\bearer\networkmanager\qnetworkmanagerservice.h: Q_DECLARE_FLAGS(ApSecurityFlags, ApSecurityFlag) +src\plugins\bearer\networkmanager\qnetworkmanagerservice.h: Q_DECLARE_FLAGS(ModemCapabilities, ModemCapability) +src\plugins\platforms\android\qandroidinputcontext.h: Q_DECLARE_FLAGS(HandleModes, HandleMode) +src\plugins\platforms\direct2d\qwindowsdirect2dpaintengine.h: Q_DECLARE_FLAGS(Flags, Flag) +src\plugins\platforms\cocoa\qcocoaintegration.h: Q_DECLARE_FLAGS(Options, Option) +src\plugins\platforms\wasm\qwasmcompositor.h: Q_DECLARE_FLAGS(SubControls, QWasmSubControl) +src\plugins\platforms\wasm\qwasmcompositor.h: Q_DECLARE_FLAGS(StateFlags, QWasmStateFlag) +src\plugins\platforms\cocoa\qcocoawindow.h: Q_DECLARE_FLAGS(RecreationReasons, RecreationReason) +src\plugins\platforms\qnx\qqnxintegration.h: Q_DECLARE_FLAGS(Options, Option) +src\plugins\platforms\xcb\qxcbeventqueue.h: Q_DECLARE_FLAGS(PeekOptions, PeekOption) +src\plugins\platforms\windows\qwindowsopengltester.h: Q_DECLARE_FLAGS(Renderers, Renderer) +src\plugins\platforms\xcb\qxcbwindow.h: Q_DECLARE_FLAGS(NetWmStates, NetWmState) +tests\auto\other\macgui\guitest.h: Q_DECLARE_FLAGS(Directions, Direction) +tests\auto\tools\moc\cxx11-enums.h: Q_DECLARE_FLAGS(ClassFlags, ClassFlag) +tests\auto\tools\moc\cxx11-enums.h: Q_DECLARE_FLAGS(StructFlags, StructFlag) +tests\auto\tools\moc\cxx11-enums.h: Q_DECLARE_FLAGS(ClassFlags, ClassFlag) +tests\auto\tools\moc\namespaced-flags.h: Q_DECLARE_FLAGS( Flags, Flag ) +src\plugins\platforms\eglfs\api\qeglfswindow_p.h: Q_DECLARE_FLAGS(Flags, Flag) +tests\auto\corelib\tools\qsharedpointer\externaltests.h: Q_DECLARE_FLAGS(QtModules, QtModule) +tests\benchmarks\corelib\io\qdiriterator\qfilesystemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag) +tests\benchmarks\widgets\graphicsview\functional\GraphicsViewBenchmark\widgets\settings.h: Q_DECLARE_FLAGS(Options, Option) diff --git a/tests/qflags/grep-results/qtcharts-qflag-grep-result.txt b/tests/qflags/grep-results/qtcharts-qflag-grep-result.txt new file mode 100644 index 00000000..d90b7b22 --- /dev/null +++ b/tests/qflags/grep-results/qtcharts-qflag-grep-result.txt @@ -0,0 +1,4 @@ +src\charts\qchart.h: Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) +src\charts\qchartview.h: Q_DECLARE_FLAGS(RubberBands, RubberBand) +src\charts\qpolarchart.h: Q_DECLARE_FLAGS(PolarOrientations, PolarOrientation) +src\charts\axis\qabstractaxis.h: Q_DECLARE_FLAGS(AxisTypes, AxisType) diff --git a/tests/qflags/grep-results/qtconnectivity-qflag-grep-result.txt b/tests/qflags/grep-results/qtconnectivity-qflag-grep-result.txt new file mode 100644 index 00000000..977ee306 --- /dev/null +++ b/tests/qflags/grep-results/qtconnectivity-qflag-grep-result.txt @@ -0,0 +1,12 @@ +src\bluetooth\qbluetooth.h:Q_DECLARE_FLAGS(SecurityFlags, Security) +src\bluetooth\qbluetooth.h:Q_DECLARE_FLAGS(AttAccessConstraints, AttAccessConstraint) +src\bluetooth\qbluetoothdevicediscoveryagent.h: Q_DECLARE_FLAGS(DiscoveryMethods, DiscoveryMethod) +src\bluetooth\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(ServiceClasses, ServiceClass) +src\bluetooth\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(Fields, Field) +src\bluetooth\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(CoreConfigurations, CoreConfiguration) +src\nfc\qnearfieldmanager.h: Q_DECLARE_FLAGS(TargetAccessModes, TargetAccessMode) +src\nfc\qnearfieldsharemanager.h: Q_DECLARE_FLAGS(ShareModes, ShareMode) +src\nfc\qnearfieldtarget.h: Q_DECLARE_FLAGS(AccessMethods, AccessMethod) +src\bluetooth\qlowenergycharacteristic.h: Q_DECLARE_FLAGS(PropertyTypes, PropertyType) +src\bluetooth\qlowenergycontroller_bluezdbus_p.h: Q_DECLARE_FLAGS(JobFlags, JobFlag) +src\bluetooth\qlowenergyservice.h: Q_DECLARE_FLAGS(ServiceTypes, ServiceType) diff --git a/tests/qflags/grep-results/qtdatavis3d-qflag-grep-result.txt b/tests/qflags/grep-results/qtdatavis3d-qflag-grep-result.txt new file mode 100644 index 00000000..efa8722c --- /dev/null +++ b/tests/qflags/grep-results/qtdatavis3d-qflag-grep-result.txt @@ -0,0 +1,6 @@ +src\datavisualizationqml2\abstractdeclarative_p.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag) +src\datavisualizationqml2\abstractdeclarative_p.h: Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint) +src\datavisualization\data\qsurface3dseries.h: Q_DECLARE_FLAGS(DrawFlags, DrawFlag) +src\datavisualization\engine\qabstract3dgraph.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag) +src\datavisualization\engine\qabstract3dgraph.h: Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint) +src\datavisualization\utils\surfaceobject_p.h: Q_DECLARE_FLAGS(DataDimensions, DataDimension) diff --git a/tests/qflags/grep-results/qtdeclarative-qflag-grep-result.txt b/tests/qflags/grep-results/qtdeclarative-qflag-grep-result.txt new file mode 100644 index 00000000..320342bd --- /dev/null +++ b/tests/qflags/grep-results/qtdeclarative-qflag-grep-result.txt @@ -0,0 +1,52 @@ +src\qmlmodels\qqmlobjectmodel_p.h: Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag) +src\quickshapes\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\qml\animations\qabstractanimationjob_p.h: Q_DECLARE_FLAGS(ChangeTypes, ChangeType) +src\qml\jsapi\qjsengine.h: Q_DECLARE_FLAGS(Extensions, Extension) +src\qml\qml\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\qml\qml\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag) +src\qml\jsruntime\qv4global_p.h:Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag) +src\qml\qml\qqmlpropertydata_p.h: Q_DECLARE_FLAGS(WriteFlags, WriteFlag) +src\qml\qml\qqmlproperty_p.h: Q_DECLARE_FLAGS(BindingFlags, BindingFlag) +src\quick\items\qquickanchors_p.h: Q_DECLARE_FLAGS(Anchors, Anchor) +src\quick\handlers\qquickpointerhandler_p.h: Q_DECLARE_FLAGS(GrabPermissions, GrabPermission) +src\quick\items\qquickevents_p_p.h: Q_DECLARE_FLAGS(States, State) +src\quick\items\qquickevents_p_p.h: Q_DECLARE_FLAGS(DeviceTypes, DeviceType) +src\quick\items\qquickevents_p_p.h: Q_DECLARE_FLAGS(PointerTypes, PointerType) +src\quick\items\qquickevents_p_p.h: Q_DECLARE_FLAGS(Capabilities, CapabilityFlag) +src\quick\items\qquickflickable_p.h: Q_DECLARE_FLAGS(BoundsBehavior, BoundsBehaviorFlag) +src\quick\scenegraph\qsgadaptationlayer_p.h: Q_DECLARE_FLAGS(DirtyShaderFlags, DirtyShaderFlag) +src\quick\scenegraph\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\quick\items\qquickimagebase_p.h: Q_DECLARE_FLAGS(LoadPixmapOptions, LoadPixmapOption) +src\quick\items\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag) +src\quick\util\qquickpixmapcache_p.h: Q_DECLARE_FLAGS(Options, Option) +src\quick\items\qquickitem_p.h: Q_DECLARE_FLAGS(ChangeTypes, ChangeType) +src\quick\items\qquickpainteditem.h: Q_DECLARE_FLAGS(PerformanceHints, PerformanceHint) +src\quick\items\qquicktableview_p_p.h: Q_DECLARE_FLAGS(RebuildOptions, RebuildOption) +src\quick\items\qquicktextnodeengine_p.h: Q_DECLARE_FLAGS(Decorations, Decoration) +src\quick\items\qquickwindow.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption) +src\quick\items\qquickwindow_p.h: Q_DECLARE_FLAGS(FocusOptions, FocusOption) +tests\auto\qml\qmltyperegistrar\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag) +tests\auto\qml\qqmlecmascript\testtypes.h: Q_DECLARE_FLAGS(MyFlags, MyFlag) +tests\auto\qml\qqmllanguage\testtypes.h: Q_DECLARE_FLAGS(MyFlags, MyFlag) +src\plugins\scenegraph\d3d12\qsgd3d12engine_p.h: Q_DECLARE_FLAGS(ClearFlags, ClearFlag) +src\plugins\scenegraph\d3d12\qsgd3d12engine_p.h: Q_DECLARE_FLAGS(TextureCreateFlags, TextureCreateFlag) +src\plugins\scenegraph\d3d12\qsgd3d12engine_p.h: Q_DECLARE_FLAGS(TextureUploadFlags, TextureUploadFlag) +src\plugins\scenegraph\d3d12\qsgd3d12material_p.h: Q_DECLARE_FLAGS(UpdateResults, UpdateResult) +src\quick\scenegraph\coreapi\qsgabstractrenderer.h: Q_DECLARE_FLAGS(ClearMode, ClearModeBit) +src\quick\scenegraph\coreapi\qsgabstractrenderer.h: Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag) +src\quick\scenegraph\coreapi\qsgbatchrenderer_p.h: Q_DECLARE_FLAGS(ClipType, ClipTypeBit) +src\quick\scenegraph\coreapi\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag) +src\quick\scenegraph\coreapi\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent) +src\quick\scenegraph\coreapi\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag) +src\quick\scenegraph\coreapi\qsgmaterialshader.h: Q_DECLARE_FLAGS(DirtyStates, DirtyState) +src\quick\scenegraph\coreapi\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag) +src\quick\scenegraph\coreapi\qsgnode.h: Q_DECLARE_FLAGS(DirtyState, DirtyStateBit) +src\quick\scenegraph\coreapi\qsgrendererinterface.h: Q_DECLARE_FLAGS(ShaderCompilationTypes, ShaderCompilationType) +src\quick\scenegraph\coreapi\qsgrendererinterface.h: Q_DECLARE_FLAGS(ShaderSourceTypes, ShaderSourceType) +src\quick\scenegraph\coreapi\qsgrendernode.h: Q_DECLARE_FLAGS(StateFlags, StateFlag) +src\quick\scenegraph\coreapi\qsgrendernode.h: Q_DECLARE_FLAGS(RenderingFlags, RenderingFlag) +src\quick\scenegraph\util\qsgdepthstencilbuffer_p.h: Q_DECLARE_FLAGS(Attachments, Attachment) +src\quick\scenegraph\util\qsgengine.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption) +src\quick\scenegraph\util\qsgimagenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag) +src\quick\scenegraph\util\qsgsimpletexturenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag) +src\quick\scenegraph\adaptations\software\qsgsoftwareinternalimagenode_p.h: Q_DECLARE_FLAGS(DrawingHints, DrawingHint) diff --git a/tests/qflags/grep-results/qtlocation-qflag-grep-result.txt b/tests/qflags/grep-results/qtlocation-qflag-grep-result.txt new file mode 100644 index 00000000..f4ec60a3 --- /dev/null +++ b/tests/qflags/grep-results/qtlocation-qflag-grep-result.txt @@ -0,0 +1,35 @@ +src\location\qlocation.h:Q_DECLARE_FLAGS(VisibilityScope, Visibility) +src\positioningquick\qdeclarativepositionsource_p.h: Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod) +src\positioning\qgeoareamonitorsource.h: Q_DECLARE_FLAGS(AreaMonitorFeatures, AreaMonitorFeature) +src\positioning\qgeopositioninfosource.h: Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod) +src\location\maps\qabstractgeotilecache_p.h: Q_DECLARE_FLAGS(CacheAreas, CacheArea) +src\location\declarativemaps\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(TravelModes, TravelMode) +src\location\declarativemaps\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(FeatureTypes, FeatureType) +src\location\declarativemaps\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight) +src\location\declarativemaps\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization) +src\location\declarativemaps\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(SegmentDetails, SegmentDetail) +src\location\declarativemaps\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(ManeuverDetails, ManeuverDetail) +src\location\declarativemaps\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature) +src\location\declarativemaps\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature) +src\location\declarativemaps\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(MappingFeatures, MappingFeature) +src\location\declarativemaps\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature) +src\location\declarativemaps\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(NavigationFeatures, NavigationFeature) +src\location\maps\qgeomap_p.h: Q_DECLARE_FLAGS(ItemTypes, ItemType) +src\location\maps\qgeomap_p.h: Q_DECLARE_FLAGS(Capabilities, Capability) +src\location\declarativemaps\qgeomapobject_p.h: Q_DECLARE_FLAGS(Features, Feature) +src\location\declarativemaps\qquickgeomapgesturearea_p.h: Q_DECLARE_FLAGS(AcceptedGestures, GeoMapGesture) +src\location\maps\qgeorouterequest.h: Q_DECLARE_FLAGS(TravelModes, TravelMode) +src\location\maps\qgeorouterequest.h: Q_DECLARE_FLAGS(FeatureTypes, FeatureType) +src\location\maps\qgeorouterequest.h: Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight) +src\location\maps\qgeorouterequest.h: Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization) +src\location\maps\qgeorouterequest.h: Q_DECLARE_FLAGS(SegmentDetails, SegmentDetail) +src\location\maps\qgeorouterequest.h: Q_DECLARE_FLAGS(ManeuverDetails, ManeuverDetail) +src\location\maps\qgeoserviceprovider.h: Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature) +src\location\maps\qgeoserviceprovider.h: Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature) +src\location\maps\qgeoserviceprovider.h: Q_DECLARE_FLAGS(MappingFeatures, MappingFeature) +src\location\maps\qgeoserviceprovider.h: Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature) +src\location\maps\qgeoserviceprovider.h: Q_DECLARE_FLAGS(NavigationFeatures, NavigationFeature) +src\plugins\geoservices\mapboxgl\qgeomapmapboxgl_p.h: Q_DECLARE_FLAGS(SyncStates, SyncState); +src\plugins\position\geoclue\qgeocluemaster.h: Q_DECLARE_FLAGS(ResourceFlags, ResourceFlag) +src\plugins\position\geoclue\qgeopositioninfosource_geocluemaster.h: Q_DECLARE_FLAGS(PositionFields, PositionField) +src\plugins\position\geoclue\qgeopositioninfosource_geocluemaster.h: Q_DECLARE_FLAGS(VelocityFields, VelocityField) diff --git a/tests/qflags/grep-results/qtmultimedia-qflag-grep-result.txt b/tests/qflags/grep-results/qtmultimedia-qflag-grep-result.txt new file mode 100644 index 00000000..b883953c --- /dev/null +++ b/tests/qflags/grep-results/qtmultimedia-qflag-grep-result.txt @@ -0,0 +1,11 @@ +src\multimediawidgets\qpaintervideosurface_p.h: Q_DECLARE_FLAGS(ShaderTypes, ShaderType) +src\qtmultimediaquicktools\qsgvideonode_p.h: Q_DECLARE_FLAGS(FrameFlags, FrameFlag) +src\multimedia\qmediaserviceproviderplugin.h: Q_DECLARE_FLAGS(Features, Feature) +src\multimedia\camera\qcamera.h: Q_DECLARE_FLAGS(CaptureModes, CaptureMode) +src\multimedia\camera\qcamera.h: Q_DECLARE_FLAGS(LockTypes, LockType) +src\multimedia\camera\qcameraexposure.h: Q_DECLARE_FLAGS(FlashModes, FlashMode) +src\multimedia\camera\qcamerafocus.h: Q_DECLARE_FLAGS(FocusModes, FocusMode) +src\multimedia\camera\qcameraimagecapture.h: Q_DECLARE_FLAGS(CaptureDestinations, CaptureDestination) +src\multimedia\playback\qmediaplayer.h: Q_DECLARE_FLAGS(Flags, Flag) +src\multimedia\audio\qsoundeffect_pulse_p.h: Q_DECLARE_FLAGS(EmptyStreamOptions, EmptyStreamOption) +src\multimedia\video\qabstractvideofilter.h: Q_DECLARE_FLAGS(RunFlags, RunFlag) diff --git a/tests/qflags/grep-results/qtnetworkauth-qflag-grep-result.txt b/tests/qflags/grep-results/qtnetworkauth-qflag-grep-result.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/qflags/grep-results/qtpurchasing-qflag-grep-result.txt b/tests/qflags/grep-results/qtpurchasing-qflag-grep-result.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/qflags/grep-results/qtquick3d-qflag-grep-result.txt b/tests/qflags/grep-results/qtquick3d-qflag-grep-result.txt new file mode 100644 index 00000000..d6ba3c42 --- /dev/null +++ b/tests/qflags/grep-results/qtquick3d-qflag-grep-result.txt @@ -0,0 +1,22 @@ +src\render\qssgrenderbasetypes_p.h:Q_DECLARE_FLAGS(QSSGRenderContextTypes, QSSGRenderContextType) +src\render\qssgrenderbasetypes_p.h:Q_DECLARE_FLAGS(QSSGRenderClearFlags, QSSGRenderClearValues) +src\render\qssgrenderbasetypes_p.h:Q_DECLARE_FLAGS(QSSGRenderSyncFlags, QSSGRenderSyncValues) +src\render\qssgrenderbasetypes_p.h:Q_DECLARE_FLAGS(QSSGRenderCommandFlushFlags, QSSGRenderCommandFlushValues) +src\render\qssgrenderbasetypes_p.h:Q_DECLARE_FLAGS(QSSGRenderBufferAccessFlags, QSSGRenderBufferAccessTypeValues) +src\render\qssgrenderbasetypes_p.h:Q_DECLARE_FLAGS(QSSGRenderBufferBarrierFlags, QSSGRenderBufferBarrierValues) +src\render\qssgrenderbasetypes_p.h:Q_DECLARE_FLAGS(QSSGRenderShaderTypeFlags, QSSGRenderShaderTypeValue) +src\runtimerender\qssgrenderclippingfrustum_p.h:Q_DECLARE_FLAGS(QSSGRenderBoxEdge, BoxEdgeFlagValues) +src\quick3d\qquick3dabstractlight_p.h: Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag) +src\runtimerender\qssgrendershadercache_p.h:Q_DECLARE_FLAGS(QSSGShaderCacheProgramFlags, ShaderCacheProgramFlagValues) +src\runtimerender\qssgrendershadercodegeneratorv2_p.h:Q_DECLARE_FLAGS(QSSGShaderGeneratorStageFlags, QSSGShaderGeneratorStage) +src\quick3d\qquick3dobject_p.h: Q_DECLARE_FLAGS(ChangeTypes, ChangeType) +src\quick3d\qquick3dshaderutils_p.h: Q_DECLARE_FLAGS(MaterialShaderKeyFlags, MaterialShaderKeyValues) +src\quick3d\qquick3dtexture_p.h: Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag) +src\runtimerender\graphobjects\qssgrendercustommaterial_p.h: Q_DECLARE_FLAGS(MaterialShaderKeyFlags, MaterialShaderKeyValues) +src\runtimerender\graphobjects\qssgrendercustommaterial_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\runtimerender\graphobjects\qssgrendereffect_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\runtimerender\graphobjects\qssgrenderimage_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\runtimerender\graphobjects\qssgrendernode_p.h: Q_DECLARE_FLAGS(Flags, Flag) +src\plugins\assetimporters\uip\uippresentation.h: Q_DECLARE_FLAGS(PropSetFlags, PropSetFlag) +src\plugins\assetimporters\uip\uippresentation.h: Q_DECLARE_FLAGS(Flags, NodeFlag) +src\plugins\assetimporters\uip\uippresentation.h: Q_DECLARE_FLAGS(Flags, Flag) diff --git a/tests/qflags/grep-results/qtquickcontrols-qflag-grep-result.txt b/tests/qflags/grep-results/qtquickcontrols-qflag-grep-result.txt new file mode 100644 index 00000000..e0f4bcdb --- /dev/null +++ b/tests/qflags/grep-results/qtquickcontrols-qflag-grep-result.txt @@ -0,0 +1 @@ +src\dialogs\qquickabstractdialog_p.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton) diff --git a/tests/qflags/grep-results/qtquickcontrols2-qflag-grep-result.txt b/tests/qflags/grep-results/qtquickcontrols2-qflag-grep-result.txt new file mode 100644 index 00000000..e0a46ddb --- /dev/null +++ b/tests/qflags/grep-results/qtquickcontrols2-qflag-grep-result.txt @@ -0,0 +1,2 @@ +src\quicktemplates2\qquickpopup_p.h: Q_DECLARE_FLAGS(ClosePolicy, ClosePolicyFlag) +tests\manual\gifs\eventcapturer.h: Q_DECLARE_FLAGS(MoveEventTrimFlags, MoveEventTrimFlag) diff --git a/tests/qflags/grep-results/qtquicktimeline-qflag-grep-result.txt b/tests/qflags/grep-results/qtquicktimeline-qflag-grep-result.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/qflags/grep-results/qtremoteobjects-qflag-grep-result.txt b/tests/qflags/grep-results/qtremoteobjects-qflag-grep-result.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/qflags/grep-results/qtsensors-qflag-grep-result.txt b/tests/qflags/grep-results/qtsensors-qflag-grep-result.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/qflags/grep-results/qtserialbus-qflag-grep-result.txt b/tests/qflags/grep-results/qtserialbus-qflag-grep-result.txt new file mode 100644 index 00000000..aec2346a --- /dev/null +++ b/tests/qflags/grep-results/qtserialbus-qflag-grep-result.txt @@ -0,0 +1,6 @@ +src\serialbus\qcanbusdevice.h: Q_DECLARE_FLAGS(FormatFilters, FormatFilter) +src\serialbus\qcanbusdevice.h: Q_DECLARE_FLAGS(Directions, Direction) +src\serialbus\qcanbusframe.h: Q_DECLARE_FLAGS(FrameErrors, FrameError) +src\plugins\canbus\passthrucan\j2534passthru.h: Q_DECLARE_FLAGS(RxStatus, RxStatusBit) +src\plugins\canbus\passthrucan\j2534passthru.h: Q_DECLARE_FLAGS(TxFlags, TxFlag) +src\plugins\canbus\passthrucan\j2534passthru.h: Q_DECLARE_FLAGS(ConnectFlags, ConnectFlag) diff --git a/tests/qflags/grep-results/qtserialport-qflag-grep-result.txt b/tests/qflags/grep-results/qtserialport-qflag-grep-result.txt new file mode 100644 index 00000000..45943370 --- /dev/null +++ b/tests/qflags/grep-results/qtserialport-qflag-grep-result.txt @@ -0,0 +1,2 @@ +src\serialport\qserialport.h: Q_DECLARE_FLAGS(Directions, Direction) +src\serialport\qserialport.h: Q_DECLARE_FLAGS(PinoutSignals, PinoutSignal) diff --git a/tests/qflags/grep-results/qtspeech-qflag-grep-result.txt b/tests/qflags/grep-results/qtspeech-qflag-grep-result.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/qflags/grep-results/qtsvg-qflag-grep-result.txt b/tests/qflags/grep-results/qtsvg-qflag-grep-result.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/qflags/grep-results/qtsystems-qflag-grep-result.txt b/tests/qflags/grep-results/qtsystems-qflag-grep-result.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/qflags/qflags_modules_analysis.json b/tests/qflags/qflags_modules_analysis.json new file mode 100644 index 00000000..c26c636f --- /dev/null +++ b/tests/qflags/qflags_modules_analysis.json @@ -0,0 +1,1920 @@ +{ + "flag_and_module_identified": [ + { + "qflag_class": "ChangeFlags", + "enum_class": "ChangeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\core\\changes\\qscenechange.h:Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DCore", + "module_path": "../../PyQt5-stubs/Qt3DCore.pyi" + }, + { + "qflag_class": "DeliveryFlags", + "enum_class": "DeliveryFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\core\\changes\\qscenechange.h: Q_DECLARE_FLAGS(DeliveryFlags, DeliveryFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DCore", + "module_path": "../../PyQt5-stubs/Qt3DCore.pyi" + }, + { + "qflag_class": "BufferTypeFlags", + "enum_class": "BufferType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\render\\framegraph\\qclearbuffers.h: Q_DECLARE_FLAGS(BufferTypeFlags, BufferType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DRender", + "module_path": "../../PyQt5-stubs/Qt3DRender.pyi" + }, + { + "qflag_class": "Operations", + "enum_class": "Operation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\render\\framegraph\\qmemorybarrier.h: Q_DECLARE_FLAGS(Operations, Operation)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DRender", + "module_path": "../../PyQt5-stubs/Qt3DRender.pyi" + }, + { + "qflag_class": "AnimationOptions", + "enum_class": "AnimationOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\qchart.h: Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi" + }, + { + "qflag_class": "RubberBands", + "enum_class": "RubberBand", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\qchartview.h: Q_DECLARE_FLAGS(RubberBands, RubberBand)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi" + }, + { + "qflag_class": "PolarOrientations", + "enum_class": "PolarOrientation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\qpolarchart.h: Q_DECLARE_FLAGS(PolarOrientations, PolarOrientation)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi" + }, + { + "qflag_class": "AxisTypes", + "enum_class": "AxisType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\axis\\qabstractaxis.h: Q_DECLARE_FLAGS(AxisTypes, AxisType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi" + }, + { + "qflag_class": "TargetAccessModes", + "enum_class": "TargetAccessMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\nfc\\qnearfieldmanager.h: Q_DECLARE_FLAGS(TargetAccessModes, TargetAccessMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNfc", + "module_path": "../../PyQt5-stubs/QtNfc.pyi" + }, + { + "qflag_class": "ShareModes", + "enum_class": "ShareMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\nfc\\qnearfieldsharemanager.h: Q_DECLARE_FLAGS(ShareModes, ShareMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNfc", + "module_path": "../../PyQt5-stubs/QtNfc.pyi" + }, + { + "qflag_class": "AccessMethods", + "enum_class": "AccessMethod", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\nfc\\qnearfieldtarget.h: Q_DECLARE_FLAGS(AccessMethods, AccessMethod)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNfc", + "module_path": "../../PyQt5-stubs/QtNfc.pyi" + }, + { + "qflag_class": "SecurityFlags", + "enum_class": "Security", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetooth.h:Q_DECLARE_FLAGS(SecurityFlags, Security)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "AttAccessConstraints", + "enum_class": "AttAccessConstraint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetooth.h:Q_DECLARE_FLAGS(AttAccessConstraints, AttAccessConstraint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "DiscoveryMethods", + "enum_class": "DiscoveryMethod", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdevicediscoveryagent.h: Q_DECLARE_FLAGS(DiscoveryMethods, DiscoveryMethod)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "ServiceClasses", + "enum_class": "ServiceClass", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(ServiceClasses, ServiceClass)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "Fields", + "enum_class": "Field", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(Fields, Field)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "CoreConfigurations", + "enum_class": "CoreConfiguration", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(CoreConfigurations, CoreConfiguration)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "PropertyTypes", + "enum_class": "PropertyType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qlowenergycharacteristic.h: Q_DECLARE_FLAGS(PropertyTypes, PropertyType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "ServiceTypes", + "enum_class": "ServiceType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qlowenergyservice.h: Q_DECLARE_FLAGS(ServiceTypes, ServiceType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "SelectionFlags", + "enum_class": "SelectionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualizationqml2\\abstractdeclarative_p.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)", + "src\\datavisualization\\engine\\qabstract3dgraph.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDataVisualization", + "module_path": "../../PyQt5-stubs/QtDataVisualization.pyi" + }, + { + "qflag_class": "OptimizationHints", + "enum_class": "OptimizationHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualizationqml2\\abstractdeclarative_p.h: Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint)", + "src\\datavisualization\\engine\\qabstract3dgraph.h: Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDataVisualization", + "module_path": "../../PyQt5-stubs/QtDataVisualization.pyi" + }, + { + "qflag_class": "DrawFlags", + "enum_class": "DrawFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualization\\data\\qsurface3dseries.h: Q_DECLARE_FLAGS(DrawFlags, DrawFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDataVisualization", + "module_path": "../../PyQt5-stubs/QtDataVisualization.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 4, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 4, + "module_idx": 1, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 4, + "module_idx": 2, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 4, + "module_idx": 3, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQml", + "module_path": "../../PyQt5-stubs/QtQml.pyi" + }, + { + "qflag_class": "Extensions", + "enum_class": "Extension", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\qml\\jsapi\\qjsengine.h: Q_DECLARE_FLAGS(Extensions, Extension)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQml", + "module_path": "../../PyQt5-stubs/QtQml.pyi" + }, + { + "qflag_class": "PerformanceHints", + "enum_class": "PerformanceHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickpainteditem.h: Q_DECLARE_FLAGS(PerformanceHints, PerformanceHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "CreateTextureOptions", + "enum_class": "CreateTextureOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickwindow.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)", + "src\\quick\\scenegraph\\util\\qsgengine.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "CreateTextureOptions", + "enum_class": "CreateTextureOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickwindow.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)", + "src\\quick\\scenegraph\\util\\qsgengine.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 1, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "ClearMode", + "enum_class": "ClearModeBit", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgabstractrenderer.h: Q_DECLARE_FLAGS(ClearMode, ClearModeBit)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "MatrixTransformFlags", + "enum_class": "MatrixTransformFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgabstractrenderer.h: Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "ColorMask", + "enum_class": "ColorMaskComponent", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "DirtyStates", + "enum_class": "DirtyState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgmaterialshader.h: Q_DECLARE_FLAGS(DirtyStates, DirtyState)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "DirtyState", + "enum_class": "DirtyStateBit", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(DirtyState, DirtyStateBit)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "ShaderCompilationTypes", + "enum_class": "ShaderCompilationType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendererinterface.h: Q_DECLARE_FLAGS(ShaderCompilationTypes, ShaderCompilationType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "ShaderSourceTypes", + "enum_class": "ShaderSourceType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendererinterface.h: Q_DECLARE_FLAGS(ShaderSourceTypes, ShaderSourceType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "StateFlags", + "enum_class": "StateFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendernode.h: Q_DECLARE_FLAGS(StateFlags, StateFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "RenderingFlags", + "enum_class": "RenderingFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendernode.h: Q_DECLARE_FLAGS(RenderingFlags, RenderingFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "TextureCoordinatesTransformMode", + "enum_class": "TextureCoordinatesTransformFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\util\\qsgimagenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)", + "src\\quick\\scenegraph\\util\\qsgsimpletexturenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "TextureCoordinatesTransformMode", + "enum_class": "TextureCoordinatesTransformFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\util\\qsgimagenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)", + "src\\quick\\scenegraph\\util\\qsgsimpletexturenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 1, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "VisibilityScope", + "enum_class": "Visibility", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\qlocation.h:Q_DECLARE_FLAGS(VisibilityScope, Visibility)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "PositioningMethods", + "enum_class": "PositioningMethod", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\positioningquick\\qdeclarativepositionsource_p.h: Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod)", + "src\\positioning\\qgeopositioninfosource.h: Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtPositioning", + "module_path": "../../PyQt5-stubs/QtPositioning.pyi" + }, + { + "qflag_class": "AreaMonitorFeatures", + "enum_class": "AreaMonitorFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\positioning\\qgeoareamonitorsource.h: Q_DECLARE_FLAGS(AreaMonitorFeatures, AreaMonitorFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtPositioning", + "module_path": "../../PyQt5-stubs/QtPositioning.pyi" + }, + { + "qflag_class": "TravelModes", + "enum_class": "TravelMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(TravelModes, TravelMode)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(TravelModes, TravelMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "FeatureTypes", + "enum_class": "FeatureType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(FeatureTypes, FeatureType)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(FeatureTypes, FeatureType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "FeatureWeights", + "enum_class": "FeatureWeight", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "RouteOptimizations", + "enum_class": "RouteOptimization", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "SegmentDetails", + "enum_class": "SegmentDetail", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(SegmentDetails, SegmentDetail)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(SegmentDetails, SegmentDetail)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "ManeuverDetails", + "enum_class": "ManeuverDetail", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(ManeuverDetails, ManeuverDetail)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(ManeuverDetails, ManeuverDetail)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "RoutingFeatures", + "enum_class": "RoutingFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "GeocodingFeatures", + "enum_class": "GeocodingFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "MappingFeatures", + "enum_class": "MappingFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(MappingFeatures, MappingFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(MappingFeatures, MappingFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "PlacesFeatures", + "enum_class": "PlacesFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "NavigationFeatures", + "enum_class": "NavigationFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(NavigationFeatures, NavigationFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(NavigationFeatures, NavigationFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "CaptureModes", + "enum_class": "CaptureMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcamera.h: Q_DECLARE_FLAGS(CaptureModes, CaptureMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "LockTypes", + "enum_class": "LockType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcamera.h: Q_DECLARE_FLAGS(LockTypes, LockType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "FlashModes", + "enum_class": "FlashMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcameraexposure.h: Q_DECLARE_FLAGS(FlashModes, FlashMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "FocusModes", + "enum_class": "FocusMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcamerafocus.h: Q_DECLARE_FLAGS(FocusModes, FocusMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "CaptureDestinations", + "enum_class": "CaptureDestination", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcameraimagecapture.h: Q_DECLARE_FLAGS(CaptureDestinations, CaptureDestination)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\playback\\qmediaplayer.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "RunFlags", + "enum_class": "RunFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\video\\qabstractvideofilter.h: Q_DECLARE_FLAGS(RunFlags, RunFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "Directions", + "enum_class": "Direction", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\serialport\\qserialport.h: Q_DECLARE_FLAGS(Directions, Direction)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtSerialPort", + "module_path": "../../PyQt5-stubs/QtSerialPort.pyi" + }, + { + "qflag_class": "PinoutSignals", + "enum_class": "PinoutSignal", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\serialport\\qserialport.h: Q_DECLARE_FLAGS(PinoutSignals, PinoutSignal)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtSerialPort", + "module_path": "../../PyQt5-stubs/QtSerialPort.pyi" + } + ], + "flag_without_module": [ + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\animation\\frontend\\qanimationcallback.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "BackendNodeDirtySet", + "enum_class": "BackendNodeDirtyFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\render\\backend\\abstractrenderer_p.h: Q_DECLARE_FLAGS(BackendNodeDirtySet, BackendNodeDirtyFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "DirtyFlags", + "enum_class": "DirtyFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\render\\texture\\texture_p.h: Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)", + "src\\quick3d\\imports\\scene3d\\scene3dview_p.h: Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "JobFlags", + "enum_class": "JobFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qlowenergycontroller_bluezdbus_p.h: Q_DECLARE_FLAGS(JobFlags, JobFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "DataDimensions", + "enum_class": "DataDimension", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualization\\utils\\surfaceobject_p.h: Q_DECLARE_FLAGS(DataDimensions, DataDimension)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "ReleaseFlags", + "enum_class": "ReleaseFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\qmlmodels\\qqmlobjectmodel_p.h: Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "ChangeTypes", + "enum_class": "ChangeType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\qml\\animations\\qabstractanimationjob_p.h: Q_DECLARE_FLAGS(ChangeTypes, ChangeType)", + "src\\quick\\items\\qquickitem_p.h: Q_DECLARE_FLAGS(ChangeTypes, ChangeType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "PropertyFlags", + "enum_class": "PropertyFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\qml\\jsruntime\\qv4global_p.h:Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "WriteFlags", + "enum_class": "WriteFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\qml\\qml\\qqmlpropertydata_p.h: Q_DECLARE_FLAGS(WriteFlags, WriteFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "BindingFlags", + "enum_class": "BindingFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\qml\\qml\\qqmlproperty_p.h: Q_DECLARE_FLAGS(BindingFlags, BindingFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "Anchors", + "enum_class": "Anchor", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickanchors_p.h: Q_DECLARE_FLAGS(Anchors, Anchor)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "GrabPermissions", + "enum_class": "GrabPermission", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\handlers\\qquickpointerhandler_p.h: Q_DECLARE_FLAGS(GrabPermissions, GrabPermission)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "States", + "enum_class": "State", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickevents_p_p.h: Q_DECLARE_FLAGS(States, State)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "DeviceTypes", + "enum_class": "DeviceType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickevents_p_p.h: Q_DECLARE_FLAGS(DeviceTypes, DeviceType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "PointerTypes", + "enum_class": "PointerType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickevents_p_p.h: Q_DECLARE_FLAGS(PointerTypes, PointerType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "Capabilities", + "enum_class": "CapabilityFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickevents_p_p.h: Q_DECLARE_FLAGS(Capabilities, CapabilityFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "BoundsBehavior", + "enum_class": "BoundsBehaviorFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickflickable_p.h: Q_DECLARE_FLAGS(BoundsBehavior, BoundsBehaviorFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "DirtyShaderFlags", + "enum_class": "DirtyShaderFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\qsgadaptationlayer_p.h: Q_DECLARE_FLAGS(DirtyShaderFlags, DirtyShaderFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "LoadPixmapOptions", + "enum_class": "LoadPixmapOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickimagebase_p.h: Q_DECLARE_FLAGS(LoadPixmapOptions, LoadPixmapOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "Options", + "enum_class": "Option", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\util\\qquickpixmapcache_p.h: Q_DECLARE_FLAGS(Options, Option)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "RebuildOptions", + "enum_class": "RebuildOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquicktableview_p_p.h: Q_DECLARE_FLAGS(RebuildOptions, RebuildOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "Decorations", + "enum_class": "Decoration", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquicktextnodeengine_p.h: Q_DECLARE_FLAGS(Decorations, Decoration)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "FocusOptions", + "enum_class": "FocusOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickwindow_p.h: Q_DECLARE_FLAGS(FocusOptions, FocusOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "MyFlags", + "enum_class": "MyFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "tests\\auto\\qml\\qqmlecmascript\\testtypes.h: Q_DECLARE_FLAGS(MyFlags, MyFlag)", + "tests\\auto\\qml\\qqmllanguage\\testtypes.h: Q_DECLARE_FLAGS(MyFlags, MyFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "ClearFlags", + "enum_class": "ClearFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\plugins\\scenegraph\\d3d12\\qsgd3d12engine_p.h: Q_DECLARE_FLAGS(ClearFlags, ClearFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "TextureCreateFlags", + "enum_class": "TextureCreateFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\plugins\\scenegraph\\d3d12\\qsgd3d12engine_p.h: Q_DECLARE_FLAGS(TextureCreateFlags, TextureCreateFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "TextureUploadFlags", + "enum_class": "TextureUploadFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\plugins\\scenegraph\\d3d12\\qsgd3d12engine_p.h: Q_DECLARE_FLAGS(TextureUploadFlags, TextureUploadFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "UpdateResults", + "enum_class": "UpdateResult", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\plugins\\scenegraph\\d3d12\\qsgd3d12material_p.h: Q_DECLARE_FLAGS(UpdateResults, UpdateResult)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "ClipType", + "enum_class": "ClipTypeBit", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgbatchrenderer_p.h: Q_DECLARE_FLAGS(ClipType, ClipTypeBit)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "Attachments", + "enum_class": "Attachment", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\util\\qsgdepthstencilbuffer_p.h: Q_DECLARE_FLAGS(Attachments, Attachment)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "DrawingHints", + "enum_class": "DrawingHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\adaptations\\software\\qsgsoftwareinternalimagenode_p.h: Q_DECLARE_FLAGS(DrawingHints, DrawingHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "CacheAreas", + "enum_class": "CacheArea", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\maps\\qabstractgeotilecache_p.h: Q_DECLARE_FLAGS(CacheAreas, CacheArea)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "ItemTypes", + "enum_class": "ItemType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\maps\\qgeomap_p.h: Q_DECLARE_FLAGS(ItemTypes, ItemType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "Capabilities", + "enum_class": "Capability", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\maps\\qgeomap_p.h: Q_DECLARE_FLAGS(Capabilities, Capability)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "Features", + "enum_class": "Feature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qgeomapobject_p.h: Q_DECLARE_FLAGS(Features, Feature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "AcceptedGestures", + "enum_class": "GeoMapGesture", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qquickgeomapgesturearea_p.h: Q_DECLARE_FLAGS(AcceptedGestures, GeoMapGesture)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "SyncStates", + "enum_class": "SyncState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\plugins\\geoservices\\mapboxgl\\qgeomapmapboxgl_p.h: Q_DECLARE_FLAGS(SyncStates, SyncState);" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "ResourceFlags", + "enum_class": "ResourceFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\plugins\\position\\geoclue\\qgeocluemaster.h: Q_DECLARE_FLAGS(ResourceFlags, ResourceFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "PositionFields", + "enum_class": "PositionField", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\plugins\\position\\geoclue\\qgeopositioninfosource_geocluemaster.h: Q_DECLARE_FLAGS(PositionFields, PositionField)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "VelocityFields", + "enum_class": "VelocityField", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\plugins\\position\\geoclue\\qgeopositioninfosource_geocluemaster.h: Q_DECLARE_FLAGS(VelocityFields, VelocityField)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "ShaderTypes", + "enum_class": "ShaderType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimediawidgets\\qpaintervideosurface_p.h: Q_DECLARE_FLAGS(ShaderTypes, ShaderType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "FrameFlags", + "enum_class": "FrameFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\qtmultimediaquicktools\\qsgvideonode_p.h: Q_DECLARE_FLAGS(FrameFlags, FrameFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "Features", + "enum_class": "Feature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\qmediaserviceproviderplugin.h: Q_DECLARE_FLAGS(Features, Feature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + }, + { + "qflag_class": "EmptyStreamOptions", + "enum_class": "EmptyStreamOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\audio\\qsoundeffect_pulse_p.h: Q_DECLARE_FLAGS(EmptyStreamOptions, EmptyStreamOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 0, + "module_idx": -1, + "module_name": "", + "module_path": "" + } + ] +} \ No newline at end of file diff --git a/tests/qflags/qflags_process_result.json b/tests/qflags/qflags_process_result.json new file mode 100644 index 00000000..c74657ad --- /dev/null +++ b/tests/qflags/qflags_process_result.json @@ -0,0 +1,4181 @@ +{ + "qflag_already_done": [ + { + "qflag_class": "RegisterOptions", + "enum_class": "RegisterOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\dbus\\qdbusconnection.h: Q_DECLARE_FLAGS(RegisterOptions, RegisterOption)" + ], + "qflag_full_class_name": "QDBusConnection.RegisterOptions", + "enum_full_class_name": "QDBusConnection.RegisterOption", + "enum_value1": "ExportAdaptors", + "enum_value2": "ExportScriptableSlots", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDBus", + "module_path": "../../PyQt5-stubs/QtDBus.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": true, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ConnectionCapabilities", + "enum_class": "ConnectionCapability", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\dbus\\qdbusconnection.h: Q_DECLARE_FLAGS(ConnectionCapabilities, ConnectionCapability)" + ], + "qflag_full_class_name": "QDBusConnection.ConnectionCapabilities", + "enum_full_class_name": "QDBusConnection.ConnectionCapability", + "enum_value1": "UnixFileDescriptorPassing", + "enum_value2": "UnixFileDescriptorPassing", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDBus", + "module_path": "../../PyQt5-stubs/QtDBus.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "FormatOptions", + "enum_class": "FormatOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qgl.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption)", + "src\\gui\\kernel\\qsurfaceformat.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption)" + ], + "qflag_full_class_name": "QSurfaceFormat.FormatOptions", + "enum_full_class_name": "QSurfaceFormat.FormatOption", + "enum_value1": "StereoBuffers", + "enum_value2": "DebugContext", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "FormatOptions", + "enum_class": "FormatOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qgl.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption)", + "src\\gui\\kernel\\qsurfaceformat.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption)" + ], + "qflag_full_class_name": "QGL.FormatOptions", + "enum_full_class_name": "QGL.FormatOption", + "enum_value1": "DoubleBuffer", + "enum_value2": "DepthBuffer", + "module_count": 1, + "module_idx": 0, + "module_name": "QtOpenGL", + "module_path": "../../PyQt5-stubs/QtOpenGL.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "OpenGLVersionFlags", + "enum_class": "OpenGLVersionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qgl.h: Q_DECLARE_FLAGS(OpenGLVersionFlags, OpenGLVersionFlag)" + ], + "qflag_full_class_name": "QGLFormat.OpenGLVersionFlags", + "enum_full_class_name": "QGLFormat.OpenGLVersionFlag", + "enum_value1": "OpenGL_Version_None", + "enum_value2": "OpenGL_Version_1_1", + "module_count": 1, + "module_idx": 0, + "module_name": "QtOpenGL", + "module_path": "../../PyQt5-stubs/QtOpenGL.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "BindOptions", + "enum_class": "BindOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qgl.h: Q_DECLARE_FLAGS(BindOptions, BindOption)", + "src\\gui\\opengl\\qopengltextureuploader_p.h: Q_DECLARE_FLAGS(BindOptions, BindOption)" + ], + "qflag_full_class_name": "QGLContext.BindOptions", + "enum_full_class_name": "QGLContext.BindOption", + "enum_value1": "NoBindOption", + "enum_value2": "InvertedYBindOption", + "module_count": 1, + "module_idx": 0, + "module_name": "QtOpenGL", + "module_path": "../../PyQt5-stubs/QtOpenGL.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ShaderType", + "enum_class": "ShaderTypeBit", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qglshaderprogram.h: Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)", + "src\\gui\\opengl\\qopenglshaderprogram.h: Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)" + ], + "qflag_full_class_name": "QOpenGLShader.ShaderType", + "enum_full_class_name": "QOpenGLShader.ShaderTypeBit", + "enum_value1": "Vertex", + "enum_value2": "Fragment", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "WatchMode", + "enum_class": "WatchModeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\dbus\\qdbusservicewatcher.h: Q_DECLARE_FLAGS(WatchMode, WatchModeFlag)" + ], + "qflag_full_class_name": "QDBusServiceWatcher.WatchMode", + "enum_full_class_name": "QDBusServiceWatcher.WatchModeFlag", + "enum_value1": "WatchForRegistration", + "enum_value2": "WatchForUnregistration", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDBus", + "module_path": "../../PyQt5-stubs/QtDBus.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": true, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ConversionFlags", + "enum_class": "ConversionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\codecs\\qtextcodec.h: Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)", + "src\\corelib\\codecs\\qtextcodec_p.h: Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)" + ], + "qflag_full_class_name": "QTextCodec.ConversionFlags", + "enum_full_class_name": "QTextCodec.ConversionFlag", + "enum_value1": "DefaultConversion", + "enum_value2": "ConvertInvalidToNull", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "CheckIndexOptions", + "enum_class": "CheckIndexOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\itemmodels\\qabstractitemmodel.h: Q_DECLARE_FLAGS(CheckIndexOptions, CheckIndexOption)" + ], + "qflag_full_class_name": "QAbstractItemModel.CheckIndexOptions", + "enum_full_class_name": "QAbstractItemModel.CheckIndexOption", + "enum_value1": "NoOption", + "enum_value2": "IndexIsValid", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false + }, + { + "qflag_class": "Filters", + "enum_class": "Filter", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qdir.h: Q_DECLARE_FLAGS(Filters, Filter)" + ], + "qflag_full_class_name": "QDir.Filters", + "enum_full_class_name": "QDir.Filter", + "enum_value1": "Dirs", + "enum_value2": "Files", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "SortFlags", + "enum_class": "SortFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qdir.h: Q_DECLARE_FLAGS(SortFlags, SortFlag)" + ], + "qflag_full_class_name": "QDir.SortFlags", + "enum_full_class_name": "QDir.SortFlag", + "enum_value1": "Name", + "enum_value2": "Time", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "IteratorFlags", + "enum_class": "IteratorFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qdiriterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)", + "src\\widgets\\itemviews\\qtreewidgetitemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)", + "tests\\benchmarks\\corelib\\io\\qdiriterator\\qfilesystemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)" + ], + "qflag_full_class_name": "QDirIterator.IteratorFlags", + "enum_full_class_name": "QDirIterator.IteratorFlag", + "enum_value1": "NoIteratorFlags", + "enum_value2": "FollowSymlinks", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "IteratorFlags", + "enum_class": "IteratorFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qdiriterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)", + "src\\widgets\\itemviews\\qtreewidgetitemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)", + "tests\\benchmarks\\corelib\\io\\qdiriterator\\qfilesystemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)" + ], + "qflag_full_class_name": "QTreeWidgetItemIterator.IteratorFlags", + "enum_full_class_name": "QTreeWidgetItemIterator.IteratorFlag", + "enum_value1": "All", + "enum_value2": "Hidden", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Permissions", + "enum_class": "Permission", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qfiledevice.h: Q_DECLARE_FLAGS(Permissions, Permission)" + ], + "qflag_full_class_name": "QFileDevice.Permissions", + "enum_full_class_name": "QFileDevice.Permission", + "enum_value1": "ReadOwner", + "enum_value2": "WriteOwner", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "SelectionFlags", + "enum_class": "SelectionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\itemmodels\\qitemselectionmodel.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)" + ], + "qflag_full_class_name": "QItemSelectionModel.SelectionFlags", + "enum_full_class_name": "QItemSelectionModel.SelectionFlag", + "enum_value1": "NoUpdate", + "enum_value2": "Clear", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "KeyboardModifiers", + "enum_class": "KeyboardModifier", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(KeyboardModifiers, KeyboardModifier)" + ], + "qflag_full_class_name": "Qt.KeyboardModifiers", + "enum_full_class_name": "Qt.KeyboardModifier", + "enum_value1": "NoModifier", + "enum_value2": "ShiftModifier", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "MouseButtons", + "enum_class": "MouseButton", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(MouseButtons, MouseButton)" + ], + "qflag_full_class_name": "Qt.MouseButtons", + "enum_full_class_name": "Qt.MouseButton", + "enum_value1": "NoButton", + "enum_value2": "AllButtons", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Orientations", + "enum_class": "Orientation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(Orientations, Orientation)" + ], + "qflag_full_class_name": "Qt.Orientations", + "enum_full_class_name": "Qt.Orientation", + "enum_value1": "Horizontal", + "enum_value2": "Vertical", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Alignment", + "enum_class": "AlignmentFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(Alignment, AlignmentFlag)" + ], + "qflag_full_class_name": "Qt.Alignment", + "enum_full_class_name": "Qt.AlignmentFlag", + "enum_value1": "AlignLeft", + "enum_value2": "AlignLeading", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "WindowFlags", + "enum_class": "WindowType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(WindowFlags, WindowType)" + ], + "qflag_full_class_name": "Qt.WindowFlags", + "enum_full_class_name": "Qt.WindowType", + "enum_value1": "Widget", + "enum_value2": "Window", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "WindowStates", + "enum_class": "WindowState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(WindowStates, WindowState)" + ], + "qflag_full_class_name": "Qt.WindowStates", + "enum_full_class_name": "Qt.WindowState", + "enum_value1": "WindowNoState", + "enum_value2": "WindowMinimized", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ScreenOrientations", + "enum_class": "ScreenOrientation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ScreenOrientations, ScreenOrientation)" + ], + "qflag_full_class_name": "Qt.ScreenOrientations", + "enum_full_class_name": "Qt.ScreenOrientation", + "enum_value1": "PrimaryOrientation", + "enum_value2": "PortraitOrientation", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ImageConversionFlags", + "enum_class": "ImageConversionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ImageConversionFlags, ImageConversionFlag)" + ], + "qflag_full_class_name": "Qt.ImageConversionFlags", + "enum_full_class_name": "Qt.ImageConversionFlag", + "enum_value1": "AutoColor", + "enum_value2": "ColorOnly", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "DockWidgetAreas", + "enum_class": "DockWidgetArea", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)" + ], + "qflag_full_class_name": "Qt.DockWidgetAreas", + "enum_full_class_name": "Qt.DockWidgetArea", + "enum_value1": "LeftDockWidgetArea", + "enum_value2": "RightDockWidgetArea", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ToolBarAreas", + "enum_class": "ToolBarArea", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ToolBarAreas, ToolBarArea)" + ], + "qflag_full_class_name": "Qt.ToolBarAreas", + "enum_full_class_name": "Qt.ToolBarArea", + "enum_value1": "LeftToolBarArea", + "enum_value2": "RightToolBarArea", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Edges", + "enum_class": "Edge", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(Edges, Edge)" + ], + "qflag_full_class_name": "Qt.Edges", + "enum_full_class_name": "Qt.Edge", + "enum_value1": "TopEdge", + "enum_value2": "LeftEdge", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "InputMethodQueries", + "enum_class": "InputMethodQuery", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(InputMethodQueries, InputMethodQuery)" + ], + "qflag_full_class_name": "Qt.InputMethodQueries", + "enum_full_class_name": "Qt.InputMethodQuery", + "enum_value1": "ImMicroFocus", + "enum_value2": "ImFont", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "InputMethodHints", + "enum_class": "InputMethodHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(InputMethodHints, InputMethodHint)" + ], + "qflag_full_class_name": "Qt.InputMethodHints", + "enum_full_class_name": "Qt.InputMethodHint", + "enum_value1": "ImhNone", + "enum_value2": "ImhHiddenText", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "DropActions", + "enum_class": "DropAction", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(DropActions, DropAction)" + ], + "qflag_full_class_name": "Qt.DropActions", + "enum_full_class_name": "Qt.DropAction", + "enum_value1": "CopyAction", + "enum_value2": "MoveAction", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ItemFlags", + "enum_class": "ItemFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ItemFlags, ItemFlag)" + ], + "qflag_full_class_name": "Qt.ItemFlags", + "enum_full_class_name": "Qt.ItemFlag", + "enum_value1": "NoItemFlags", + "enum_value2": "ItemIsSelectable", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "MatchFlags", + "enum_class": "MatchFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(MatchFlags, MatchFlag)" + ], + "qflag_full_class_name": "Qt.MatchFlags", + "enum_full_class_name": "Qt.MatchFlag", + "enum_value1": "MatchExactly", + "enum_value2": "MatchFixedString", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "TextInteractionFlags", + "enum_class": "TextInteractionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(TextInteractionFlags, TextInteractionFlag)" + ], + "qflag_full_class_name": "Qt.TextInteractionFlags", + "enum_full_class_name": "Qt.TextInteractionFlag", + "enum_value1": "NoTextInteraction", + "enum_value2": "TextSelectableByMouse", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "TouchPointStates", + "enum_class": "TouchPointState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(TouchPointStates, TouchPointState)" + ], + "qflag_full_class_name": "Qt.TouchPointStates", + "enum_full_class_name": "Qt.TouchPointState", + "enum_value1": "TouchPointPressed", + "enum_value2": "TouchPointMoved", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "GestureFlags", + "enum_class": "GestureFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(GestureFlags, GestureFlag)" + ], + "qflag_full_class_name": "Qt.GestureFlags", + "enum_full_class_name": "Qt.GestureFlag", + "enum_value1": "DontStartGestureOnChildren", + "enum_value2": "ReceivePartialGestures", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "MouseEventFlags", + "enum_class": "MouseEventFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(MouseEventFlags, MouseEventFlag)" + ], + "qflag_full_class_name": "Qt.MouseEventFlags", + "enum_full_class_name": "Qt.MouseEventFlag", + "enum_value1": "MouseEventCreatedDoubleClick", + "enum_value2": "MouseEventCreatedDoubleClick", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Capabilities", + "enum_class": "Capability", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\image\\qimageiohandler.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\gui\\kernel\\qplatformcursor.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\gui\\painting\\qblittable_p.h: Q_DECLARE_FLAGS (Capabilities, Capability)", + "src\\network\\bearer\\qnetworkconfigmanager.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\network\\kernel\\qnetworkproxy.h: Q_DECLARE_FLAGS(Capabilities, Capability)" + ], + "qflag_full_class_name": "QNetworkConfigurationManager.Capabilities", + "enum_full_class_name": "QNetworkConfigurationManager.Capability", + "enum_value1": "CanStartAndStopInterfaces", + "enum_value2": "DirectConnectionRouting", + "module_count": 2, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": true, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ProcessEventsFlags", + "enum_class": "ProcessEventsFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\kernel\\qeventloop.h: Q_DECLARE_FLAGS(ProcessEventsFlags, ProcessEventsFlag)" + ], + "qflag_full_class_name": "QEventLoop.ProcessEventsFlags", + "enum_full_class_name": "QEventLoop.ProcessEventsFlag", + "enum_value1": "AllEvents", + "enum_value2": "ExcludeUserInputEvents", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "OpenMode", + "enum_class": "OpenModeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qiodevice.h: Q_DECLARE_FLAGS(OpenMode, OpenModeFlag)" + ], + "qflag_full_class_name": "QIODevice.OpenMode", + "enum_full_class_name": "QIODevice.OpenModeFlag", + "enum_value1": "NotOpen", + "enum_value2": "ReadOnly", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "InfoFlags", + "enum_class": "InfoFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qevent.h: Q_DECLARE_FLAGS(InfoFlags, InfoFlag)" + ], + "qflag_full_class_name": "QTouchEvent.TouchPoint.InfoFlags", + "enum_full_class_name": "QTouchEvent.TouchPoint.InfoFlag", + "enum_value1": "Pen", + "enum_value2": "Token", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": true, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "LoadHints", + "enum_class": "LoadHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\plugin\\qlibrary.h: Q_DECLARE_FLAGS(LoadHints, LoadHint)" + ], + "qflag_full_class_name": "QLibrary.LoadHints", + "enum_full_class_name": "QLibrary.LoadHint", + "enum_value1": "ResolveAllSymbolsHint", + "enum_value2": "ExportExternalSymbolsHint", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "RangeAccessFlags", + "enum_class": "RangeAccessFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\opengl\\qopenglbuffer.h: Q_DECLARE_FLAGS(RangeAccessFlags, RangeAccessFlag)" + ], + "qflag_full_class_name": "QOpenGLBuffer.RangeAccessFlags", + "enum_full_class_name": "QOpenGLBuffer.RangeAccessFlag", + "enum_value1": "RangeRead", + "enum_value2": "RangeWrite", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Sources", + "enum_class": "Source", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\opengl\\qopengldebug.h: Q_DECLARE_FLAGS(Sources, Source)" + ], + "qflag_full_class_name": "QOpenGLDebugMessage.Sources", + "enum_full_class_name": "QOpenGLDebugMessage.Source", + "enum_value1": "InvalidSource", + "enum_value2": "APISource", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Types", + "enum_class": "Type", + "human_hint_qflag_full_class_name": "QOpenGLDebugMessage.Types", + "human_hint_enum_full_class_name": "QOpenGLDebugMessage.Type", + "grep_line": [ + "src\\gui\\opengl\\qopengldebug.h: Q_DECLARE_FLAGS(Types, Type)" + ], + "qflag_full_class_name": "QOpenGLDebugMessage.Types", + "enum_full_class_name": "QOpenGLDebugMessage.Type", + "enum_value1": "InvalidType", + "enum_value2": "ErrorType", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Severities", + "enum_class": "Severity", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\opengl\\qopengldebug.h: Q_DECLARE_FLAGS(Severities, Severity)" + ], + "qflag_full_class_name": "QOpenGLDebugMessage.Severities", + "enum_full_class_name": "QOpenGLDebugMessage.Severity", + "enum_value1": "InvalidSeverity", + "enum_value2": "HighSeverity", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "TypeFlags", + "enum_class": "TypeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\kernel\\qmetatype.h: Q_DECLARE_FLAGS(TypeFlags, TypeFlag)" + ], + "qflag_full_class_name": "QMetaType.TypeFlags", + "enum_full_class_name": "QMetaType.TypeFlag", + "enum_value1": "NeedsConstruction", + "enum_value2": "NeedsDestruction", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "LocateOptions", + "enum_class": "LocateOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qstandardpaths.h: Q_DECLARE_FLAGS(LocateOptions, LocateOption)" + ], + "qflag_full_class_name": "QStandardPaths.LocateOptions", + "enum_full_class_name": "QStandardPaths.LocateOption", + "enum_value1": "LocateFile", + "enum_value2": "LocateDirectory", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\kernel\\qppsattribute_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\painting\\qplatformbackingstore.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\vulkan\\qvulkaninstance.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qshader_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\vulkan\\qvulkanwindow.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\text\\qtextoption.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\corelib\\tools\\qcommandlineoption.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\platformsupport\\eglconvenience\\qeglplatformcontext_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\platformsupport\\fbconvenience\\qfbscreen_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\plugins\\platforms\\direct2d\\qwindowsdirect2dpaintengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\tools\\moc\\namespaced-flags.h: Q_DECLARE_FLAGS( Flags, Flag )", + "src\\plugins\\platforms\\eglfs\\api\\qeglfswindow_p.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "QCommandLineOption.Flags", + "enum_full_class_name": "QCommandLineOption.Flag", + "enum_value1": "HiddenFromHelp", + "enum_value2": "ShortOptionStyle", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\kernel\\qppsattribute_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\painting\\qplatformbackingstore.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\vulkan\\qvulkaninstance.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qshader_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\vulkan\\qvulkanwindow.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\text\\qtextoption.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\corelib\\tools\\qcommandlineoption.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\platformsupport\\eglconvenience\\qeglplatformcontext_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\platformsupport\\fbconvenience\\qfbscreen_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\plugins\\platforms\\direct2d\\qwindowsdirect2dpaintengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\tools\\moc\\namespaced-flags.h: Q_DECLARE_FLAGS( Flags, Flag )", + "src\\plugins\\platforms\\eglfs\\api\\qeglfswindow_p.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "QTextOption.Flags", + "enum_full_class_name": "QTextOption.Flag", + "enum_value1": "IncludeTrailingSpaces", + "enum_value2": "ShowTabsAndSpaces", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "PolicyFlags", + "enum_class": "PolicyFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\access\\qhstspolicy.h: Q_DECLARE_FLAGS(PolicyFlags, PolicyFlag)" + ], + "qflag_full_class_name": "QHstsPolicy.PolicyFlags", + "enum_full_class_name": "QHstsPolicy.PolicyFlag", + "enum_value1": "IncludeSubDomains", + "enum_value2": "IncludeSubDomains", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "StandardButtons", + "enum_class": "StandardButton", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qplatformdialoghelper.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)", + "src\\widgets\\dialogs\\qmessagebox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)", + "src\\widgets\\widgets\\qdialogbuttonbox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)" + ], + "qflag_full_class_name": "QDialogButtonBox.StandardButtons", + "enum_full_class_name": "QDialogButtonBox.StandardButton", + "enum_value1": "NoButton", + "enum_value2": "Ok", + "module_count": 2, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "StandardButtons", + "enum_class": "StandardButton", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qplatformdialoghelper.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)", + "src\\widgets\\dialogs\\qmessagebox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)", + "src\\widgets\\widgets\\qdialogbuttonbox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)" + ], + "qflag_full_class_name": "QMessageBox.StandardButtons", + "enum_full_class_name": "QMessageBox.StandardButton", + "enum_value1": "NoButton", + "enum_value2": "Ok", + "module_count": 2, + "module_idx": 1, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ColorDialogOptions", + "enum_class": "ColorDialogOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qplatformdialoghelper.h: Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)", + "src\\widgets\\dialogs\\qcolordialog.h: Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)" + ], + "qflag_full_class_name": "QColorDialog.ColorDialogOptions", + "enum_full_class_name": "QColorDialog.ColorDialogOption", + "enum_value1": "ShowAlphaChannel", + "enum_value2": "NoButtons", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "FontDialogOptions", + "enum_class": "FontDialogOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qplatformdialoghelper.h: Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption)", + "src\\widgets\\dialogs\\qfontdialog.h: Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption)" + ], + "qflag_full_class_name": "QFontDialog.FontDialogOptions", + "enum_full_class_name": "QFontDialog.FontDialogOption", + "enum_value1": "NoButtons", + "enum_value2": "DontUseNativeDialog", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ComponentFormattingOptions", + "enum_class": "ComponentFormattingOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qurl.h: Q_DECLARE_FLAGS(ComponentFormattingOptions, ComponentFormattingOption)" + ], + "qflag_full_class_name": "QUrl.ComponentFormattingOptions", + "enum_full_class_name": "QUrl.ComponentFormattingOption", + "enum_value1": "PrettyDecoded", + "enum_value2": "EncodeSpaces", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "RenderFlags", + "enum_class": "RenderFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpaintengine.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag)", + "src\\widgets\\kernel\\qwidget.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag)" + ], + "qflag_full_class_name": "QWidget.RenderFlags", + "enum_full_class_name": "QWidget.RenderFlag", + "enum_value1": "DrawWindowBackground", + "enum_value2": "DrawChildren", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "RenderFlags", + "enum_class": "RenderFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpaintengine.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag)", + "src\\widgets\\kernel\\qwidget.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag)" + ], + "qflag_full_class_name": "QTextItem.RenderFlags", + "enum_full_class_name": "QTextItem.RenderFlag", + "enum_value1": "RightToLeft", + "enum_value2": "Overline", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "PaintEngineFeatures", + "enum_class": "PaintEngineFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpaintengine.h: Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)" + ], + "qflag_full_class_name": "QPaintEngine.PaintEngineFeatures", + "enum_full_class_name": "QPaintEngine.PaintEngineFeature", + "enum_value1": "PrimitiveTransform", + "enum_value2": "PatternTransform", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Capabilities", + "enum_class": "CapabilityFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qtouchdevice.h: Q_DECLARE_FLAGS(Capabilities, CapabilityFlag)" + ], + "qflag_full_class_name": "QTouchDevice.Capabilities", + "enum_full_class_name": "QTouchDevice.CapabilityFlag", + "enum_value1": "Position", + "enum_value2": "Area", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Features", + "enum_class": "Feature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\opengl\\qopengltexture.h: Q_DECLARE_FLAGS(Features, Feature)", + "src\\gui\\text\\qtextmarkdownimporter_p.h: Q_DECLARE_FLAGS(Features, Feature)" + ], + "qflag_full_class_name": "QOpenGLTexture.Features", + "enum_full_class_name": "QOpenGLTexture.Feature", + "enum_value1": "ImmutableStorage", + "enum_value2": "ImmutableMultisampleStorage", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "RenderHints", + "enum_class": "RenderHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpainter.h: Q_DECLARE_FLAGS(RenderHints, RenderHint)" + ], + "qflag_full_class_name": "QPainter.RenderHints", + "enum_full_class_name": "QPainter.RenderHint", + "enum_value1": "Antialiasing", + "enum_value2": "TextAntialiasing", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ControlTypes", + "enum_class": "ControlType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\util\\qlayoutpolicy_p.h: Q_DECLARE_FLAGS(ControlTypes, ControlType)", + "src\\widgets\\kernel\\qsizepolicy.h: Q_DECLARE_FLAGS(ControlTypes, ControlType)" + ], + "qflag_full_class_name": "QSizePolicy.ControlTypes", + "enum_full_class_name": "QSizePolicy.ControlType", + "enum_value1": "DefaultType", + "enum_value2": "ButtonBox", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "LayoutFlags", + "enum_class": "LayoutFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qrawfont.h: Q_DECLARE_FLAGS(LayoutFlags, LayoutFlag)" + ], + "qflag_full_class_name": "QRawFont.LayoutFlags", + "enum_full_class_name": "QRawFont.LayoutFlag", + "enum_value1": "SeparateAdvances", + "enum_value2": "KernedAdvances", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "FindFlags", + "enum_class": "FindFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qtextdocument.h: Q_DECLARE_FLAGS(FindFlags, FindFlag)" + ], + "qflag_full_class_name": "QTextDocument.FindFlags", + "enum_full_class_name": "QTextDocument.FindFlag", + "enum_value1": "FindBackward", + "enum_value2": "FindCaseSensitively", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ConversionMode", + "enum_class": "ConversionModeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\kernel\\qhostaddress.h: Q_DECLARE_FLAGS(ConversionMode, ConversionModeFlag)" + ], + "qflag_full_class_name": "QHostAddress.ConversionMode", + "enum_full_class_name": "QHostAddress.ConversionModeFlag", + "enum_value1": "ConvertV4MappedToIPv4", + "enum_value2": "ConvertV4CompatToIPv4", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "BindMode", + "enum_class": "BindFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\socket\\qabstractsocket.h: Q_DECLARE_FLAGS(BindMode, BindFlag)" + ], + "qflag_full_class_name": "QAbstractSocket.BindMode", + "enum_full_class_name": "QAbstractSocket.BindFlag", + "enum_value1": "DefaultForPlatform", + "enum_value2": "ShareAddress", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "PauseModes", + "enum_class": "PauseMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\socket\\qabstractsocket.h: Q_DECLARE_FLAGS(PauseModes, PauseMode)" + ], + "qflag_full_class_name": "QAbstractSocket.PauseModes", + "enum_full_class_name": "QAbstractSocket.PauseMode", + "enum_value1": "PauseNever", + "enum_value2": "PauseOnSslErrors", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "PageBreakFlags", + "enum_class": "PageBreakFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qtextformat.h: Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag)" + ], + "qflag_full_class_name": "QTextFormat.PageBreakFlags", + "enum_full_class_name": "QTextFormat.PageBreakFlag", + "enum_value1": "PageBreak_Auto", + "enum_value2": "PageBreak_AlwaysBefore", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "SocketOptions", + "enum_class": "SocketOption", + "human_hint_qflag_full_class_name": "QLocalServer.SocketOptions", + "human_hint_enum_full_class_name": "QLocalServer.SocketOption", + "grep_line": [ + "src\\network\\socket\\qlocalserver.h: Q_DECLARE_FLAGS(SocketOptions, SocketOption)" + ], + "qflag_full_class_name": "QLocalServer.SocketOptions", + "enum_full_class_name": "QLocalServer.SocketOption", + "enum_value1": "UserAccessOption", + "enum_value2": "GroupAccessOption", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "InterfaceFlags", + "enum_class": "InterfaceFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\kernel\\qnetworkinterface.h: Q_DECLARE_FLAGS(InterfaceFlags, InterfaceFlag)" + ], + "qflag_full_class_name": "QNetworkInterface.InterfaceFlags", + "enum_full_class_name": "QNetworkInterface.InterfaceFlag", + "enum_value1": "IsUp", + "enum_value2": "IsRunning", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "SslOptions", + "enum_class": "SslOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\ssl\\qssl.h: Q_DECLARE_FLAGS(SslOptions, SslOption)" + ], + "qflag_full_class_name": "QSsl.SslOptions", + "enum_full_class_name": "QSsl.SslOption", + "enum_value1": "SslOptionDisableEmptyFragments", + "enum_value2": "SslOptionDisableSessionTickets", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Base64Options", + "enum_class": "Base64Option", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qbytearray.h: Q_DECLARE_FLAGS(Base64Options, Base64Option)" + ], + "qflag_full_class_name": "QByteArray.Base64Options", + "enum_full_class_name": "QByteArray.Base64Option", + "enum_value1": "Base64Encoding", + "enum_value2": "Base64UrlEncoding", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "NumberOptions", + "enum_class": "NumberOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qlocale.h: Q_DECLARE_FLAGS(NumberOptions, NumberOption)" + ], + "qflag_full_class_name": "QLocale.NumberOptions", + "enum_full_class_name": "QLocale.NumberOption", + "enum_value1": "OmitGroupSeparator", + "enum_value2": "RejectGroupSeparator", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Sections", + "enum_class": "Section", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\time\\qdatetimeparser_p.h: Q_DECLARE_FLAGS(Sections, Section)", + "src\\widgets\\widgets\\qdatetimeedit.h: Q_DECLARE_FLAGS(Sections, Section)" + ], + "qflag_full_class_name": "QDateTimeEdit.Sections", + "enum_full_class_name": "QDateTimeEdit.Section", + "enum_value1": "NoSection", + "enum_value2": "AmPmSection", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "PatternOptions", + "enum_class": "PatternOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qregularexpression.h: Q_DECLARE_FLAGS(PatternOptions, PatternOption)" + ], + "qflag_full_class_name": "QRegularExpression.PatternOptions", + "enum_full_class_name": "QRegularExpression.PatternOption", + "enum_value1": "NoPatternOption", + "enum_value2": "CaseInsensitiveOption", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "MatchOptions", + "enum_class": "MatchOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qregularexpression.h: Q_DECLARE_FLAGS(MatchOptions, MatchOption)" + ], + "qflag_full_class_name": "QRegularExpression.MatchOptions", + "enum_full_class_name": "QRegularExpression.MatchOption", + "enum_value1": "NoMatchOption", + "enum_value2": "AnchoredMatchOption", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "NumberFlags", + "enum_class": "NumberFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\serialization\\qtextstream.h: Q_DECLARE_FLAGS(NumberFlags, NumberFlag)" + ], + "qflag_full_class_name": "QTextStream.NumberFlags", + "enum_full_class_name": "QTextStream.NumberFlag", + "enum_value1": "ShowBase", + "enum_value2": "ForcePoint", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "BoundaryReasons", + "enum_class": "BoundaryReason", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qtextboundaryfinder.h: Q_DECLARE_FLAGS( BoundaryReasons, BoundaryReason )" + ], + "qflag_full_class_name": "QTextBoundaryFinder.BoundaryReasons", + "enum_full_class_name": "QTextBoundaryFinder.BoundaryReason", + "enum_value1": "NotAtBoundary", + "enum_value2": "SoftHyphen", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "PrintDialogOptions", + "enum_class": "PrintDialogOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\printsupport\\dialogs\\qabstractprintdialog.h: Q_DECLARE_FLAGS(PrintDialogOptions, PrintDialogOption)" + ], + "qflag_full_class_name": "QAbstractPrintDialog.PrintDialogOptions", + "enum_full_class_name": "QAbstractPrintDialog.PrintDialogOption", + "enum_value1": "None_", + "enum_value2": "PrintToFile", + "module_count": 1, + "module_idx": 0, + "module_name": "QtPrintSupport", + "module_path": "../../PyQt5-stubs/QtPrintSupport.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ParamType", + "enum_class": "ParamTypeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\sql\\kernel\\qtsqlglobal.h: Q_DECLARE_FLAGS(ParamType, ParamTypeFlag)" + ], + "qflag_full_class_name": "QSql.ParamType", + "enum_full_class_name": "QSql.ParamTypeFlag", + "enum_value1": "In", + "enum_value2": "Out", + "module_count": 1, + "module_idx": 0, + "module_name": "QtSql", + "module_path": "../../PyQt5-stubs/QtSql.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Options", + "enum_class": "Option", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qfiledialog.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\dialogs\\qfilesystemmodel.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\itemviews\\qfileiconprovider.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\cocoa\\qcocoaintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\qnx\\qqnxintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "tests\\benchmarks\\widgets\\graphicsview\\functional\\GraphicsViewBenchmark\\widgets\\settings.h: Q_DECLARE_FLAGS(Options, Option)" + ], + "qflag_full_class_name": "QFileDialog.Options", + "enum_full_class_name": "QFileDialog.Option", + "enum_value1": "ShowDirsOnly", + "enum_value2": "DontResolveSymlinks", + "module_count": 3, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Options", + "enum_class": "Option", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qfiledialog.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\dialogs\\qfilesystemmodel.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\itemviews\\qfileiconprovider.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\cocoa\\qcocoaintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\qnx\\qqnxintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "tests\\benchmarks\\widgets\\graphicsview\\functional\\GraphicsViewBenchmark\\widgets\\settings.h: Q_DECLARE_FLAGS(Options, Option)" + ], + "qflag_full_class_name": "QFileIconProvider.Options", + "enum_full_class_name": "QFileIconProvider.Option", + "enum_value1": "DontUseCustomDirectoryIcons", + "enum_value2": "DontUseCustomDirectoryIcons", + "module_count": 3, + "module_idx": 1, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Options", + "enum_class": "Option", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qfiledialog.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\dialogs\\qfilesystemmodel.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\itemviews\\qfileiconprovider.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\cocoa\\qcocoaintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\qnx\\qqnxintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "tests\\benchmarks\\widgets\\graphicsview\\functional\\GraphicsViewBenchmark\\widgets\\settings.h: Q_DECLARE_FLAGS(Options, Option)" + ], + "qflag_full_class_name": "QFileSystemModel.Options", + "enum_full_class_name": "QFileSystemModel.Option", + "enum_value1": "DontWatchForChanges", + "enum_value2": "DontResolveSymlinks", + "module_count": 3, + "module_idx": 2, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "BlurHints", + "enum_class": "BlurHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\effects\\qgraphicseffect.h: Q_DECLARE_FLAGS(BlurHints, BlurHint)" + ], + "qflag_full_class_name": "QGraphicsBlurEffect.BlurHints", + "enum_full_class_name": "QGraphicsBlurEffect.BlurHint", + "enum_value1": "PerformanceHint", + "enum_value2": "QualityHint", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "InputDialogOptions", + "enum_class": "InputDialogOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qinputdialog.h: Q_DECLARE_FLAGS(InputDialogOptions, InputDialogOption)" + ], + "qflag_full_class_name": "QInputDialog.InputDialogOptions", + "enum_full_class_name": "QInputDialog.InputDialogOption", + "enum_value1": "NoButtons", + "enum_value2": "UseListViewForComboBoxItems", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "WizardOptions", + "enum_class": "WizardOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qwizard.h: Q_DECLARE_FLAGS(WizardOptions, WizardOption)" + ], + "qflag_full_class_name": "QWizard.WizardOptions", + "enum_full_class_name": "QWizard.WizardOption", + "enum_value1": "IndependentPages", + "enum_value2": "IgnoreSubTitles", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "EditTriggers", + "enum_class": "EditTrigger", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\itemviews\\qabstractitemview.h: Q_DECLARE_FLAGS(EditTriggers, EditTrigger)" + ], + "qflag_full_class_name": "QAbstractItemView.EditTriggers", + "enum_full_class_name": "QAbstractItemView.EditTrigger", + "enum_value1": "NoEditTriggers", + "enum_value2": "CurrentChanged", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "GraphicsItemFlags", + "enum_class": "GraphicsItemFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\graphicsview\\qgraphicsitem.h: Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)" + ], + "qflag_full_class_name": "QGraphicsItem.GraphicsItemFlags", + "enum_full_class_name": "QGraphicsItem.GraphicsItemFlag", + "enum_value1": "ItemIsMovable", + "enum_value2": "ItemIsSelectable", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "Result", + "enum_class": "ResultFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\kernel\\qgesturerecognizer.h: Q_DECLARE_FLAGS(Result, ResultFlag)" + ], + "qflag_full_class_name": "QGestureRecognizer.Result", + "enum_full_class_name": "QGestureRecognizer.ResultFlag", + "enum_value1": "Ignore", + "enum_value2": "MayBeGesture", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "SceneLayers", + "enum_class": "SceneLayer", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\graphicsview\\qgraphicsscene.h: Q_DECLARE_FLAGS(SceneLayers, SceneLayer)" + ], + "qflag_full_class_name": "QGraphicsScene.SceneLayers", + "enum_full_class_name": "QGraphicsScene.SceneLayer", + "enum_value1": "ItemLayer", + "enum_value2": "BackgroundLayer", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "CacheMode", + "enum_class": "CacheModeFlag", + "human_hint_qflag_full_class_name": "QGraphicsView.CacheMode", + "human_hint_enum_full_class_name": "QGraphicsView.CacheModeFlag", + "grep_line": [ + "src\\widgets\\graphicsview\\qgraphicsview.h: Q_DECLARE_FLAGS(CacheMode, CacheModeFlag)" + ], + "qflag_full_class_name": "QGraphicsView.CacheMode", + "enum_full_class_name": "QGraphicsView.CacheModeFlag", + "enum_value1": "CacheNone", + "enum_value2": "CacheBackground", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "OptimizationFlags", + "enum_class": "OptimizationFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\graphicsview\\qgraphicsview.h: Q_DECLARE_FLAGS(OptimizationFlags, OptimizationFlag)" + ], + "qflag_full_class_name": "QGraphicsView.OptimizationFlags", + "enum_full_class_name": "QGraphicsView.OptimizationFlag", + "enum_value1": "DontClipPainter", + "enum_value2": "DontSavePainterState", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "SubControls", + "enum_class": "SubControl", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyle.h: Q_DECLARE_FLAGS(SubControls, SubControl)" + ], + "qflag_full_class_name": "QStyle.SubControls", + "enum_full_class_name": "QStyle.SubControl", + "enum_value1": "SC_None", + "enum_value2": "SC_ScrollBarAddLine", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "StepEnabled", + "enum_class": "StepEnabledFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qabstractspinbox.h: Q_DECLARE_FLAGS(StepEnabled, StepEnabledFlag)" + ], + "qflag_full_class_name": "QAbstractSpinBox.StepEnabled", + "enum_full_class_name": "QAbstractSpinBox.StepEnabledFlag", + "enum_value1": "StepNone", + "enum_value2": "StepUpEnabled", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "FrameFeatures", + "enum_class": "FrameFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(FrameFeatures, FrameFeature)" + ], + "qflag_full_class_name": "QStyleOptionFrame.FrameFeatures", + "enum_full_class_name": "QStyleOptionFrame.FrameFeature", + "enum_value1": "None_", + "enum_value2": "Flat", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ButtonFeatures", + "enum_class": "ButtonFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(ButtonFeatures, ButtonFeature)" + ], + "qflag_full_class_name": "QStyleOptionButton.ButtonFeatures", + "enum_full_class_name": "QStyleOptionButton.ButtonFeature", + "enum_value1": "None_", + "enum_value2": "Flat", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "CornerWidgets", + "enum_class": "CornerWidget", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(CornerWidgets, CornerWidget)" + ], + "qflag_full_class_name": "QStyleOptionTab.CornerWidgets", + "enum_full_class_name": "QStyleOptionTab.CornerWidget", + "enum_value1": "NoCornerWidgets", + "enum_value2": "LeftCornerWidget", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ToolBarFeatures", + "enum_class": "ToolBarFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(ToolBarFeatures, ToolBarFeature)" + ], + "qflag_full_class_name": "QStyleOptionToolBar.ToolBarFeatures", + "enum_full_class_name": "QStyleOptionToolBar.ToolBarFeature", + "enum_value1": "None_", + "enum_value2": "Movable", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ViewItemFeatures", + "enum_class": "ViewItemFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(ViewItemFeatures, ViewItemFeature)" + ], + "qflag_full_class_name": "QStyleOptionViewItem.ViewItemFeatures", + "enum_full_class_name": "QStyleOptionViewItem.ViewItemFeature", + "enum_value1": "None_", + "enum_value2": "WrapText", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "ToolButtonFeatures", + "enum_class": "ToolButtonFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(ToolButtonFeatures, ToolButtonFeature)" + ], + "qflag_full_class_name": "QStyleOptionToolButton.ToolButtonFeatures", + "enum_full_class_name": "QStyleOptionToolButton.ToolButtonFeature", + "enum_value1": "None_", + "enum_value2": "Arrow", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "DockWidgetFeatures", + "enum_class": "DockWidgetFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qdockwidget.h: Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature)" + ], + "qflag_full_class_name": "QDockWidget.DockWidgetFeatures", + "enum_full_class_name": "QDockWidget.DockWidgetFeature", + "enum_value1": "DockWidgetClosable", + "enum_value2": "DockWidgetMovable", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "FontFilters", + "enum_class": "FontFilter", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qfontcombobox.h: Q_DECLARE_FLAGS(FontFilters, FontFilter)" + ], + "qflag_full_class_name": "QFontComboBox.FontFilters", + "enum_full_class_name": "QFontComboBox.FontFilter", + "enum_value1": "AllFonts", + "enum_value2": "ScalableFonts", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "AreaOptions", + "enum_class": "AreaOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qmdiarea.h: Q_DECLARE_FLAGS(AreaOptions, AreaOption)" + ], + "qflag_full_class_name": "QMdiArea.AreaOptions", + "enum_full_class_name": "QMdiArea.AreaOption", + "enum_value1": "DontMaximizeSubWindowOnActivation", + "enum_value2": "DontMaximizeSubWindowOnActivation", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "SubWindowOptions", + "enum_class": "SubWindowOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qmdisubwindow.h: Q_DECLARE_FLAGS(SubWindowOptions, SubWindowOption)" + ], + "qflag_full_class_name": "QMdiSubWindow.SubWindowOptions", + "enum_full_class_name": "QMdiSubWindow.SubWindowOption", + "enum_value1": "RubberBandResize", + "enum_value2": "RubberBandMove", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "DockOptions", + "enum_class": "DockOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qmainwindow.h: Q_DECLARE_FLAGS(DockOptions, DockOption)" + ], + "qflag_full_class_name": "QMainWindow.DockOptions", + "enum_full_class_name": "QMainWindow.DockOption", + "enum_value1": "AnimatedDocks", + "enum_value2": "AllowNestedDocks", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "AutoFormatting", + "enum_class": "AutoFormattingFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qtextedit.h: Q_DECLARE_FLAGS(AutoFormatting, AutoFormattingFlag)" + ], + "qflag_full_class_name": "QTextEdit.AutoFormatting", + "enum_full_class_name": "QTextEdit.AutoFormattingFlag", + "enum_value1": "AutoNone", + "enum_value2": "AutoBulletList", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true + }, + { + "qflag_class": "FileHandleFlags", + "enum_class": "FileHandleFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qfiledevice.h: Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)" + ], + "qflag_full_class_name": "QFileDevice.FileHandleFlags", + "enum_full_class_name": "QFileDevice.FileHandleFlag", + "enum_value1": "AutoCloseHandle", + "enum_value2": "DontCloseHandle", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "ApplicationStates", + "enum_class": "ApplicationState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ApplicationStates, ApplicationState)" + ], + "qflag_full_class_name": "Qt.ApplicationStates", + "enum_full_class_name": "Qt.ApplicationState", + "enum_value1": "ApplicationSuspended", + "enum_value2": "ApplicationHidden", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "FindChildOptions", + "enum_class": "FindChildOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(FindChildOptions, FindChildOption)" + ], + "qflag_full_class_name": "Qt.FindChildOptions", + "enum_full_class_name": "Qt.FindChildOption", + "enum_value1": "FindDirectChildrenOnly", + "enum_value2": "FindChildrenRecursively", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "Transformations", + "enum_class": "Transformation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\image\\qimageiohandler.h: Q_DECLARE_FLAGS(Transformations, Transformation)" + ], + "qflag_full_class_name": "QImageIOHandler.Transformations", + "enum_full_class_name": "QImageIOHandler.Transformation", + "enum_value1": "TransformationNone", + "enum_value2": "TransformationMirror", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "Capabilities", + "enum_class": "Capability", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\image\\qimageiohandler.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\gui\\kernel\\qplatformcursor.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\gui\\painting\\qblittable_p.h: Q_DECLARE_FLAGS (Capabilities, Capability)", + "src\\network\\bearer\\qnetworkconfigmanager.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\network\\kernel\\qnetworkproxy.h: Q_DECLARE_FLAGS(Capabilities, Capability)" + ], + "qflag_full_class_name": "QNetworkProxy.Capabilities", + "enum_full_class_name": "QNetworkProxy.Capability", + "enum_value1": "TunnelingCapability", + "enum_value2": "ListeningCapability", + "module_count": 2, + "module_idx": 1, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "UserInputResolutionOptions", + "enum_class": "UserInputResolutionOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qurl.h: Q_DECLARE_FLAGS(UserInputResolutionOptions, UserInputResolutionOption)" + ], + "qflag_full_class_name": "QUrl.UserInputResolutionOptions", + "enum_full_class_name": "QUrl.UserInputResolutionOption", + "enum_value1": "DefaultResolution", + "enum_value2": "AssumeLocalFile", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "StateFlags", + "enum_class": "StateFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\bearer\\qnetworkconfiguration.h: Q_DECLARE_FLAGS(StateFlags, StateFlag)" + ], + "qflag_full_class_name": "QNetworkConfiguration.StateFlags", + "enum_full_class_name": "QNetworkConfiguration.StateFlag", + "enum_value1": "Undefined", + "enum_value2": "Defined", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "UsagePolicies", + "enum_class": "UsagePolicy", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\bearer\\qnetworksession.h: Q_DECLARE_FLAGS(UsagePolicies, UsagePolicy)" + ], + "qflag_full_class_name": "QNetworkSession.UsagePolicies", + "enum_full_class_name": "QNetworkSession.UsagePolicy", + "enum_value1": "NoPolicy", + "enum_value2": "NoBackgroundTrafficPolicy", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "DirtyFlags", + "enum_class": "DirtyFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpaintengine.h: Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)" + ], + "qflag_full_class_name": "QPaintEngine.DirtyFlags", + "enum_full_class_name": "QPaintEngine.DirtyFlag", + "enum_value1": "DirtyPen", + "enum_value2": "DirtyBrush", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "PixmapFragmentHints", + "enum_class": "PixmapFragmentHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpainter.h: Q_DECLARE_FLAGS(PixmapFragmentHints, PixmapFragmentHint)" + ], + "qflag_full_class_name": "QPainter.PixmapFragmentHints", + "enum_full_class_name": "QPainter.PixmapFragmentHint", + "enum_value1": "OpaqueHint", + "enum_value2": "OpaqueHint", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "GlyphRunFlags", + "enum_class": "GlyphRunFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qglyphrun.h: Q_DECLARE_FLAGS(GlyphRunFlags, GlyphRunFlag)" + ], + "qflag_full_class_name": "QGlyphRun.GlyphRunFlags", + "enum_full_class_name": "QGlyphRun.GlyphRunFlag", + "enum_value1": "Overline", + "enum_value2": "Underline", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "MarkdownFeatures", + "enum_class": "MarkdownFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qtextdocument.h: Q_DECLARE_FLAGS(MarkdownFeatures, MarkdownFeature)" + ], + "qflag_full_class_name": "QTextDocument.MarkdownFeatures", + "enum_full_class_name": "QTextDocument.MarkdownFeature", + "enum_value1": "MarkdownNoHTML", + "enum_value2": "MarkdownDialectCommonMark", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "DataSizeFormats", + "enum_class": "DataSizeFormat", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qlocale.h: Q_DECLARE_FLAGS(DataSizeFormats, DataSizeFormat)" + ], + "qflag_full_class_name": "QLocale.DataSizeFormats", + "enum_full_class_name": "QLocale.DataSizeFormat", + "enum_value1": "DataSizeIecFormat", + "enum_value2": "DataSizeTraditionalFormat", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "ChangeFlags", + "enum_class": "ChangeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\effects\\qgraphicseffect.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)", + "src\\widgets\\kernel\\qgesture.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)" + ], + "qflag_full_class_name": "QPinchGesture.ChangeFlags", + "enum_full_class_name": "QPinchGesture.ChangeFlag", + "enum_value1": "ScaleFactorChanged", + "enum_value2": "RotationAngleChanged", + "module_count": 2, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "ChangeFlags", + "enum_class": "ChangeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\effects\\qgraphicseffect.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)", + "src\\widgets\\kernel\\qgesture.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)" + ], + "qflag_full_class_name": "QGraphicsEffect.ChangeFlags", + "enum_full_class_name": "QGraphicsEffect.ChangeFlag", + "enum_value1": "SourceAttached", + "enum_value2": "SourceDetached", + "module_count": 2, + "module_idx": 1, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "TabFeatures", + "enum_class": "TabFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(TabFeatures, TabFeature)" + ], + "qflag_full_class_name": "QStyleOptionTab.TabFeatures", + "enum_full_class_name": "QStyleOptionTab.TabFeature", + "enum_value1": "None_", + "enum_value2": "HasFrame", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "State", + "enum_class": "StateFlag", + "human_hint_qflag_full_class_name": "QStyle.State", + "human_hint_enum_full_class_name": "QStyle.StateFlag", + "grep_line": [ + "src\\widgets\\styles\\qstyle.h: Q_DECLARE_FLAGS(State, StateFlag)" + ], + "qflag_full_class_name": "QStyle.State", + "enum_full_class_name": "QStyle.StateFlag", + "enum_value1": "State_None", + "enum_value2": "State_Enabled", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + } + ], + "qflag_processed_done": [ + { + "qflag_class": "Operations", + "enum_class": "Operation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\render\\framegraph\\qmemorybarrier.h: Q_DECLARE_FLAGS(Operations, Operation)" + ], + "qflag_full_class_name": "QMemoryBarrier.Operations", + "enum_full_class_name": "QMemoryBarrier.Operation", + "enum_value1": "None_", + "enum_value2": "VertexAttributeArray", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DRender", + "module_path": "../../PyQt5-stubs/Qt3DRender.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false + }, + { + "qflag_class": "ChangeFlags", + "enum_class": "ChangeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\core\\changes\\qscenechange.h:Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)" + ], + "qflag_full_class_name": "ChangeFlags", + "enum_full_class_name": "ChangeFlag", + "enum_value1": "NodeCreated", + "enum_value2": "NodeDeleted", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DCore", + "module_path": "../../PyQt5-stubs/Qt3DCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "DeliveryFlags", + "enum_class": "DeliveryFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\core\\changes\\qscenechange.h: Q_DECLARE_FLAGS(DeliveryFlags, DeliveryFlag)" + ], + "qflag_full_class_name": "QSceneChange.DeliveryFlags", + "enum_full_class_name": "QSceneChange.DeliveryFlag", + "enum_value1": "BackendNodes", + "enum_value2": "Nodes", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DCore", + "module_path": "../../PyQt5-stubs/Qt3DCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "BufferTypeFlags", + "enum_class": "BufferType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\render\\framegraph\\qclearbuffers.h: Q_DECLARE_FLAGS(BufferTypeFlags, BufferType)" + ], + "qflag_full_class_name": "QClearBuffers.BufferTypeFlags", + "enum_full_class_name": "QBuffer.BufferType", + "enum_value1": "VertexBuffer", + "enum_value2": "IndexBuffer", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DRender", + "module_path": "../../PyQt5-stubs/Qt3DRender.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": false + }, + { + "qflag_class": "AnimationOptions", + "enum_class": "AnimationOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\qchart.h: Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)" + ], + "qflag_full_class_name": "QChart.AnimationOptions", + "enum_full_class_name": "QChart.AnimationOption", + "enum_value1": "NoAnimation", + "enum_value2": "GridAxisAnimations", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": true, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "RubberBands", + "enum_class": "RubberBand", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\qchartview.h: Q_DECLARE_FLAGS(RubberBands, RubberBand)" + ], + "qflag_full_class_name": "QChartView.RubberBands", + "enum_full_class_name": "QChartView.RubberBand", + "enum_value1": "NoRubberBand", + "enum_value2": "VerticalRubberBand", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "PolarOrientations", + "enum_class": "PolarOrientation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\qpolarchart.h: Q_DECLARE_FLAGS(PolarOrientations, PolarOrientation)" + ], + "qflag_full_class_name": "QPolarChart.PolarOrientations", + "enum_full_class_name": "QPolarChart.PolarOrientation", + "enum_value1": "PolarOrientationRadial", + "enum_value2": "PolarOrientationAngular", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "AxisTypes", + "enum_class": "AxisType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\axis\\qabstractaxis.h: Q_DECLARE_FLAGS(AxisTypes, AxisType)" + ], + "qflag_full_class_name": "QAbstractAxis.AxisTypes", + "enum_full_class_name": "QAbstractAxis.AxisType", + "enum_value1": "AxisTypeNoAxis", + "enum_value2": "AxisTypeValue", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "TargetAccessModes", + "enum_class": "TargetAccessMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\nfc\\qnearfieldmanager.h: Q_DECLARE_FLAGS(TargetAccessModes, TargetAccessMode)" + ], + "qflag_full_class_name": "QNearFieldManager.TargetAccessModes", + "enum_full_class_name": "QNearFieldManager.TargetAccessMode", + "enum_value1": "NoTargetAccess", + "enum_value2": "NdefReadTargetAccess", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNfc", + "module_path": "../../PyQt5-stubs/QtNfc.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "ShareModes", + "enum_class": "ShareMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\nfc\\qnearfieldsharemanager.h: Q_DECLARE_FLAGS(ShareModes, ShareMode)" + ], + "qflag_full_class_name": "QNearFieldShareManager.ShareModes", + "enum_full_class_name": "QNearFieldShareManager.ShareMode", + "enum_value1": "NoShare", + "enum_value2": "NdefShare", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNfc", + "module_path": "../../PyQt5-stubs/QtNfc.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "AccessMethods", + "enum_class": "AccessMethod", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\nfc\\qnearfieldtarget.h: Q_DECLARE_FLAGS(AccessMethods, AccessMethod)" + ], + "qflag_full_class_name": "QNearFieldTarget.AccessMethods", + "enum_full_class_name": "QNearFieldTarget.AccessMethod", + "enum_value1": "UnknownAccess", + "enum_value2": "NdefAccess", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNfc", + "module_path": "../../PyQt5-stubs/QtNfc.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "SecurityFlags", + "enum_class": "Security", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetooth.h:Q_DECLARE_FLAGS(SecurityFlags, Security)" + ], + "qflag_full_class_name": "QBluetooth.SecurityFlags", + "enum_full_class_name": "QBluetooth.Security", + "enum_value1": "NoSecurity", + "enum_value2": "Authorization", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "AttAccessConstraints", + "enum_class": "AttAccessConstraint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetooth.h:Q_DECLARE_FLAGS(AttAccessConstraints, AttAccessConstraint)" + ], + "qflag_full_class_name": "QBluetooth.AttAccessConstraints", + "enum_full_class_name": "QBluetooth.AttAccessConstraint", + "enum_value1": "AttAuthorizationRequired", + "enum_value2": "AttAuthenticationRequired", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "ServiceClasses", + "enum_class": "ServiceClass", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(ServiceClasses, ServiceClass)" + ], + "qflag_full_class_name": "QBluetoothDeviceInfo.ServiceClasses", + "enum_full_class_name": "QBluetoothDeviceInfo.ServiceClass", + "enum_value1": "NoService", + "enum_value2": "PositioningService", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Fields", + "enum_class": "Field", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(Fields, Field)" + ], + "qflag_full_class_name": "QBluetoothDeviceInfo.Fields", + "enum_full_class_name": "QBluetoothDeviceInfo.Field", + "enum_value1": "None_", + "enum_value2": "RSSI", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "CoreConfigurations", + "enum_class": "CoreConfiguration", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(CoreConfigurations, CoreConfiguration)" + ], + "qflag_full_class_name": "QBluetoothDeviceInfo.CoreConfigurations", + "enum_full_class_name": "QBluetoothDeviceInfo.CoreConfiguration", + "enum_value1": "UnknownCoreConfiguration", + "enum_value2": "LowEnergyCoreConfiguration", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "PropertyTypes", + "enum_class": "PropertyType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qlowenergycharacteristic.h: Q_DECLARE_FLAGS(PropertyTypes, PropertyType)" + ], + "qflag_full_class_name": "QLowEnergyCharacteristic.PropertyTypes", + "enum_full_class_name": "QLowEnergyCharacteristic.PropertyType", + "enum_value1": "Unknown", + "enum_value2": "Broadcasting", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "ServiceTypes", + "enum_class": "ServiceType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qlowenergyservice.h: Q_DECLARE_FLAGS(ServiceTypes, ServiceType)" + ], + "qflag_full_class_name": "QLowEnergyService.ServiceTypes", + "enum_full_class_name": "QLowEnergyService.ServiceType", + "enum_value1": "PrimaryService", + "enum_value2": "IncludedService", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "SelectionFlags", + "enum_class": "SelectionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualizationqml2\\abstractdeclarative_p.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)", + "src\\datavisualization\\engine\\qabstract3dgraph.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)" + ], + "qflag_full_class_name": "QAbstract3DGraph.SelectionFlags", + "enum_full_class_name": "QAbstract3DGraph.SelectionFlag", + "enum_value1": "SelectionNone", + "enum_value2": "SelectionItem", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDataVisualization", + "module_path": "../../PyQt5-stubs/QtDataVisualization.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "OptimizationHints", + "enum_class": "OptimizationHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualizationqml2\\abstractdeclarative_p.h: Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint)", + "src\\datavisualization\\engine\\qabstract3dgraph.h: Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint)" + ], + "qflag_full_class_name": "QAbstract3DGraph.OptimizationHints", + "enum_full_class_name": "QAbstract3DGraph.OptimizationHint", + "enum_value1": "OptimizationDefault", + "enum_value2": "OptimizationStatic", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDataVisualization", + "module_path": "../../PyQt5-stubs/QtDataVisualization.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "DrawFlags", + "enum_class": "DrawFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualization\\data\\qsurface3dseries.h: Q_DECLARE_FLAGS(DrawFlags, DrawFlag)" + ], + "qflag_full_class_name": "QSurface3DSeries.DrawFlags", + "enum_full_class_name": "QSurface3DSeries.DrawFlag", + "enum_value1": "DrawWireframe", + "enum_value2": "DrawSurface", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDataVisualization", + "module_path": "../../PyQt5-stubs/QtDataVisualization.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "QQuickItem.Flags", + "enum_full_class_name": "QQuickItem.Flag", + "enum_value1": "ItemClipsChildrenToShape", + "enum_value2": "ItemAcceptsInputMethod", + "module_count": 4, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "QSGMaterial.Flags", + "enum_full_class_name": "QSGMaterial.Flag", + "enum_value1": "Blending", + "enum_value2": "RequiresDeterminant", + "module_count": 4, + "module_idx": 1, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "QSGNode.Flags", + "enum_full_class_name": "QSGNode.Flag", + "enum_value1": "OwnedByParent", + "enum_value2": "UsePreprocess", + "module_count": 4, + "module_idx": 2, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "QSGMaterialRhiShader.Flags", + "enum_full_class_name": "QSGMaterialRhiShader.Flag", + "enum_value1": "UpdatesGraphicsPipelineState", + "enum_value2": "UpdatesGraphicsPipelineState", + "module_count": 4, + "module_idx": 3, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "QQmlImageProviderBase.Flags", + "enum_full_class_name": "QQmlImageProviderBase.Flag", + "enum_value1": "ForceAsynchronousImageLoading", + "enum_value2": "ForceAsynchronousImageLoading", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQml", + "module_path": "../../PyQt5-stubs/QtQml.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Extensions", + "enum_class": "Extension", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\qml\\jsapi\\qjsengine.h: Q_DECLARE_FLAGS(Extensions, Extension)" + ], + "qflag_full_class_name": "QJSEngine.Extensions", + "enum_full_class_name": "QJSEngine.Extension", + "enum_value1": "TranslationExtension", + "enum_value2": "ConsoleExtension", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQml", + "module_path": "../../PyQt5-stubs/QtQml.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "PerformanceHints", + "enum_class": "PerformanceHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickpainteditem.h: Q_DECLARE_FLAGS(PerformanceHints, PerformanceHint)" + ], + "qflag_full_class_name": "QQuickPaintedItem.PerformanceHints", + "enum_full_class_name": "QQuickPaintedItem.PerformanceHint", + "enum_value1": "FastFBOResizing", + "enum_value2": "FastFBOResizing", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "CreateTextureOptions", + "enum_class": "CreateTextureOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickwindow.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)", + "src\\quick\\scenegraph\\util\\qsgengine.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)" + ], + "qflag_full_class_name": "QQuickWindow.CreateTextureOptions", + "enum_full_class_name": "QQuickWindow.CreateTextureOption", + "enum_value1": "TextureHasAlphaChannel", + "enum_value2": "TextureHasMipmaps", + "module_count": 2, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "CreateTextureOptions", + "enum_class": "CreateTextureOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickwindow.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)", + "src\\quick\\scenegraph\\util\\qsgengine.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)" + ], + "qflag_full_class_name": "QSGEngine.CreateTextureOptions", + "enum_full_class_name": "QSGEngine.CreateTextureOption", + "enum_value1": "TextureHasAlphaChannel", + "enum_value2": "TextureOwnsGLTexture", + "module_count": 2, + "module_idx": 1, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "ClearMode", + "enum_class": "ClearModeBit", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgabstractrenderer.h: Q_DECLARE_FLAGS(ClearMode, ClearModeBit)" + ], + "qflag_full_class_name": "QSGAbstractRenderer.ClearMode", + "enum_full_class_name": "QSGAbstractRenderer.ClearModeBit", + "enum_value1": "ClearColorBuffer", + "enum_value2": "ClearDepthBuffer", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "MatrixTransformFlags", + "enum_class": "MatrixTransformFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgabstractrenderer.h: Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag)" + ], + "qflag_full_class_name": "QSGAbstractRenderer.MatrixTransformFlags", + "enum_full_class_name": "QSGAbstractRenderer.MatrixTransformFlag", + "enum_value1": "MatrixTransformFlipY", + "enum_value2": "MatrixTransformFlipY", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "ColorMask", + "enum_class": "ColorMaskComponent", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)" + ], + "qflag_full_class_name": "QSGMaterialRhiShader.GraphicsPipelineState.ColorMask", + "enum_full_class_name": "QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent", + "enum_value1": "R", + "enum_value2": "G", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "DirtyState", + "enum_class": "DirtyStateBit", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(DirtyState, DirtyStateBit)" + ], + "qflag_full_class_name": "QSGNode.DirtyState", + "enum_full_class_name": "QSGNode.DirtyStateBit", + "enum_value1": "DirtyMatrix", + "enum_value2": "DirtyNodeAdded", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "ShaderCompilationTypes", + "enum_class": "ShaderCompilationType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendererinterface.h: Q_DECLARE_FLAGS(ShaderCompilationTypes, ShaderCompilationType)" + ], + "qflag_full_class_name": "QSGRendererInterface.ShaderCompilationTypes", + "enum_full_class_name": "QSGRendererInterface.ShaderCompilationType", + "enum_value1": "RuntimeCompilation", + "enum_value2": "OfflineCompilation", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "ShaderSourceTypes", + "enum_class": "ShaderSourceType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendererinterface.h: Q_DECLARE_FLAGS(ShaderSourceTypes, ShaderSourceType)" + ], + "qflag_full_class_name": "QSGRendererInterface.ShaderSourceTypes", + "enum_full_class_name": "QSGRendererInterface.ShaderSourceType", + "enum_value1": "ShaderSourceString", + "enum_value2": "ShaderSourceFile", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "StateFlags", + "enum_class": "StateFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendernode.h: Q_DECLARE_FLAGS(StateFlags, StateFlag)" + ], + "qflag_full_class_name": "QSGRenderNode.StateFlags", + "enum_full_class_name": "QSGRenderNode.StateFlag", + "enum_value1": "DepthState", + "enum_value2": "StencilState", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "RenderingFlags", + "enum_class": "RenderingFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendernode.h: Q_DECLARE_FLAGS(RenderingFlags, RenderingFlag)" + ], + "qflag_full_class_name": "QSGRenderNode.RenderingFlags", + "enum_full_class_name": "QSGRenderNode.RenderingFlag", + "enum_value1": "BoundedRectRendering", + "enum_value2": "DepthAwareRendering", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "TextureCoordinatesTransformMode", + "enum_class": "TextureCoordinatesTransformFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\util\\qsgimagenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)", + "src\\quick\\scenegraph\\util\\qsgsimpletexturenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)" + ], + "qflag_full_class_name": "QSGImageNode.TextureCoordinatesTransformMode", + "enum_full_class_name": "QSGImageNode.TextureCoordinatesTransformFlag", + "enum_value1": "NoTransform", + "enum_value2": "MirrorHorizontally", + "module_count": 2, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "TextureCoordinatesTransformMode", + "enum_class": "TextureCoordinatesTransformFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\util\\qsgimagenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)", + "src\\quick\\scenegraph\\util\\qsgsimpletexturenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)" + ], + "qflag_full_class_name": "QSGSimpleTextureNode.TextureCoordinatesTransformMode", + "enum_full_class_name": "QSGSimpleTextureNode.TextureCoordinatesTransformFlag", + "enum_value1": "NoTransform", + "enum_value2": "MirrorHorizontally", + "module_count": 2, + "module_idx": 1, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "VisibilityScope", + "enum_class": "Visibility", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\qlocation.h:Q_DECLARE_FLAGS(VisibilityScope, Visibility)" + ], + "qflag_full_class_name": "QLocation.VisibilityScope", + "enum_full_class_name": "QLocation.Visibility", + "enum_value1": "UnspecifiedVisibility", + "enum_value2": "DeviceVisibility", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "PositioningMethods", + "enum_class": "PositioningMethod", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\positioningquick\\qdeclarativepositionsource_p.h: Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod)", + "src\\positioning\\qgeopositioninfosource.h: Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod)" + ], + "qflag_full_class_name": "QGeoPositionInfoSource.PositioningMethods", + "enum_full_class_name": "QGeoPositionInfoSource.PositioningMethod", + "enum_value1": "NoPositioningMethods", + "enum_value2": "SatellitePositioningMethods", + "module_count": 1, + "module_idx": 0, + "module_name": "QtPositioning", + "module_path": "../../PyQt5-stubs/QtPositioning.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "AreaMonitorFeatures", + "enum_class": "AreaMonitorFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\positioning\\qgeoareamonitorsource.h: Q_DECLARE_FLAGS(AreaMonitorFeatures, AreaMonitorFeature)" + ], + "qflag_full_class_name": "QGeoAreaMonitorSource.AreaMonitorFeatures", + "enum_full_class_name": "QGeoAreaMonitorSource.AreaMonitorFeature", + "enum_value1": "PersistentAreaMonitorFeature", + "enum_value2": "AnyAreaMonitorFeature", + "module_count": 1, + "module_idx": 0, + "module_name": "QtPositioning", + "module_path": "../../PyQt5-stubs/QtPositioning.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "TravelModes", + "enum_class": "TravelMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(TravelModes, TravelMode)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(TravelModes, TravelMode)" + ], + "qflag_full_class_name": "QGeoRouteRequest.TravelModes", + "enum_full_class_name": "QGeoRouteRequest.TravelMode", + "enum_value1": "CarTravel", + "enum_value2": "PedestrianTravel", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "FeatureTypes", + "enum_class": "FeatureType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(FeatureTypes, FeatureType)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(FeatureTypes, FeatureType)" + ], + "qflag_full_class_name": "QGeoRouteRequest.FeatureTypes", + "enum_full_class_name": "QGeoRouteRequest.FeatureType", + "enum_value1": "NoFeature", + "enum_value2": "TollFeature", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "FeatureWeights", + "enum_class": "FeatureWeight", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight)" + ], + "qflag_full_class_name": "QGeoRouteRequest.FeatureWeights", + "enum_full_class_name": "QGeoRouteRequest.FeatureWeight", + "enum_value1": "NeutralFeatureWeight", + "enum_value2": "PreferFeatureWeight", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "RouteOptimizations", + "enum_class": "RouteOptimization", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization)" + ], + "qflag_full_class_name": "QGeoRouteRequest.RouteOptimizations", + "enum_full_class_name": "QGeoRouteRequest.RouteOptimization", + "enum_value1": "ShortestRoute", + "enum_value2": "FastestRoute", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "SegmentDetails", + "enum_class": "SegmentDetail", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(SegmentDetails, SegmentDetail)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(SegmentDetails, SegmentDetail)" + ], + "qflag_full_class_name": "QGeoRouteRequest.SegmentDetails", + "enum_full_class_name": "QGeoRouteRequest.SegmentDetail", + "enum_value1": "NoSegmentData", + "enum_value2": "BasicSegmentData", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "ManeuverDetails", + "enum_class": "ManeuverDetail", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(ManeuverDetails, ManeuverDetail)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(ManeuverDetails, ManeuverDetail)" + ], + "qflag_full_class_name": "QGeoRouteRequest.ManeuverDetails", + "enum_full_class_name": "QGeoRouteRequest.ManeuverDetail", + "enum_value1": "NoManeuvers", + "enum_value2": "BasicManeuvers", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "RoutingFeatures", + "enum_class": "RoutingFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature)" + ], + "qflag_full_class_name": "QGeoServiceProvider.RoutingFeatures", + "enum_full_class_name": "QGeoServiceProvider.RoutingFeature", + "enum_value1": "NoRoutingFeatures", + "enum_value2": "OnlineRoutingFeature", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "GeocodingFeatures", + "enum_class": "GeocodingFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature)" + ], + "qflag_full_class_name": "QGeoServiceProvider.GeocodingFeatures", + "enum_full_class_name": "QGeoServiceProvider.GeocodingFeature", + "enum_value1": "NoGeocodingFeatures", + "enum_value2": "OnlineGeocodingFeature", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "MappingFeatures", + "enum_class": "MappingFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(MappingFeatures, MappingFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(MappingFeatures, MappingFeature)" + ], + "qflag_full_class_name": "QGeoServiceProvider.MappingFeatures", + "enum_full_class_name": "QGeoServiceProvider.MappingFeature", + "enum_value1": "NoMappingFeatures", + "enum_value2": "OnlineMappingFeature", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "PlacesFeatures", + "enum_class": "PlacesFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature)" + ], + "qflag_full_class_name": "QGeoServiceProvider.PlacesFeatures", + "enum_full_class_name": "QGeoServiceProvider.PlacesFeature", + "enum_value1": "NoPlacesFeatures", + "enum_value2": "OnlinePlacesFeature", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "NavigationFeatures", + "enum_class": "NavigationFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(NavigationFeatures, NavigationFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(NavigationFeatures, NavigationFeature)" + ], + "qflag_full_class_name": "QGeoServiceProvider.NavigationFeatures", + "enum_full_class_name": "QGeoServiceProvider.NavigationFeature", + "enum_value1": "NoNavigationFeatures", + "enum_value2": "OnlineNavigationFeature", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "CaptureModes", + "enum_class": "CaptureMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcamera.h: Q_DECLARE_FLAGS(CaptureModes, CaptureMode)" + ], + "qflag_full_class_name": "QCamera.CaptureModes", + "enum_full_class_name": "QCamera.CaptureMode", + "enum_value1": "CaptureViewfinder", + "enum_value2": "CaptureStillImage", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "LockTypes", + "enum_class": "LockType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcamera.h: Q_DECLARE_FLAGS(LockTypes, LockType)" + ], + "qflag_full_class_name": "QCamera.LockTypes", + "enum_full_class_name": "QCamera.LockType", + "enum_value1": "NoLock", + "enum_value2": "LockExposure", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "FlashModes", + "enum_class": "FlashMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcameraexposure.h: Q_DECLARE_FLAGS(FlashModes, FlashMode)" + ], + "qflag_full_class_name": "QCameraExposure.FlashModes", + "enum_full_class_name": "QCameraExposure.FlashMode", + "enum_value1": "FlashAuto", + "enum_value2": "FlashOff", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "FocusModes", + "enum_class": "FocusMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcamerafocus.h: Q_DECLARE_FLAGS(FocusModes, FocusMode)" + ], + "qflag_full_class_name": "QCameraFocus.FocusModes", + "enum_full_class_name": "QCameraFocus.FocusMode", + "enum_value1": "ManualFocus", + "enum_value2": "HyperfocalFocus", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "CaptureDestinations", + "enum_class": "CaptureDestination", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcameraimagecapture.h: Q_DECLARE_FLAGS(CaptureDestinations, CaptureDestination)" + ], + "qflag_full_class_name": "QCameraImageCapture.CaptureDestinations", + "enum_full_class_name": "QCameraImageCapture.CaptureDestination", + "enum_value1": "CaptureToFile", + "enum_value2": "CaptureToBuffer", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\playback\\qmediaplayer.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "QMediaPlayer.Flags", + "enum_full_class_name": "QMediaPlayer.Flag", + "enum_value1": "LowLatency", + "enum_value2": "StreamPlayback", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + }, + { + "qflag_class": "RunFlags", + "enum_class": "RunFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\video\\qabstractvideofilter.h: Q_DECLARE_FLAGS(RunFlags, RunFlag)" + ], + "qflag_full_class_name": "QVideoFilterRunnable.RunFlags", + "enum_full_class_name": "QVideoFilterRunnable.RunFlag", + "enum_value1": "LastInChain", + "enum_value2": "LastInChain", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Directions", + "enum_class": "Direction", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\serialport\\qserialport.h: Q_DECLARE_FLAGS(Directions, Direction)" + ], + "qflag_full_class_name": "QSerialPort.Directions", + "enum_full_class_name": "QSerialPort.Direction", + "enum_value1": "Input", + "enum_value2": "Output", + "module_count": 1, + "module_idx": 0, + "module_name": "QtSerialPort", + "module_path": "../../PyQt5-stubs/QtSerialPort.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "PinoutSignals", + "enum_class": "PinoutSignal", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\serialport\\qserialport.h: Q_DECLARE_FLAGS(PinoutSignals, PinoutSignal)" + ], + "qflag_full_class_name": "QSerialPort.PinoutSignals", + "enum_full_class_name": "QSerialPort.PinoutSignal", + "enum_value1": "NoSignal", + "enum_value2": "TransmittedDataSignal", + "module_count": 1, + "module_idx": 0, + "module_name": "QtSerialPort", + "module_path": "../../PyQt5-stubs/QtSerialPort.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "QWebEngineUrlScheme.Flags", + "human_hint_enum_full_class_name": "QWebEngineUrlScheme.Flag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "QWebEngineUrlScheme.Flags", + "enum_full_class_name": "QWebEngineUrlScheme.Flag", + "enum_value1": "SecureScheme", + "enum_value2": "LocalScheme", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebEngineCore", + "module_path": "../../PyQt5-stubs/QtWebEngineCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "MediaFlags", + "enum_class": "MediaFlag", + "human_hint_qflag_full_class_name": "QWebEngineContextMenuData.MediaFlags", + "human_hint_enum_full_class_name": "QWebEngineContextMenuData.MediaFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "QWebEngineContextMenuData.MediaFlags", + "enum_full_class_name": "QWebEngineContextMenuData.MediaFlag", + "enum_value1": "MediaInError", + "enum_value2": "MediaPaused", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebEngineWidgets", + "module_path": "../../PyQt5-stubs/QtWebEngineWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "EditFlags", + "enum_class": "EditFlag", + "human_hint_qflag_full_class_name": "QWebEngineContextMenuData.EditFlags", + "human_hint_enum_full_class_name": "QWebEngineContextMenuData.EditFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "QWebEngineContextMenuData.EditFlags", + "enum_full_class_name": "QWebEngineContextMenuData.EditFlag", + "enum_value1": "CanUndo", + "enum_value2": "CanRedo", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebEngineWidgets", + "module_path": "../../PyQt5-stubs/QtWebEngineWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "FindFlags", + "enum_class": "FindFlag", + "human_hint_qflag_full_class_name": "QWebEnginePage.FindFlags", + "human_hint_enum_full_class_name": "QWebEnginePage.FindFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "QWebEnginePage.FindFlags", + "enum_full_class_name": "QWebEnginePage.FindFlag", + "enum_value1": "FindBackward", + "enum_value2": "FindCaseSensitively", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebEngineWidgets", + "module_path": "../../PyQt5-stubs/QtWebEngineWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true + }, + { + "qflag_class": "Feature", + "enum_class": "FeatureFlag", + "human_hint_qflag_full_class_name": "QDesignerFormWindowInterface.Feature", + "human_hint_enum_full_class_name": "QDesignerFormWindowInterface.FeatureFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "QDesignerFormWindowInterface.Feature", + "enum_full_class_name": "QDesignerFormWindowInterface.FeatureFlag", + "enum_value1": "EditFeature", + "enum_value2": "GridFeature", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDesigner", + "module_path": "../../PyQt5-stubs/QtDesigner.pyi", + "or_converts_to_multi": false, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": false, + "supports_one_op_multi": true + } + ], + "qflag_process_error": [ + { + "qflag_class": "FormattingOptions", + "enum_class": "UrlFormattingOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qurl.h: Q_DECLARE_FLAGS(FormattingOptions, UrlFormattingOption)" + ], + "qflag_full_class_name": "QUrl.FormattingOptions", + "enum_full_class_name": "QUrl.UrlFormattingOption", + "enum_value1": "None_", + "enum_value2": "RemoveScheme", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": false, + "error": [ + "Enum methods are present but not QFlag methods" + ] + }, + { + "qflag_class": "DiscoveryMethods", + "enum_class": "DiscoveryMethod", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdevicediscoveryagent.h: Q_DECLARE_FLAGS(DiscoveryMethods, DiscoveryMethod)" + ], + "qflag_full_class_name": "QBluetoothDeviceDiscoveryAgent.DiscoveryMethods", + "enum_full_class_name": "QBluetoothDeviceDiscoveryAgent.DiscoveryMethod", + "enum_value1": "NoMethod", + "enum_value2": "ClassicMethod", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true, + "error": [ + "Traceback (most recent call last):", + " File \"generate_qflags_stubs_and_tests.py\", line 552, in generate_missing_stubs", + " flag_info.or_converts_to_multi = not eval('''type({qtmodule}.{oneFlagName}.{value1} | {qtmodule}.{oneFlagName}.{value2}) == int'''.format(", + " File \"\", line 1, in ", + "AttributeError: sip.enumtype object 'DiscoveryMethod' has no member 'NoMethod'" + ] + }, + { + "qflag_class": "DirtyStates", + "enum_class": "DirtyState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgmaterialshader.h: Q_DECLARE_FLAGS(DirtyStates, DirtyState)" + ], + "qflag_full_class_name": "QSGMaterialShader.RenderState.DirtyStates", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true, + "error": [ + "Could not locate class DirtyState" + ] + }, + { + "qflag_class": "RenderLayers", + "enum_class": "RenderLayer", + "human_hint_qflag_full_class_name": "QWebFrame.RenderLayers", + "human_hint_enum_full_class_name": "QWebFrame.RenderLayer", + "grep_line": [ + "" + ], + "qflag_full_class_name": "QWebFrame.RenderLayers", + "enum_full_class_name": "QWebFrame.RenderLayer", + "enum_value1": "ContentsLayer", + "enum_value2": "ScrollBarLayer", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebKitWiddgets", + "module_path": "../../PyQt5-stubs/QtWebKitWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true, + "error": [ + "Traceback (most recent call last):", + " File \"generate_qflags_stubs_and_tests.py\", line 601, in generate_missing_stubs", + " flag_info.or_converts_to_multi = not eval('''type({qtmodule}.{oneFlagName}.{value1} | {qtmodule}.{oneFlagName}.{value2}) == int'''.format(", + " File \"\", line 1, in ", + "NameError: name 'QtWebKitWiddgets' is not defined" + ] + }, + { + "qflag_class": "FindFlags", + "enum_class": "FindFlag", + "human_hint_qflag_full_class_name": "QWebPage.FindFlags", + "human_hint_enum_full_class_name": "QWebPage.FindFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "QWebPage.FindFlags", + "enum_full_class_name": "QWebPage.FindFlag", + "enum_value1": "FindBackward", + "enum_value2": "FindCaseSensitively", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebKitWiddgets", + "module_path": "../../PyQt5-stubs/QtWebKitWidgets.pyi", + "or_converts_to_multi": true, + "or_int_converts_to_multi": false, + "int_or_converts_to_multi": true, + "supports_one_op_multi": true, + "error": [ + "Traceback (most recent call last):", + " File \"generate_qflags_stubs_and_tests.py\", line 601, in generate_missing_stubs", + " flag_info.or_converts_to_multi = not eval('''type({qtmodule}.{oneFlagName}.{value1} | {qtmodule}.{oneFlagName}.{value2}) == int'''.format(", + " File \"\", line 1, in ", + "NameError: name 'QtWebKitWiddgets' is not defined" + ] + } + ] +} \ No newline at end of file diff --git a/tests/qflags/qflags_test_template.py b/tests/qflags/qflags_test_template.py new file mode 100644 index 00000000..935a1d5a --- /dev/null +++ b/tests/qflags/qflags_test_template.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# This file is used as a source to generate all qflags related tests. The specific part +# changes for each test but the rest of the file is totally identical +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.WindowType +MultiFlagClass = QtCore.Qt.WindowFlags + +oneFlagRefValue1 = QtCore.Qt.WindowContextHelpButtonHint +oneFlagRefValue2 = QtCore.Qt.WindowMaximizeButtonHint + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/qflags_to_process.json b/tests/qflags/qflags_to_process.json new file mode 100644 index 00000000..7ef0c0b1 --- /dev/null +++ b/tests/qflags/qflags_to_process.json @@ -0,0 +1,3721 @@ +{ + "__": "This file can be adjusted manually by a human prior to being processed by the tool", + "qflags_to_process": [ + { + "qflag_class": "RegisterOptions", + "enum_class": "RegisterOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\dbus\\qdbusconnection.h: Q_DECLARE_FLAGS(RegisterOptions, RegisterOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDBus", + "module_path": "../../PyQt5-stubs/QtDBus.pyi" + }, + { + "qflag_class": "ConnectionCapabilities", + "enum_class": "ConnectionCapability", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\dbus\\qdbusconnection.h: Q_DECLARE_FLAGS(ConnectionCapabilities, ConnectionCapability)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDBus", + "module_path": "../../PyQt5-stubs/QtDBus.pyi" + }, + { + "qflag_class": "FormatOptions", + "enum_class": "FormatOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qgl.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption)", + "src\\gui\\kernel\\qsurfaceformat.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "FormatOptions", + "enum_class": "FormatOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qgl.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption)", + "src\\gui\\kernel\\qsurfaceformat.h: Q_DECLARE_FLAGS(FormatOptions, FormatOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtOpenGL", + "module_path": "../../PyQt5-stubs/QtOpenGL.pyi" + }, + { + "qflag_class": "OpenGLVersionFlags", + "enum_class": "OpenGLVersionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qgl.h: Q_DECLARE_FLAGS(OpenGLVersionFlags, OpenGLVersionFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtOpenGL", + "module_path": "../../PyQt5-stubs/QtOpenGL.pyi" + }, + { + "qflag_class": "BindOptions", + "enum_class": "BindOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qgl.h: Q_DECLARE_FLAGS(BindOptions, BindOption)", + "src\\gui\\opengl\\qopengltextureuploader_p.h: Q_DECLARE_FLAGS(BindOptions, BindOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtOpenGL", + "module_path": "../../PyQt5-stubs/QtOpenGL.pyi" + }, + { + "qflag_class": "ShaderType", + "enum_class": "ShaderTypeBit", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\opengl\\qglshaderprogram.h: Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)", + "src\\gui\\opengl\\qopenglshaderprogram.h: Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "WatchMode", + "enum_class": "WatchModeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\dbus\\qdbusservicewatcher.h: Q_DECLARE_FLAGS(WatchMode, WatchModeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDBus", + "module_path": "../../PyQt5-stubs/QtDBus.pyi" + }, + { + "qflag_class": "ConversionFlags", + "enum_class": "ConversionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\codecs\\qtextcodec.h: Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)", + "src\\corelib\\codecs\\qtextcodec_p.h: Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "CheckIndexOptions", + "enum_class": "CheckIndexOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\itemmodels\\qabstractitemmodel.h: Q_DECLARE_FLAGS(CheckIndexOptions, CheckIndexOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "Filters", + "enum_class": "Filter", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qdir.h: Q_DECLARE_FLAGS(Filters, Filter)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "SortFlags", + "enum_class": "SortFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qdir.h: Q_DECLARE_FLAGS(SortFlags, SortFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "IteratorFlags", + "enum_class": "IteratorFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qdiriterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)", + "src\\widgets\\itemviews\\qtreewidgetitemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)", + "tests\\benchmarks\\corelib\\io\\qdiriterator\\qfilesystemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "IteratorFlags", + "enum_class": "IteratorFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qdiriterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)", + "src\\widgets\\itemviews\\qtreewidgetitemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)", + "tests\\benchmarks\\corelib\\io\\qdiriterator\\qfilesystemiterator.h: Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "Permissions", + "enum_class": "Permission", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qfiledevice.h: Q_DECLARE_FLAGS(Permissions, Permission)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "FileHandleFlags", + "enum_class": "FileHandleFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qfiledevice.h: Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "SelectionFlags", + "enum_class": "SelectionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\itemmodels\\qitemselectionmodel.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "KeyboardModifiers", + "enum_class": "KeyboardModifier", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(KeyboardModifiers, KeyboardModifier)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "MouseButtons", + "enum_class": "MouseButton", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(MouseButtons, MouseButton)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "Orientations", + "enum_class": "Orientation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(Orientations, Orientation)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "Alignment", + "enum_class": "AlignmentFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(Alignment, AlignmentFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "WindowFlags", + "enum_class": "WindowType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(WindowFlags, WindowType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "WindowStates", + "enum_class": "WindowState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(WindowStates, WindowState)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "ApplicationStates", + "enum_class": "ApplicationState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ApplicationStates, ApplicationState)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "ScreenOrientations", + "enum_class": "ScreenOrientation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ScreenOrientations, ScreenOrientation)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "ImageConversionFlags", + "enum_class": "ImageConversionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ImageConversionFlags, ImageConversionFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "DockWidgetAreas", + "enum_class": "DockWidgetArea", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "ToolBarAreas", + "enum_class": "ToolBarArea", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ToolBarAreas, ToolBarArea)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "Edges", + "enum_class": "Edge", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(Edges, Edge)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "InputMethodQueries", + "enum_class": "InputMethodQuery", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(InputMethodQueries, InputMethodQuery)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "InputMethodHints", + "enum_class": "InputMethodHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(InputMethodHints, InputMethodHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "FindChildOptions", + "enum_class": "FindChildOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(FindChildOptions, FindChildOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "DropActions", + "enum_class": "DropAction", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(DropActions, DropAction)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "ItemFlags", + "enum_class": "ItemFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(ItemFlags, ItemFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "MatchFlags", + "enum_class": "MatchFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(MatchFlags, MatchFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "TextInteractionFlags", + "enum_class": "TextInteractionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(TextInteractionFlags, TextInteractionFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "TouchPointStates", + "enum_class": "TouchPointState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(TouchPointStates, TouchPointState)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "GestureFlags", + "enum_class": "GestureFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(GestureFlags, GestureFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "MouseEventFlags", + "enum_class": "MouseEventFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\global\\qnamespace.h: Q_DECLARE_FLAGS(MouseEventFlags, MouseEventFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "Transformations", + "enum_class": "Transformation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\image\\qimageiohandler.h: Q_DECLARE_FLAGS(Transformations, Transformation)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "Capabilities", + "enum_class": "Capability", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\image\\qimageiohandler.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\gui\\kernel\\qplatformcursor.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\gui\\painting\\qblittable_p.h: Q_DECLARE_FLAGS (Capabilities, Capability)", + "src\\network\\bearer\\qnetworkconfigmanager.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\network\\kernel\\qnetworkproxy.h: Q_DECLARE_FLAGS(Capabilities, Capability)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "Capabilities", + "enum_class": "Capability", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\image\\qimageiohandler.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\gui\\kernel\\qplatformcursor.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\gui\\painting\\qblittable_p.h: Q_DECLARE_FLAGS (Capabilities, Capability)", + "src\\network\\bearer\\qnetworkconfigmanager.h: Q_DECLARE_FLAGS(Capabilities, Capability)", + "src\\network\\kernel\\qnetworkproxy.h: Q_DECLARE_FLAGS(Capabilities, Capability)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 1, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "ProcessEventsFlags", + "enum_class": "ProcessEventsFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\kernel\\qeventloop.h: Q_DECLARE_FLAGS(ProcessEventsFlags, ProcessEventsFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "OpenMode", + "enum_class": "OpenModeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qiodevice.h: Q_DECLARE_FLAGS(OpenMode, OpenModeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "InfoFlags", + "enum_class": "InfoFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qevent.h: Q_DECLARE_FLAGS(InfoFlags, InfoFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "LoadHints", + "enum_class": "LoadHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\plugin\\qlibrary.h: Q_DECLARE_FLAGS(LoadHints, LoadHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "RangeAccessFlags", + "enum_class": "RangeAccessFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\opengl\\qopenglbuffer.h: Q_DECLARE_FLAGS(RangeAccessFlags, RangeAccessFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "Sources", + "enum_class": "Source", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\opengl\\qopengldebug.h: Q_DECLARE_FLAGS(Sources, Source)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "Types", + "enum_class": "Type", + "human_hint_qflag_full_class_name": "QOpenGLDebugMessage.Types", + "human_hint_enum_full_class_name": "QOpenGLDebugMessage.Type", + "grep_line": [ + "src\\gui\\opengl\\qopengldebug.h: Q_DECLARE_FLAGS(Types, Type)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "Severities", + "enum_class": "Severity", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\opengl\\qopengldebug.h: Q_DECLARE_FLAGS(Severities, Severity)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "TypeFlags", + "enum_class": "TypeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\kernel\\qmetatype.h: Q_DECLARE_FLAGS(TypeFlags, TypeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "LocateOptions", + "enum_class": "LocateOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qstandardpaths.h: Q_DECLARE_FLAGS(LocateOptions, LocateOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\kernel\\qppsattribute_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\painting\\qplatformbackingstore.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\vulkan\\qvulkaninstance.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qshader_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\vulkan\\qvulkanwindow.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\text\\qtextoption.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\corelib\\tools\\qcommandlineoption.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\platformsupport\\eglconvenience\\qeglplatformcontext_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\platformsupport\\fbconvenience\\qfbscreen_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\plugins\\platforms\\direct2d\\qwindowsdirect2dpaintengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\tools\\moc\\namespaced-flags.h: Q_DECLARE_FLAGS( Flags, Flag )", + "src\\plugins\\platforms\\eglfs\\api\\qeglfswindow_p.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\kernel\\qppsattribute_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\painting\\qplatformbackingstore.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qrhi_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\vulkan\\qvulkaninstance.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\rhi\\qshader_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\vulkan\\qvulkanwindow.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\gui\\text\\qtextoption.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\corelib\\tools\\qcommandlineoption.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\platformsupport\\eglconvenience\\qeglplatformcontext_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\platformsupport\\fbconvenience\\qfbscreen_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\plugins\\platforms\\direct2d\\qwindowsdirect2dpaintengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\tools\\moc\\namespaced-flags.h: Q_DECLARE_FLAGS( Flags, Flag )", + "src\\plugins\\platforms\\eglfs\\api\\qeglfswindow_p.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "PolicyFlags", + "enum_class": "PolicyFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\access\\qhstspolicy.h: Q_DECLARE_FLAGS(PolicyFlags, PolicyFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "StandardButtons", + "enum_class": "StandardButton", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qplatformdialoghelper.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)", + "src\\widgets\\dialogs\\qmessagebox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)", + "src\\widgets\\widgets\\qdialogbuttonbox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "StandardButtons", + "enum_class": "StandardButton", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qplatformdialoghelper.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)", + "src\\widgets\\dialogs\\qmessagebox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)", + "src\\widgets\\widgets\\qdialogbuttonbox.h: Q_DECLARE_FLAGS(StandardButtons, StandardButton)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 1, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "ColorDialogOptions", + "enum_class": "ColorDialogOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qplatformdialoghelper.h: Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)", + "src\\widgets\\dialogs\\qcolordialog.h: Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "FontDialogOptions", + "enum_class": "FontDialogOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qplatformdialoghelper.h: Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption)", + "src\\widgets\\dialogs\\qfontdialog.h: Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "ComponentFormattingOptions", + "enum_class": "ComponentFormattingOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qurl.h: Q_DECLARE_FLAGS(ComponentFormattingOptions, ComponentFormattingOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "FormattingOptions", + "enum_class": "UrlFormattingOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qurl.h: Q_DECLARE_FLAGS(FormattingOptions, UrlFormattingOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "UserInputResolutionOptions", + "enum_class": "UserInputResolutionOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\io\\qurl.h: Q_DECLARE_FLAGS(UserInputResolutionOptions, UserInputResolutionOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "StateFlags", + "enum_class": "StateFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\bearer\\qnetworkconfiguration.h: Q_DECLARE_FLAGS(StateFlags, StateFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "UsagePolicies", + "enum_class": "UsagePolicy", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\bearer\\qnetworksession.h: Q_DECLARE_FLAGS(UsagePolicies, UsagePolicy)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "RenderFlags", + "enum_class": "RenderFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpaintengine.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag)", + "src\\widgets\\kernel\\qwidget.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "RenderFlags", + "enum_class": "RenderFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpaintengine.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag)", + "src\\widgets\\kernel\\qwidget.h: Q_DECLARE_FLAGS(RenderFlags, RenderFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "PaintEngineFeatures", + "enum_class": "PaintEngineFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpaintengine.h: Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "DirtyFlags", + "enum_class": "DirtyFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpaintengine.h: Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "Capabilities", + "enum_class": "CapabilityFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\kernel\\qtouchdevice.h: Q_DECLARE_FLAGS(Capabilities, CapabilityFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "Features", + "enum_class": "Feature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\opengl\\qopengltexture.h: Q_DECLARE_FLAGS(Features, Feature)", + "src\\gui\\text\\qtextmarkdownimporter_p.h: Q_DECLARE_FLAGS(Features, Feature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "RenderHints", + "enum_class": "RenderHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpainter.h: Q_DECLARE_FLAGS(RenderHints, RenderHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "PixmapFragmentHints", + "enum_class": "PixmapFragmentHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\painting\\qpainter.h: Q_DECLARE_FLAGS(PixmapFragmentHints, PixmapFragmentHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "ControlTypes", + "enum_class": "ControlType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\util\\qlayoutpolicy_p.h: Q_DECLARE_FLAGS(ControlTypes, ControlType)", + "src\\widgets\\kernel\\qsizepolicy.h: Q_DECLARE_FLAGS(ControlTypes, ControlType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "GlyphRunFlags", + "enum_class": "GlyphRunFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qglyphrun.h: Q_DECLARE_FLAGS(GlyphRunFlags, GlyphRunFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "LayoutFlags", + "enum_class": "LayoutFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qrawfont.h: Q_DECLARE_FLAGS(LayoutFlags, LayoutFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "MarkdownFeatures", + "enum_class": "MarkdownFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qtextdocument.h: Q_DECLARE_FLAGS(MarkdownFeatures, MarkdownFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "FindFlags", + "enum_class": "FindFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qtextdocument.h: Q_DECLARE_FLAGS(FindFlags, FindFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "ConversionMode", + "enum_class": "ConversionModeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\kernel\\qhostaddress.h: Q_DECLARE_FLAGS(ConversionMode, ConversionModeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "BindMode", + "enum_class": "BindFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\socket\\qabstractsocket.h: Q_DECLARE_FLAGS(BindMode, BindFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "PauseModes", + "enum_class": "PauseMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\socket\\qabstractsocket.h: Q_DECLARE_FLAGS(PauseModes, PauseMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "PageBreakFlags", + "enum_class": "PageBreakFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\gui\\text\\qtextformat.h: Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtGui", + "module_path": "../../PyQt5-stubs/QtGui.pyi" + }, + { + "qflag_class": "SocketOptions", + "enum_class": "SocketOption", + "human_hint_qflag_full_class_name": "QLocalServer.SocketOptions", + "human_hint_enum_full_class_name": "QLocalServer.SocketOption", + "grep_line": [ + "src\\network\\socket\\qlocalserver.h: Q_DECLARE_FLAGS(SocketOptions, SocketOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "InterfaceFlags", + "enum_class": "InterfaceFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\kernel\\qnetworkinterface.h: Q_DECLARE_FLAGS(InterfaceFlags, InterfaceFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "SslOptions", + "enum_class": "SslOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\network\\ssl\\qssl.h: Q_DECLARE_FLAGS(SslOptions, SslOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNetwork", + "module_path": "../../PyQt5-stubs/QtNetwork.pyi" + }, + { + "qflag_class": "Base64Options", + "enum_class": "Base64Option", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qbytearray.h: Q_DECLARE_FLAGS(Base64Options, Base64Option)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "NumberOptions", + "enum_class": "NumberOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qlocale.h: Q_DECLARE_FLAGS(NumberOptions, NumberOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "DataSizeFormats", + "enum_class": "DataSizeFormat", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qlocale.h: Q_DECLARE_FLAGS(DataSizeFormats, DataSizeFormat)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "Sections", + "enum_class": "Section", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\time\\qdatetimeparser_p.h: Q_DECLARE_FLAGS(Sections, Section)", + "src\\widgets\\widgets\\qdatetimeedit.h: Q_DECLARE_FLAGS(Sections, Section)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "PatternOptions", + "enum_class": "PatternOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qregularexpression.h: Q_DECLARE_FLAGS(PatternOptions, PatternOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "MatchOptions", + "enum_class": "MatchOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qregularexpression.h: Q_DECLARE_FLAGS(MatchOptions, MatchOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "NumberFlags", + "enum_class": "NumberFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\serialization\\qtextstream.h: Q_DECLARE_FLAGS(NumberFlags, NumberFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "BoundaryReasons", + "enum_class": "BoundaryReason", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\corelib\\text\\qtextboundaryfinder.h: Q_DECLARE_FLAGS( BoundaryReasons, BoundaryReason )" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtCore", + "module_path": "../../PyQt5-stubs/QtCore.pyi" + }, + { + "qflag_class": "PrintDialogOptions", + "enum_class": "PrintDialogOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\printsupport\\dialogs\\qabstractprintdialog.h: Q_DECLARE_FLAGS(PrintDialogOptions, PrintDialogOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtPrintSupport", + "module_path": "../../PyQt5-stubs/QtPrintSupport.pyi" + }, + { + "qflag_class": "ParamType", + "enum_class": "ParamTypeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\sql\\kernel\\qtsqlglobal.h: Q_DECLARE_FLAGS(ParamType, ParamTypeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtSql", + "module_path": "../../PyQt5-stubs/QtSql.pyi" + }, + { + "qflag_class": "Options", + "enum_class": "Option", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qfiledialog.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\dialogs\\qfilesystemmodel.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\itemviews\\qfileiconprovider.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\cocoa\\qcocoaintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\qnx\\qqnxintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "tests\\benchmarks\\widgets\\graphicsview\\functional\\GraphicsViewBenchmark\\widgets\\settings.h: Q_DECLARE_FLAGS(Options, Option)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 3, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "Options", + "enum_class": "Option", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qfiledialog.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\dialogs\\qfilesystemmodel.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\itemviews\\qfileiconprovider.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\cocoa\\qcocoaintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\qnx\\qqnxintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "tests\\benchmarks\\widgets\\graphicsview\\functional\\GraphicsViewBenchmark\\widgets\\settings.h: Q_DECLARE_FLAGS(Options, Option)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 3, + "module_idx": 1, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "Options", + "enum_class": "Option", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qfiledialog.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\dialogs\\qfilesystemmodel.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\widgets\\itemviews\\qfileiconprovider.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\cocoa\\qcocoaintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "src\\plugins\\platforms\\qnx\\qqnxintegration.h: Q_DECLARE_FLAGS(Options, Option)", + "tests\\benchmarks\\widgets\\graphicsview\\functional\\GraphicsViewBenchmark\\widgets\\settings.h: Q_DECLARE_FLAGS(Options, Option)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 3, + "module_idx": 2, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "ChangeFlags", + "enum_class": "ChangeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\effects\\qgraphicseffect.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)", + "src\\widgets\\kernel\\qgesture.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "ChangeFlags", + "enum_class": "ChangeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\effects\\qgraphicseffect.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)", + "src\\widgets\\kernel\\qgesture.h: Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 1, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "BlurHints", + "enum_class": "BlurHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\effects\\qgraphicseffect.h: Q_DECLARE_FLAGS(BlurHints, BlurHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "InputDialogOptions", + "enum_class": "InputDialogOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qinputdialog.h: Q_DECLARE_FLAGS(InputDialogOptions, InputDialogOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "WizardOptions", + "enum_class": "WizardOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\dialogs\\qwizard.h: Q_DECLARE_FLAGS(WizardOptions, WizardOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "EditTriggers", + "enum_class": "EditTrigger", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\itemviews\\qabstractitemview.h: Q_DECLARE_FLAGS(EditTriggers, EditTrigger)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "GraphicsItemFlags", + "enum_class": "GraphicsItemFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\graphicsview\\qgraphicsitem.h: Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "Result", + "enum_class": "ResultFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\kernel\\qgesturerecognizer.h: Q_DECLARE_FLAGS(Result, ResultFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "SceneLayers", + "enum_class": "SceneLayer", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\graphicsview\\qgraphicsscene.h: Q_DECLARE_FLAGS(SceneLayers, SceneLayer)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "CacheMode", + "enum_class": "CacheModeFlag", + "human_hint_qflag_full_class_name": "QGraphicsView.CacheMode", + "human_hint_enum_full_class_name": "QGraphicsView.CacheModeFlag", + "grep_line": [ + "src\\widgets\\graphicsview\\qgraphicsview.h: Q_DECLARE_FLAGS(CacheMode, CacheModeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "OptimizationFlags", + "enum_class": "OptimizationFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\graphicsview\\qgraphicsview.h: Q_DECLARE_FLAGS(OptimizationFlags, OptimizationFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "State", + "enum_class": "StateFlag", + "human_hint_qflag_full_class_name": "QStyle.State", + "human_hint_enum_full_class_name": "QStyle.StateFlag", + "grep_line": [ + "src\\widgets\\styles\\qstyle.h: Q_DECLARE_FLAGS(State, StateFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "SubControls", + "enum_class": "SubControl", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyle.h: Q_DECLARE_FLAGS(SubControls, SubControl)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "StepEnabled", + "enum_class": "StepEnabledFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qabstractspinbox.h: Q_DECLARE_FLAGS(StepEnabled, StepEnabledFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "FrameFeatures", + "enum_class": "FrameFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(FrameFeatures, FrameFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "ButtonFeatures", + "enum_class": "ButtonFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(ButtonFeatures, ButtonFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "CornerWidgets", + "enum_class": "CornerWidget", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(CornerWidgets, CornerWidget)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "TabFeatures", + "enum_class": "TabFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(TabFeatures, TabFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "ToolBarFeatures", + "enum_class": "ToolBarFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(ToolBarFeatures, ToolBarFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "ViewItemFeatures", + "enum_class": "ViewItemFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(ViewItemFeatures, ViewItemFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "ToolButtonFeatures", + "enum_class": "ToolButtonFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\styles\\qstyleoption.h: Q_DECLARE_FLAGS(ToolButtonFeatures, ToolButtonFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "DockWidgetFeatures", + "enum_class": "DockWidgetFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qdockwidget.h: Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "FontFilters", + "enum_class": "FontFilter", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qfontcombobox.h: Q_DECLARE_FLAGS(FontFilters, FontFilter)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "AreaOptions", + "enum_class": "AreaOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qmdiarea.h: Q_DECLARE_FLAGS(AreaOptions, AreaOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "SubWindowOptions", + "enum_class": "SubWindowOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qmdisubwindow.h: Q_DECLARE_FLAGS(SubWindowOptions, SubWindowOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "DockOptions", + "enum_class": "DockOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qmainwindow.h: Q_DECLARE_FLAGS(DockOptions, DockOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "AutoFormatting", + "enum_class": "AutoFormattingFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\widgets\\widgets\\qtextedit.h: Q_DECLARE_FLAGS(AutoFormatting, AutoFormattingFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWidgets", + "module_path": "../../PyQt5-stubs/QtWidgets.pyi" + }, + { + "qflag_class": "ChangeFlags", + "enum_class": "ChangeFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\core\\changes\\qscenechange.h:Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DCore", + "module_path": "../../PyQt5-stubs/Qt3DCore.pyi" + }, + { + "qflag_class": "DeliveryFlags", + "enum_class": "DeliveryFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\core\\changes\\qscenechange.h: Q_DECLARE_FLAGS(DeliveryFlags, DeliveryFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DCore", + "module_path": "../../PyQt5-stubs/Qt3DCore.pyi" + }, + { + "qflag_class": "BufferTypeFlags", + "enum_class": "BufferType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\render\\framegraph\\qclearbuffers.h: Q_DECLARE_FLAGS(BufferTypeFlags, BufferType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DRender", + "module_path": "../../PyQt5-stubs/Qt3DRender.pyi" + }, + { + "qflag_class": "Operations", + "enum_class": "Operation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\render\\framegraph\\qmemorybarrier.h: Q_DECLARE_FLAGS(Operations, Operation)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "Qt3DRender", + "module_path": "../../PyQt5-stubs/Qt3DRender.pyi" + }, + { + "qflag_class": "AnimationOptions", + "enum_class": "AnimationOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\qchart.h: Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi" + }, + { + "qflag_class": "RubberBands", + "enum_class": "RubberBand", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\qchartview.h: Q_DECLARE_FLAGS(RubberBands, RubberBand)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi" + }, + { + "qflag_class": "AxisTypes", + "enum_class": "AxisType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\axis\\qabstractaxis.h: Q_DECLARE_FLAGS(AxisTypes, AxisType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi" + }, + { + "qflag_class": "PolarOrientations", + "enum_class": "PolarOrientation", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\charts\\qpolarchart.h: Q_DECLARE_FLAGS(PolarOrientations, PolarOrientation)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtChart", + "module_path": "../../PyQt5-stubs/QtChart.pyi" + }, + { + "qflag_class": "TargetAccessModes", + "enum_class": "TargetAccessMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\nfc\\qnearfieldmanager.h: Q_DECLARE_FLAGS(TargetAccessModes, TargetAccessMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNfc", + "module_path": "../../PyQt5-stubs/QtNfc.pyi" + }, + { + "qflag_class": "ShareModes", + "enum_class": "ShareMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\nfc\\qnearfieldsharemanager.h: Q_DECLARE_FLAGS(ShareModes, ShareMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNfc", + "module_path": "../../PyQt5-stubs/QtNfc.pyi" + }, + { + "qflag_class": "AccessMethods", + "enum_class": "AccessMethod", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\nfc\\qnearfieldtarget.h: Q_DECLARE_FLAGS(AccessMethods, AccessMethod)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtNfc", + "module_path": "../../PyQt5-stubs/QtNfc.pyi" + }, + { + "qflag_class": "SecurityFlags", + "enum_class": "Security", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetooth.h:Q_DECLARE_FLAGS(SecurityFlags, Security)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "AttAccessConstraints", + "enum_class": "AttAccessConstraint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetooth.h:Q_DECLARE_FLAGS(AttAccessConstraints, AttAccessConstraint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "DiscoveryMethods", + "enum_class": "DiscoveryMethod", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdevicediscoveryagent.h: Q_DECLARE_FLAGS(DiscoveryMethods, DiscoveryMethod)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "ServiceClasses", + "enum_class": "ServiceClass", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(ServiceClasses, ServiceClass)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "Fields", + "enum_class": "Field", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(Fields, Field)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "CoreConfigurations", + "enum_class": "CoreConfiguration", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qbluetoothdeviceinfo.h: Q_DECLARE_FLAGS(CoreConfigurations, CoreConfiguration)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "PropertyTypes", + "enum_class": "PropertyType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qlowenergycharacteristic.h: Q_DECLARE_FLAGS(PropertyTypes, PropertyType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "ServiceTypes", + "enum_class": "ServiceType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\bluetooth\\qlowenergyservice.h: Q_DECLARE_FLAGS(ServiceTypes, ServiceType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtBluetooth", + "module_path": "../../PyQt5-stubs/QtBluetooth.pyi" + }, + { + "qflag_class": "SelectionFlags", + "enum_class": "SelectionFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualizationqml2\\abstractdeclarative_p.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)", + "src\\datavisualization\\engine\\qabstract3dgraph.h: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDataVisualization", + "module_path": "../../PyQt5-stubs/QtDataVisualization.pyi" + }, + { + "qflag_class": "OptimizationHints", + "enum_class": "OptimizationHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualizationqml2\\abstractdeclarative_p.h: Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint)", + "src\\datavisualization\\engine\\qabstract3dgraph.h: Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDataVisualization", + "module_path": "../../PyQt5-stubs/QtDataVisualization.pyi" + }, + { + "qflag_class": "DrawFlags", + "enum_class": "DrawFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\datavisualization\\data\\qsurface3dseries.h: Q_DECLARE_FLAGS(DrawFlags, DrawFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDataVisualization", + "module_path": "../../PyQt5-stubs/QtDataVisualization.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 4, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 4, + "module_idx": 1, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 4, + "module_idx": 2, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 4, + "module_idx": 3, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quickshapes\\qquickshape_p_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlcustomparser_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\qml\\qml\\qqmlengine.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\qsgcontextplugin_p.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\items\\qquickitem.h: Q_DECLARE_FLAGS(Flags, Flag)", + "tests\\auto\\qml\\qmltyperegistrar\\tst_qmltyperegistrar.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterial.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(Flags, Flag)", + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQml", + "module_path": "../../PyQt5-stubs/QtQml.pyi" + }, + { + "qflag_class": "Extensions", + "enum_class": "Extension", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\qml\\jsapi\\qjsengine.h: Q_DECLARE_FLAGS(Extensions, Extension)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQml", + "module_path": "../../PyQt5-stubs/QtQml.pyi" + }, + { + "qflag_class": "PerformanceHints", + "enum_class": "PerformanceHint", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickpainteditem.h: Q_DECLARE_FLAGS(PerformanceHints, PerformanceHint)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "CreateTextureOptions", + "enum_class": "CreateTextureOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickwindow.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)", + "src\\quick\\scenegraph\\util\\qsgengine.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "CreateTextureOptions", + "enum_class": "CreateTextureOption", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\items\\qquickwindow.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)", + "src\\quick\\scenegraph\\util\\qsgengine.h: Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 1, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "ClearMode", + "enum_class": "ClearModeBit", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgabstractrenderer.h: Q_DECLARE_FLAGS(ClearMode, ClearModeBit)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "MatrixTransformFlags", + "enum_class": "MatrixTransformFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgabstractrenderer.h: Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "ColorMask", + "enum_class": "ColorMaskComponent", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgmaterialrhishader.h: Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "DirtyStates", + "enum_class": "DirtyState", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgmaterialshader.h: Q_DECLARE_FLAGS(DirtyStates, DirtyState)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "DirtyState", + "enum_class": "DirtyStateBit", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgnode.h: Q_DECLARE_FLAGS(DirtyState, DirtyStateBit)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "ShaderCompilationTypes", + "enum_class": "ShaderCompilationType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendererinterface.h: Q_DECLARE_FLAGS(ShaderCompilationTypes, ShaderCompilationType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "ShaderSourceTypes", + "enum_class": "ShaderSourceType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendererinterface.h: Q_DECLARE_FLAGS(ShaderSourceTypes, ShaderSourceType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "StateFlags", + "enum_class": "StateFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendernode.h: Q_DECLARE_FLAGS(StateFlags, StateFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "RenderingFlags", + "enum_class": "RenderingFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\coreapi\\qsgrendernode.h: Q_DECLARE_FLAGS(RenderingFlags, RenderingFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "TextureCoordinatesTransformMode", + "enum_class": "TextureCoordinatesTransformFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\util\\qsgimagenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)", + "src\\quick\\scenegraph\\util\\qsgsimpletexturenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 0, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "TextureCoordinatesTransformMode", + "enum_class": "TextureCoordinatesTransformFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\quick\\scenegraph\\util\\qsgimagenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)", + "src\\quick\\scenegraph\\util\\qsgsimpletexturenode.h: Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 2, + "module_idx": 1, + "module_name": "QtQuick", + "module_path": "../../PyQt5-stubs/QtQuick.pyi" + }, + { + "qflag_class": "VisibilityScope", + "enum_class": "Visibility", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\qlocation.h:Q_DECLARE_FLAGS(VisibilityScope, Visibility)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "PositioningMethods", + "enum_class": "PositioningMethod", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\positioningquick\\qdeclarativepositionsource_p.h: Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod)", + "src\\positioning\\qgeopositioninfosource.h: Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtPositioning", + "module_path": "../../PyQt5-stubs/QtPositioning.pyi" + }, + { + "qflag_class": "AreaMonitorFeatures", + "enum_class": "AreaMonitorFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\positioning\\qgeoareamonitorsource.h: Q_DECLARE_FLAGS(AreaMonitorFeatures, AreaMonitorFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtPositioning", + "module_path": "../../PyQt5-stubs/QtPositioning.pyi" + }, + { + "qflag_class": "TravelModes", + "enum_class": "TravelMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(TravelModes, TravelMode)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(TravelModes, TravelMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "FeatureTypes", + "enum_class": "FeatureType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(FeatureTypes, FeatureType)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(FeatureTypes, FeatureType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "FeatureWeights", + "enum_class": "FeatureWeight", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "RouteOptimizations", + "enum_class": "RouteOptimization", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "SegmentDetails", + "enum_class": "SegmentDetail", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(SegmentDetails, SegmentDetail)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(SegmentDetails, SegmentDetail)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "ManeuverDetails", + "enum_class": "ManeuverDetail", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoroutemodel_p.h: Q_DECLARE_FLAGS(ManeuverDetails, ManeuverDetail)", + "src\\location\\maps\\qgeorouterequest.h: Q_DECLARE_FLAGS(ManeuverDetails, ManeuverDetail)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "RoutingFeatures", + "enum_class": "RoutingFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "GeocodingFeatures", + "enum_class": "GeocodingFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "MappingFeatures", + "enum_class": "MappingFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(MappingFeatures, MappingFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(MappingFeatures, MappingFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "PlacesFeatures", + "enum_class": "PlacesFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "NavigationFeatures", + "enum_class": "NavigationFeature", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\location\\declarativemaps\\qdeclarativegeoserviceprovider_p.h: Q_DECLARE_FLAGS(NavigationFeatures, NavigationFeature)", + "src\\location\\maps\\qgeoserviceprovider.h: Q_DECLARE_FLAGS(NavigationFeatures, NavigationFeature)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtLocation", + "module_path": "../../PyQt5-stubs/QtLocation.pyi" + }, + { + "qflag_class": "CaptureModes", + "enum_class": "CaptureMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcamera.h: Q_DECLARE_FLAGS(CaptureModes, CaptureMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "LockTypes", + "enum_class": "LockType", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcamera.h: Q_DECLARE_FLAGS(LockTypes, LockType)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "FlashModes", + "enum_class": "FlashMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcameraexposure.h: Q_DECLARE_FLAGS(FlashModes, FlashMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "FocusModes", + "enum_class": "FocusMode", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcamerafocus.h: Q_DECLARE_FLAGS(FocusModes, FocusMode)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "CaptureDestinations", + "enum_class": "CaptureDestination", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\camera\\qcameraimagecapture.h: Q_DECLARE_FLAGS(CaptureDestinations, CaptureDestination)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\playback\\qmediaplayer.h: Q_DECLARE_FLAGS(Flags, Flag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "RunFlags", + "enum_class": "RunFlag", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\multimedia\\video\\qabstractvideofilter.h: Q_DECLARE_FLAGS(RunFlags, RunFlag)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtMultimedia", + "module_path": "../../PyQt5-stubs/QtMultimedia.pyi" + }, + { + "qflag_class": "Directions", + "enum_class": "Direction", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\serialport\\qserialport.h: Q_DECLARE_FLAGS(Directions, Direction)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtSerialPort", + "module_path": "../../PyQt5-stubs/QtSerialPort.pyi" + }, + { + "qflag_class": "PinoutSignals", + "enum_class": "PinoutSignal", + "human_hint_qflag_full_class_name": "", + "human_hint_enum_full_class_name": "", + "grep_line": [ + "src\\serialport\\qserialport.h: Q_DECLARE_FLAGS(PinoutSignals, PinoutSignal)" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtSerialPort", + "module_path": "../../PyQt5-stubs/QtSerialPort.pyi" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "human_hint_qflag_full_class_name": "QWebEngineUrlScheme.Flags", + "human_hint_enum_full_class_name": "QWebEngineUrlScheme.Flag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebEngineCore", + "module_path": "../../PyQt5-stubs/QtWebEngineCore.pyi" + }, + { + "qflag_class": "MediaFlags", + "enum_class": "MediaFlag", + "human_hint_qflag_full_class_name": "QWebEngineContextMenuData.MediaFlags", + "human_hint_enum_full_class_name": "QWebEngineContextMenuData.MediaFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebEngineWidgets", + "module_path": "../../PyQt5-stubs/QtWebEngineWidgets.pyi" + }, + { + "qflag_class": "EditFlags", + "enum_class": "EditFlag", + "human_hint_qflag_full_class_name": "QWebEngineContextMenuData.EditFlags", + "human_hint_enum_full_class_name": "QWebEngineContextMenuData.EditFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebEngineWidgets", + "module_path": "../../PyQt5-stubs/QtWebEngineWidgets.pyi" + }, + { + "qflag_class": "FindFlags", + "enum_class": "FindFlag", + "human_hint_qflag_full_class_name": "QWebEnginePage.FindFlags", + "human_hint_enum_full_class_name": "QWebEnginePage.FindFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebEngineWidgets", + "module_path": "../../PyQt5-stubs/QtWebEngineWidgets.pyi" + }, + { + "qflag_class": "RenderLayers", + "enum_class": "RenderLayer", + "human_hint_qflag_full_class_name": "QWebFrame.RenderLayers", + "human_hint_enum_full_class_name": "QWebFrame.RenderLayer", + "grep_line": [ + "" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebKitWiddgets", + "module_path": "../../PyQt5-stubs/QtWebKitWidgets.pyi" + }, + { + "qflag_class": "FindFlags", + "enum_class": "FindFlag", + "human_hint_qflag_full_class_name": "QWebPage.FindFlags", + "human_hint_enum_full_class_name": "QWebPage.FindFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtWebKitWiddgets", + "module_path": "../../PyQt5-stubs/QtWebKitWidgets.pyi" + }, + { + "qflag_class": "Feature", + "enum_class": "FeatureFlag", + "human_hint_qflag_full_class_name": "QDesignerFormWindowInterface.Feature", + "human_hint_enum_full_class_name": "QDesignerFormWindowInterface.FeatureFlag", + "grep_line": [ + "" + ], + "qflag_full_class_name": "", + "enum_full_class_name": "", + "enum_value1": "", + "enum_value2": "", + "module_count": 1, + "module_idx": 0, + "module_name": "QtDesigner", + "module_path": "../../PyQt5-stubs/QtDesigner.pyi" + } + ], + "qflags_to_skip": [ + { + "qflag_class": "Flags", + "enum_class": "Flag", + "skip_reason": "QFlag not found" + }, + { + "qflag_class": "BackendNodeDirtySet", + "enum_class": "BackendNodeDirtyFlag", + "skip_reason": "QFlag not found" + }, + { + "qflag_class": "DirtyFlags", + "enum_class": "DirtyFlag", + "skip_reason": "QFlag not found" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "skip_reason": "QFlag not found in module group qtchart" + }, + { + "qflag_class": "BackendNodeDirtySet", + "enum_class": "BackendNodeDirtyFlag", + "skip_reason": "QFlag not found in module group qtchart" + }, + { + "qflag_class": "DirtyFlags", + "enum_class": "DirtyFlag", + "skip_reason": "QFlag not found in module group qtchart" + }, + { + "qflag_class": "Flags", + "enum_class": "Flag", + "skip_reason": "QFlag not found in module group qtconnectivity" + }, + { + "qflag_class": "BackendNodeDirtySet", + "enum_class": "BackendNodeDirtyFlag", + "skip_reason": "QFlag not found in module group qtconnectivity" + }, + { + "qflag_class": "DirtyFlags", + "enum_class": "DirtyFlag", + "skip_reason": "QFlag not found in module group qtconnectivity" + }, + { + "qflag_class": "JobFlags", + "enum_class": "JobFlag", + "skip_reason": "QFlag not found in module group qtconnectivity" + }, + { + "qflag_class": "DataDimensions", + "enum_class": "DataDimension", + "skip_reason": "QFlag not found in module group qtdatavisualization" + }, + { + "qflag_class": "ReleaseFlags", + "enum_class": "ReleaseFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "ChangeTypes", + "enum_class": "ChangeType", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "PropertyFlags", + "enum_class": "PropertyFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "WriteFlags", + "enum_class": "WriteFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "BindingFlags", + "enum_class": "BindingFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "Anchors", + "enum_class": "Anchor", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "GrabPermissions", + "enum_class": "GrabPermission", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "States", + "enum_class": "State", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "DeviceTypes", + "enum_class": "DeviceType", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "PointerTypes", + "enum_class": "PointerType", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "Capabilities", + "enum_class": "CapabilityFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "BoundsBehavior", + "enum_class": "BoundsBehaviorFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "DirtyShaderFlags", + "enum_class": "DirtyShaderFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "LoadPixmapOptions", + "enum_class": "LoadPixmapOption", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "Options", + "enum_class": "Option", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "RebuildOptions", + "enum_class": "RebuildOption", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "Decorations", + "enum_class": "Decoration", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "FocusOptions", + "enum_class": "FocusOption", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "MyFlags", + "enum_class": "MyFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "ClearFlags", + "enum_class": "ClearFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "TextureCreateFlags", + "enum_class": "TextureCreateFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "TextureUploadFlags", + "enum_class": "TextureUploadFlag", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "UpdateResults", + "enum_class": "UpdateResult", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "ClipType", + "enum_class": "ClipTypeBit", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "Attachments", + "enum_class": "Attachment", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "DrawingHints", + "enum_class": "DrawingHint", + "skip_reason": "QFlag not found in module group qtquick" + }, + { + "qflag_class": "CacheAreas", + "enum_class": "CacheArea", + "skip_reason": "QFlag not found in module group qtlocation" + }, + { + "qflag_class": "ItemTypes", + "enum_class": "ItemType", + "skip_reason": "QFlag not found in module group qtlocation" + }, + { + "qflag_class": "Capabilities", + "enum_class": "Capability", + "skip_reason": "QFlag not found in module group qtlocation" + }, + { + "qflag_class": "Features", + "enum_class": "Feature", + "skip_reason": "QFlag not found in module group qtlocation" + }, + { + "qflag_class": "AcceptedGestures", + "enum_class": "GeoMapGesture", + "skip_reason": "QFlag not found in module group qtlocation" + }, + { + "qflag_class": "SyncStates", + "enum_class": "SyncState", + "skip_reason": "QFlag not found in module group qtlocation" + }, + { + "qflag_class": "ResourceFlags", + "enum_class": "ResourceFlag", + "skip_reason": "QFlag not found in module group qtlocation" + }, + { + "qflag_class": "PositionFields", + "enum_class": "PositionField", + "skip_reason": "QFlag not found in module group qtlocation" + }, + { + "qflag_class": "VelocityFields", + "enum_class": "VelocityField", + "skip_reason": "QFlag not found in module group qtlocation" + }, + { + "qflag_class": "ShaderTypes", + "enum_class": "ShaderType", + "skip_reason": "QFlag not found in module group qtmultimedia" + }, + { + "qflag_class": "FrameFlags", + "enum_class": "FrameFlag", + "skip_reason": "QFlag not found in module group qtmultimedia" + }, + { + "qflag_class": "EmptyStreamOptions", + "enum_class": "EmptyStreamOption", + "skip_reason": "QFlag not found in module group qtmultimedia" + } + ] +} \ No newline at end of file diff --git a/tests/qflags/test_Qt3DCore_ChangeFlags_ChangeFlag.py b/tests/qflags/test_Qt3DCore_ChangeFlags_ChangeFlag.py new file mode 100644 index 00000000..abba7e99 --- /dev/null +++ b/tests/qflags/test_Qt3DCore_ChangeFlags_ChangeFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "ChangeFlags" and flag class "ChangeFlag" +from PyQt5 import Qt3DCore + +OneFlagClass = Qt3DCore.ChangeFlag +MultiFlagClass = Qt3DCore.ChangeFlags + +oneFlagRefValue1 = Qt3DCore.ChangeFlag.NodeCreated +oneFlagRefValue2 = Qt3DCore.ChangeFlag.NodeDeleted + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_Qt3DCore_DeliveryFlags_DeliveryFlag.py b/tests/qflags/test_Qt3DCore_DeliveryFlags_DeliveryFlag.py new file mode 100644 index 00000000..b1107b68 --- /dev/null +++ b/tests/qflags/test_Qt3DCore_DeliveryFlags_DeliveryFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSceneChange.DeliveryFlags" and flag class "QSceneChange.DeliveryFlag" +from PyQt5 import Qt3DCore + +OneFlagClass = Qt3DCore.QSceneChange.DeliveryFlag +MultiFlagClass = Qt3DCore.QSceneChange.DeliveryFlags + +oneFlagRefValue1 = Qt3DCore.QSceneChange.DeliveryFlag.BackendNodes +oneFlagRefValue2 = Qt3DCore.QSceneChange.DeliveryFlag.Nodes + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_Qt3DRender_BufferTypeFlags_BufferType.py b/tests/qflags/test_Qt3DRender_BufferTypeFlags_BufferType.py new file mode 100644 index 00000000..267b5f8c --- /dev/null +++ b/tests/qflags/test_Qt3DRender_BufferTypeFlags_BufferType.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QClearBuffers.BufferTypeFlags" and flag class "QBuffer.BufferType" +from PyQt5 import Qt3DRender + +OneFlagClass = Qt3DRender.QBuffer.BufferType +MultiFlagClass = Qt3DRender.QClearBuffers.BufferTypeFlags + +oneFlagRefValue1 = Qt3DRender.QBuffer.BufferType.VertexBuffer +oneFlagRefValue2 = Qt3DRender.QBuffer.BufferType.IndexBuffer + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) # type: ignore[operator] + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_Qt3DRender_Operations_Operation.py b/tests/qflags/test_Qt3DRender_Operations_Operation.py new file mode 100644 index 00000000..c9c70a12 --- /dev/null +++ b/tests/qflags/test_Qt3DRender_Operations_Operation.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QMemoryBarrier.Operations" and flag class "QMemoryBarrier.Operation" +from PyQt5 import Qt3DRender + +OneFlagClass = Qt3DRender.QMemoryBarrier.Operation +MultiFlagClass = Qt3DRender.QMemoryBarrier.Operations + +oneFlagRefValue1 = Qt3DRender.QMemoryBarrier.Operation.None_ +oneFlagRefValue2 = Qt3DRender.QMemoryBarrier.Operation.VertexAttributeArray + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtBluetooth_AttAccessConstraints_AttAccessConstraint.py b/tests/qflags/test_QtBluetooth_AttAccessConstraints_AttAccessConstraint.py new file mode 100644 index 00000000..69239abc --- /dev/null +++ b/tests/qflags/test_QtBluetooth_AttAccessConstraints_AttAccessConstraint.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QBluetooth.AttAccessConstraints" and flag class "QBluetooth.AttAccessConstraint" +from PyQt5 import QtBluetooth + +OneFlagClass = QtBluetooth.QBluetooth.AttAccessConstraint +MultiFlagClass = QtBluetooth.QBluetooth.AttAccessConstraints + +oneFlagRefValue1 = QtBluetooth.QBluetooth.AttAccessConstraint.AttAuthorizationRequired +oneFlagRefValue2 = QtBluetooth.QBluetooth.AttAccessConstraint.AttAuthenticationRequired + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtBluetooth_CoreConfigurations_CoreConfiguration.py b/tests/qflags/test_QtBluetooth_CoreConfigurations_CoreConfiguration.py new file mode 100644 index 00000000..f73e2689 --- /dev/null +++ b/tests/qflags/test_QtBluetooth_CoreConfigurations_CoreConfiguration.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QBluetoothDeviceInfo.CoreConfigurations" and flag class "QBluetoothDeviceInfo.CoreConfiguration" +from PyQt5 import QtBluetooth + +OneFlagClass = QtBluetooth.QBluetoothDeviceInfo.CoreConfiguration +MultiFlagClass = QtBluetooth.QBluetoothDeviceInfo.CoreConfigurations + +oneFlagRefValue1 = QtBluetooth.QBluetoothDeviceInfo.CoreConfiguration.UnknownCoreConfiguration +oneFlagRefValue2 = QtBluetooth.QBluetoothDeviceInfo.CoreConfiguration.LowEnergyCoreConfiguration + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtBluetooth_Fields_Field.py b/tests/qflags/test_QtBluetooth_Fields_Field.py new file mode 100644 index 00000000..604ae64e --- /dev/null +++ b/tests/qflags/test_QtBluetooth_Fields_Field.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QBluetoothDeviceInfo.Fields" and flag class "QBluetoothDeviceInfo.Field" +from PyQt5 import QtBluetooth + +OneFlagClass = QtBluetooth.QBluetoothDeviceInfo.Field +MultiFlagClass = QtBluetooth.QBluetoothDeviceInfo.Fields + +oneFlagRefValue1 = QtBluetooth.QBluetoothDeviceInfo.Field.None_ +oneFlagRefValue2 = QtBluetooth.QBluetoothDeviceInfo.Field.RSSI + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtBluetooth_PropertyTypes_PropertyType.py b/tests/qflags/test_QtBluetooth_PropertyTypes_PropertyType.py new file mode 100644 index 00000000..74f32536 --- /dev/null +++ b/tests/qflags/test_QtBluetooth_PropertyTypes_PropertyType.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QLowEnergyCharacteristic.PropertyTypes" and flag class "QLowEnergyCharacteristic.PropertyType" +from PyQt5 import QtBluetooth + +OneFlagClass = QtBluetooth.QLowEnergyCharacteristic.PropertyType +MultiFlagClass = QtBluetooth.QLowEnergyCharacteristic.PropertyTypes + +oneFlagRefValue1 = QtBluetooth.QLowEnergyCharacteristic.PropertyType.Unknown +oneFlagRefValue2 = QtBluetooth.QLowEnergyCharacteristic.PropertyType.Broadcasting + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtBluetooth_SecurityFlags_Security.py b/tests/qflags/test_QtBluetooth_SecurityFlags_Security.py new file mode 100644 index 00000000..94eb00f0 --- /dev/null +++ b/tests/qflags/test_QtBluetooth_SecurityFlags_Security.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QBluetooth.SecurityFlags" and flag class "QBluetooth.Security" +from PyQt5 import QtBluetooth + +OneFlagClass = QtBluetooth.QBluetooth.Security +MultiFlagClass = QtBluetooth.QBluetooth.SecurityFlags + +oneFlagRefValue1 = QtBluetooth.QBluetooth.Security.NoSecurity +oneFlagRefValue2 = QtBluetooth.QBluetooth.Security.Authorization + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtBluetooth_ServiceClasses_ServiceClass.py b/tests/qflags/test_QtBluetooth_ServiceClasses_ServiceClass.py new file mode 100644 index 00000000..bc42e486 --- /dev/null +++ b/tests/qflags/test_QtBluetooth_ServiceClasses_ServiceClass.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QBluetoothDeviceInfo.ServiceClasses" and flag class "QBluetoothDeviceInfo.ServiceClass" +from PyQt5 import QtBluetooth + +OneFlagClass = QtBluetooth.QBluetoothDeviceInfo.ServiceClass +MultiFlagClass = QtBluetooth.QBluetoothDeviceInfo.ServiceClasses + +oneFlagRefValue1 = QtBluetooth.QBluetoothDeviceInfo.ServiceClass.NoService +oneFlagRefValue2 = QtBluetooth.QBluetoothDeviceInfo.ServiceClass.PositioningService + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtBluetooth_ServiceTypes_ServiceType.py b/tests/qflags/test_QtBluetooth_ServiceTypes_ServiceType.py new file mode 100644 index 00000000..951fd10f --- /dev/null +++ b/tests/qflags/test_QtBluetooth_ServiceTypes_ServiceType.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QLowEnergyService.ServiceTypes" and flag class "QLowEnergyService.ServiceType" +from PyQt5 import QtBluetooth + +OneFlagClass = QtBluetooth.QLowEnergyService.ServiceType +MultiFlagClass = QtBluetooth.QLowEnergyService.ServiceTypes + +oneFlagRefValue1 = QtBluetooth.QLowEnergyService.ServiceType.PrimaryService +oneFlagRefValue2 = QtBluetooth.QLowEnergyService.ServiceType.IncludedService + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtChart_AnimationOptions_AnimationOption.py b/tests/qflags/test_QtChart_AnimationOptions_AnimationOption.py new file mode 100644 index 00000000..c6186825 --- /dev/null +++ b/tests/qflags/test_QtChart_AnimationOptions_AnimationOption.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QChart.AnimationOptions" and flag class "QChart.AnimationOption" +from PyQt5 import QtChart + +OneFlagClass = QtChart.QChart.AnimationOption +MultiFlagClass = QtChart.QChart.AnimationOptions + +oneFlagRefValue1 = QtChart.QChart.AnimationOption.NoAnimation +oneFlagRefValue2 = QtChart.QChart.AnimationOption.GridAxisAnimations + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[True] = True +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtChart_AxisTypes_AxisType.py b/tests/qflags/test_QtChart_AxisTypes_AxisType.py new file mode 100644 index 00000000..ff38ca2a --- /dev/null +++ b/tests/qflags/test_QtChart_AxisTypes_AxisType.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QAbstractAxis.AxisTypes" and flag class "QAbstractAxis.AxisType" +from PyQt5 import QtChart + +OneFlagClass = QtChart.QAbstractAxis.AxisType +MultiFlagClass = QtChart.QAbstractAxis.AxisTypes + +oneFlagRefValue1 = QtChart.QAbstractAxis.AxisType.AxisTypeNoAxis +oneFlagRefValue2 = QtChart.QAbstractAxis.AxisType.AxisTypeValue + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtChart_PolarOrientations_PolarOrientation.py b/tests/qflags/test_QtChart_PolarOrientations_PolarOrientation.py new file mode 100644 index 00000000..0f667166 --- /dev/null +++ b/tests/qflags/test_QtChart_PolarOrientations_PolarOrientation.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QPolarChart.PolarOrientations" and flag class "QPolarChart.PolarOrientation" +from PyQt5 import QtChart + +OneFlagClass = QtChart.QPolarChart.PolarOrientation +MultiFlagClass = QtChart.QPolarChart.PolarOrientations + +oneFlagRefValue1 = QtChart.QPolarChart.PolarOrientation.PolarOrientationRadial +oneFlagRefValue2 = QtChart.QPolarChart.PolarOrientation.PolarOrientationAngular + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtChart_RubberBands_RubberBand.py b/tests/qflags/test_QtChart_RubberBands_RubberBand.py new file mode 100644 index 00000000..06dc4d63 --- /dev/null +++ b/tests/qflags/test_QtChart_RubberBands_RubberBand.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QChartView.RubberBands" and flag class "QChartView.RubberBand" +from PyQt5 import QtChart + +OneFlagClass = QtChart.QChartView.RubberBand +MultiFlagClass = QtChart.QChartView.RubberBands + +oneFlagRefValue1 = QtChart.QChartView.RubberBand.NoRubberBand +oneFlagRefValue2 = QtChart.QChartView.RubberBand.VerticalRubberBand + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_Alignment_AlignmentFlag.py b/tests/qflags/test_QtCore_Alignment_AlignmentFlag.py new file mode 100644 index 00000000..e1045204 --- /dev/null +++ b/tests/qflags/test_QtCore_Alignment_AlignmentFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.Alignment" and flag class "Qt.AlignmentFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.AlignmentFlag +MultiFlagClass = QtCore.Qt.Alignment + +oneFlagRefValue1 = QtCore.Qt.AlignmentFlag.AlignLeft +oneFlagRefValue2 = QtCore.Qt.AlignmentFlag.AlignLeading + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_ApplicationStates_ApplicationState.py b/tests/qflags/test_QtCore_ApplicationStates_ApplicationState.py new file mode 100644 index 00000000..fb8e27df --- /dev/null +++ b/tests/qflags/test_QtCore_ApplicationStates_ApplicationState.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.ApplicationStates" and flag class "Qt.ApplicationState" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.ApplicationState +MultiFlagClass = QtCore.Qt.ApplicationStates + +oneFlagRefValue1 = QtCore.Qt.ApplicationState.ApplicationSuspended +oneFlagRefValue2 = QtCore.Qt.ApplicationState.ApplicationHidden + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_Base64Options_Base64Option.py b/tests/qflags/test_QtCore_Base64Options_Base64Option.py new file mode 100644 index 00000000..60534242 --- /dev/null +++ b/tests/qflags/test_QtCore_Base64Options_Base64Option.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QByteArray.Base64Options" and flag class "QByteArray.Base64Option" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QByteArray.Base64Option +MultiFlagClass = QtCore.QByteArray.Base64Options + +oneFlagRefValue1 = QtCore.QByteArray.Base64Option.Base64Encoding +oneFlagRefValue2 = QtCore.QByteArray.Base64Option.Base64UrlEncoding + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_BoundaryReasons_BoundaryReason.py b/tests/qflags/test_QtCore_BoundaryReasons_BoundaryReason.py new file mode 100644 index 00000000..90eb8dbd --- /dev/null +++ b/tests/qflags/test_QtCore_BoundaryReasons_BoundaryReason.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTextBoundaryFinder.BoundaryReasons" and flag class "QTextBoundaryFinder.BoundaryReason" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QTextBoundaryFinder.BoundaryReason +MultiFlagClass = QtCore.QTextBoundaryFinder.BoundaryReasons + +oneFlagRefValue1 = QtCore.QTextBoundaryFinder.BoundaryReason.NotAtBoundary +oneFlagRefValue2 = QtCore.QTextBoundaryFinder.BoundaryReason.SoftHyphen + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_CheckIndexOptions_CheckIndexOption.py b/tests/qflags/test_QtCore_CheckIndexOptions_CheckIndexOption.py new file mode 100644 index 00000000..e6282bdf --- /dev/null +++ b/tests/qflags/test_QtCore_CheckIndexOptions_CheckIndexOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QAbstractItemModel.CheckIndexOptions" and flag class "QAbstractItemModel.CheckIndexOption" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QAbstractItemModel.CheckIndexOption +MultiFlagClass = QtCore.QAbstractItemModel.CheckIndexOptions + +oneFlagRefValue1 = QtCore.QAbstractItemModel.CheckIndexOption.NoOption +oneFlagRefValue2 = QtCore.QAbstractItemModel.CheckIndexOption.IndexIsValid + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_ComponentFormattingOptions_ComponentFormattingOption.py b/tests/qflags/test_QtCore_ComponentFormattingOptions_ComponentFormattingOption.py new file mode 100644 index 00000000..a461db58 --- /dev/null +++ b/tests/qflags/test_QtCore_ComponentFormattingOptions_ComponentFormattingOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QUrl.ComponentFormattingOptions" and flag class "QUrl.ComponentFormattingOption" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QUrl.ComponentFormattingOption +MultiFlagClass = QtCore.QUrl.ComponentFormattingOptions + +oneFlagRefValue1 = QtCore.QUrl.ComponentFormattingOption.PrettyDecoded +oneFlagRefValue2 = QtCore.QUrl.ComponentFormattingOption.EncodeSpaces + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_ConversionFlags_ConversionFlag.py b/tests/qflags/test_QtCore_ConversionFlags_ConversionFlag.py new file mode 100644 index 00000000..94f556df --- /dev/null +++ b/tests/qflags/test_QtCore_ConversionFlags_ConversionFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTextCodec.ConversionFlags" and flag class "QTextCodec.ConversionFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QTextCodec.ConversionFlag +MultiFlagClass = QtCore.QTextCodec.ConversionFlags + +oneFlagRefValue1 = QtCore.QTextCodec.ConversionFlag.DefaultConversion +oneFlagRefValue2 = QtCore.QTextCodec.ConversionFlag.ConvertInvalidToNull + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_DataSizeFormats_DataSizeFormat.py b/tests/qflags/test_QtCore_DataSizeFormats_DataSizeFormat.py new file mode 100644 index 00000000..0bcf8d1f --- /dev/null +++ b/tests/qflags/test_QtCore_DataSizeFormats_DataSizeFormat.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QLocale.DataSizeFormats" and flag class "QLocale.DataSizeFormat" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QLocale.DataSizeFormat +MultiFlagClass = QtCore.QLocale.DataSizeFormats + +oneFlagRefValue1 = QtCore.QLocale.DataSizeFormat.DataSizeIecFormat +oneFlagRefValue2 = QtCore.QLocale.DataSizeFormat.DataSizeTraditionalFormat + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_DockWidgetAreas_DockWidgetArea.py b/tests/qflags/test_QtCore_DockWidgetAreas_DockWidgetArea.py new file mode 100644 index 00000000..6cce4761 --- /dev/null +++ b/tests/qflags/test_QtCore_DockWidgetAreas_DockWidgetArea.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.DockWidgetAreas" and flag class "Qt.DockWidgetArea" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.DockWidgetArea +MultiFlagClass = QtCore.Qt.DockWidgetAreas + +oneFlagRefValue1 = QtCore.Qt.DockWidgetArea.LeftDockWidgetArea +oneFlagRefValue2 = QtCore.Qt.DockWidgetArea.RightDockWidgetArea + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_DropActions_DropAction.py b/tests/qflags/test_QtCore_DropActions_DropAction.py new file mode 100644 index 00000000..6c5a8ceb --- /dev/null +++ b/tests/qflags/test_QtCore_DropActions_DropAction.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.DropActions" and flag class "Qt.DropAction" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.DropAction +MultiFlagClass = QtCore.Qt.DropActions + +oneFlagRefValue1 = QtCore.Qt.DropAction.CopyAction +oneFlagRefValue2 = QtCore.Qt.DropAction.MoveAction + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_Edges_Edge.py b/tests/qflags/test_QtCore_Edges_Edge.py new file mode 100644 index 00000000..05048e21 --- /dev/null +++ b/tests/qflags/test_QtCore_Edges_Edge.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.Edges" and flag class "Qt.Edge" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.Edge +MultiFlagClass = QtCore.Qt.Edges + +oneFlagRefValue1 = QtCore.Qt.Edge.TopEdge +oneFlagRefValue2 = QtCore.Qt.Edge.LeftEdge + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_FileHandleFlags_FileHandleFlag.py b/tests/qflags/test_QtCore_FileHandleFlags_FileHandleFlag.py new file mode 100644 index 00000000..8339fa5d --- /dev/null +++ b/tests/qflags/test_QtCore_FileHandleFlags_FileHandleFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QFileDevice.FileHandleFlags" and flag class "QFileDevice.FileHandleFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QFileDevice.FileHandleFlag +MultiFlagClass = QtCore.QFileDevice.FileHandleFlags + +oneFlagRefValue1 = QtCore.QFileDevice.FileHandleFlag.AutoCloseHandle +oneFlagRefValue2 = QtCore.QFileDevice.FileHandleFlag.DontCloseHandle + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_Filters_Filter.py b/tests/qflags/test_QtCore_Filters_Filter.py new file mode 100644 index 00000000..f3a9e61f --- /dev/null +++ b/tests/qflags/test_QtCore_Filters_Filter.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QDir.Filters" and flag class "QDir.Filter" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QDir.Filter +MultiFlagClass = QtCore.QDir.Filters + +oneFlagRefValue1 = QtCore.QDir.Filter.Dirs +oneFlagRefValue2 = QtCore.QDir.Filter.Files + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_FindChildOptions_FindChildOption.py b/tests/qflags/test_QtCore_FindChildOptions_FindChildOption.py new file mode 100644 index 00000000..32efffe3 --- /dev/null +++ b/tests/qflags/test_QtCore_FindChildOptions_FindChildOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.FindChildOptions" and flag class "Qt.FindChildOption" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.FindChildOption +MultiFlagClass = QtCore.Qt.FindChildOptions + +oneFlagRefValue1 = QtCore.Qt.FindChildOption.FindDirectChildrenOnly +oneFlagRefValue2 = QtCore.Qt.FindChildOption.FindChildrenRecursively + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_Flags_Flag.py b/tests/qflags/test_QtCore_Flags_Flag.py new file mode 100644 index 00000000..389b580f --- /dev/null +++ b/tests/qflags/test_QtCore_Flags_Flag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QCommandLineOption.Flags" and flag class "QCommandLineOption.Flag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QCommandLineOption.Flag +MultiFlagClass = QtCore.QCommandLineOption.Flags + +oneFlagRefValue1 = QtCore.QCommandLineOption.Flag.HiddenFromHelp +oneFlagRefValue2 = QtCore.QCommandLineOption.Flag.ShortOptionStyle + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_FormattingOptions_UrlFormattingOption.py b/tests/qflags/test_QtCore_FormattingOptions_UrlFormattingOption.py new file mode 100644 index 00000000..6a4cd2dd --- /dev/null +++ b/tests/qflags/test_QtCore_FormattingOptions_UrlFormattingOption.py @@ -0,0 +1,269 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# This file is used as a source to generate all qflags related tests. The specific part +# changes for each test but the rest of the file is totally identical +from PyQt5 import QtCore + +OneFlagClass = QtCore.QUrl.UrlFormattingOption +MultiFlagClass = QtCore.QUrl.FormattingOptions + +oneFlagRefValue1 = QtCore.QUrl.None_ +oneFlagRefValue2 = QtCore.QUrl.RemoveScheme + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 1. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + +### Disable the tests on multiflag for QUrl.FormattingOptions because the implementation does not support anything. +''' +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass(oneFlagValue1 | oneFlagValue1) + multiFlagValue2 = MultiFlagClass(oneFlagValue1 | oneFlagValue1) + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f4) +''' + diff --git a/tests/qflags/test_QtCore_GestureFlags_GestureFlag.py b/tests/qflags/test_QtCore_GestureFlags_GestureFlag.py new file mode 100644 index 00000000..0410daae --- /dev/null +++ b/tests/qflags/test_QtCore_GestureFlags_GestureFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.GestureFlags" and flag class "Qt.GestureFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.GestureFlag +MultiFlagClass = QtCore.Qt.GestureFlags + +oneFlagRefValue1 = QtCore.Qt.GestureFlag.DontStartGestureOnChildren +oneFlagRefValue2 = QtCore.Qt.GestureFlag.ReceivePartialGestures + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_ImageConversionFlags_ImageConversionFlag.py b/tests/qflags/test_QtCore_ImageConversionFlags_ImageConversionFlag.py new file mode 100644 index 00000000..c790de7c --- /dev/null +++ b/tests/qflags/test_QtCore_ImageConversionFlags_ImageConversionFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.ImageConversionFlags" and flag class "Qt.ImageConversionFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.ImageConversionFlag +MultiFlagClass = QtCore.Qt.ImageConversionFlags + +oneFlagRefValue1 = QtCore.Qt.ImageConversionFlag.AutoColor +oneFlagRefValue2 = QtCore.Qt.ImageConversionFlag.ColorOnly + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_InputMethodHints_InputMethodHint.py b/tests/qflags/test_QtCore_InputMethodHints_InputMethodHint.py new file mode 100644 index 00000000..556c7018 --- /dev/null +++ b/tests/qflags/test_QtCore_InputMethodHints_InputMethodHint.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.InputMethodHints" and flag class "Qt.InputMethodHint" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.InputMethodHint +MultiFlagClass = QtCore.Qt.InputMethodHints + +oneFlagRefValue1 = QtCore.Qt.InputMethodHint.ImhNone +oneFlagRefValue2 = QtCore.Qt.InputMethodHint.ImhHiddenText + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_InputMethodQueries_InputMethodQuery.py b/tests/qflags/test_QtCore_InputMethodQueries_InputMethodQuery.py new file mode 100644 index 00000000..e3db721e --- /dev/null +++ b/tests/qflags/test_QtCore_InputMethodQueries_InputMethodQuery.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.InputMethodQueries" and flag class "Qt.InputMethodQuery" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.InputMethodQuery +MultiFlagClass = QtCore.Qt.InputMethodQueries + +oneFlagRefValue1 = QtCore.Qt.InputMethodQuery.ImMicroFocus +oneFlagRefValue2 = QtCore.Qt.InputMethodQuery.ImFont + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_ItemFlags_ItemFlag.py b/tests/qflags/test_QtCore_ItemFlags_ItemFlag.py new file mode 100644 index 00000000..dc5b0b7b --- /dev/null +++ b/tests/qflags/test_QtCore_ItemFlags_ItemFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.ItemFlags" and flag class "Qt.ItemFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.ItemFlag +MultiFlagClass = QtCore.Qt.ItemFlags + +oneFlagRefValue1 = QtCore.Qt.ItemFlag.NoItemFlags +oneFlagRefValue2 = QtCore.Qt.ItemFlag.ItemIsSelectable + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_IteratorFlags_IteratorFlag.py b/tests/qflags/test_QtCore_IteratorFlags_IteratorFlag.py new file mode 100644 index 00000000..3c23bef5 --- /dev/null +++ b/tests/qflags/test_QtCore_IteratorFlags_IteratorFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QDirIterator.IteratorFlags" and flag class "QDirIterator.IteratorFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QDirIterator.IteratorFlag +MultiFlagClass = QtCore.QDirIterator.IteratorFlags + +oneFlagRefValue1 = QtCore.QDirIterator.IteratorFlag.NoIteratorFlags +oneFlagRefValue2 = QtCore.QDirIterator.IteratorFlag.FollowSymlinks + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_KeyboardModifiers_KeyboardModifier.py b/tests/qflags/test_QtCore_KeyboardModifiers_KeyboardModifier.py new file mode 100644 index 00000000..857e2d46 --- /dev/null +++ b/tests/qflags/test_QtCore_KeyboardModifiers_KeyboardModifier.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.KeyboardModifiers" and flag class "Qt.KeyboardModifier" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.KeyboardModifier +MultiFlagClass = QtCore.Qt.KeyboardModifiers + +oneFlagRefValue1 = QtCore.Qt.KeyboardModifier.NoModifier +oneFlagRefValue2 = QtCore.Qt.KeyboardModifier.ShiftModifier + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_LoadHints_LoadHint.py b/tests/qflags/test_QtCore_LoadHints_LoadHint.py new file mode 100644 index 00000000..ec0b54dc --- /dev/null +++ b/tests/qflags/test_QtCore_LoadHints_LoadHint.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QLibrary.LoadHints" and flag class "QLibrary.LoadHint" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QLibrary.LoadHint +MultiFlagClass = QtCore.QLibrary.LoadHints + +oneFlagRefValue1 = QtCore.QLibrary.LoadHint.ResolveAllSymbolsHint +oneFlagRefValue2 = QtCore.QLibrary.LoadHint.ExportExternalSymbolsHint + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_LocateOptions_LocateOption.py b/tests/qflags/test_QtCore_LocateOptions_LocateOption.py new file mode 100644 index 00000000..9beb26d1 --- /dev/null +++ b/tests/qflags/test_QtCore_LocateOptions_LocateOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStandardPaths.LocateOptions" and flag class "QStandardPaths.LocateOption" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QStandardPaths.LocateOption +MultiFlagClass = QtCore.QStandardPaths.LocateOptions + +oneFlagRefValue1 = QtCore.QStandardPaths.LocateOption.LocateFile +oneFlagRefValue2 = QtCore.QStandardPaths.LocateOption.LocateDirectory + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_MatchFlags_MatchFlag.py b/tests/qflags/test_QtCore_MatchFlags_MatchFlag.py new file mode 100644 index 00000000..649447fb --- /dev/null +++ b/tests/qflags/test_QtCore_MatchFlags_MatchFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.MatchFlags" and flag class "Qt.MatchFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.MatchFlag +MultiFlagClass = QtCore.Qt.MatchFlags + +oneFlagRefValue1 = QtCore.Qt.MatchFlag.MatchExactly +oneFlagRefValue2 = QtCore.Qt.MatchFlag.MatchFixedString + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_MatchOptions_MatchOption.py b/tests/qflags/test_QtCore_MatchOptions_MatchOption.py new file mode 100644 index 00000000..ffadbf1a --- /dev/null +++ b/tests/qflags/test_QtCore_MatchOptions_MatchOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QRegularExpression.MatchOptions" and flag class "QRegularExpression.MatchOption" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QRegularExpression.MatchOption +MultiFlagClass = QtCore.QRegularExpression.MatchOptions + +oneFlagRefValue1 = QtCore.QRegularExpression.MatchOption.NoMatchOption +oneFlagRefValue2 = QtCore.QRegularExpression.MatchOption.AnchoredMatchOption + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_MouseButtons_MouseButton.py b/tests/qflags/test_QtCore_MouseButtons_MouseButton.py new file mode 100644 index 00000000..420131c2 --- /dev/null +++ b/tests/qflags/test_QtCore_MouseButtons_MouseButton.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.MouseButtons" and flag class "Qt.MouseButton" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.MouseButton +MultiFlagClass = QtCore.Qt.MouseButtons + +oneFlagRefValue1 = QtCore.Qt.MouseButton.NoButton +oneFlagRefValue2 = QtCore.Qt.MouseButton.AllButtons + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_MouseEventFlags_MouseEventFlag.py b/tests/qflags/test_QtCore_MouseEventFlags_MouseEventFlag.py new file mode 100644 index 00000000..3a6485f9 --- /dev/null +++ b/tests/qflags/test_QtCore_MouseEventFlags_MouseEventFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.MouseEventFlags" and flag class "Qt.MouseEventFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.MouseEventFlag +MultiFlagClass = QtCore.Qt.MouseEventFlags + +oneFlagRefValue1 = QtCore.Qt.MouseEventFlag.MouseEventCreatedDoubleClick +oneFlagRefValue2 = QtCore.Qt.MouseEventFlag.MouseEventCreatedDoubleClick + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_NumberFlags_NumberFlag.py b/tests/qflags/test_QtCore_NumberFlags_NumberFlag.py new file mode 100644 index 00000000..9dca3d75 --- /dev/null +++ b/tests/qflags/test_QtCore_NumberFlags_NumberFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTextStream.NumberFlags" and flag class "QTextStream.NumberFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QTextStream.NumberFlag +MultiFlagClass = QtCore.QTextStream.NumberFlags + +oneFlagRefValue1 = QtCore.QTextStream.NumberFlag.ShowBase +oneFlagRefValue2 = QtCore.QTextStream.NumberFlag.ForcePoint + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_NumberOptions_NumberOption.py b/tests/qflags/test_QtCore_NumberOptions_NumberOption.py new file mode 100644 index 00000000..f40e09bc --- /dev/null +++ b/tests/qflags/test_QtCore_NumberOptions_NumberOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QLocale.NumberOptions" and flag class "QLocale.NumberOption" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QLocale.NumberOption +MultiFlagClass = QtCore.QLocale.NumberOptions + +oneFlagRefValue1 = QtCore.QLocale.NumberOption.OmitGroupSeparator +oneFlagRefValue2 = QtCore.QLocale.NumberOption.RejectGroupSeparator + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_OpenMode_OpenModeFlag.py b/tests/qflags/test_QtCore_OpenMode_OpenModeFlag.py new file mode 100644 index 00000000..175d2504 --- /dev/null +++ b/tests/qflags/test_QtCore_OpenMode_OpenModeFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QIODevice.OpenMode" and flag class "QIODevice.OpenModeFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QIODevice.OpenModeFlag +MultiFlagClass = QtCore.QIODevice.OpenMode + +oneFlagRefValue1 = QtCore.QIODevice.OpenModeFlag.NotOpen +oneFlagRefValue2 = QtCore.QIODevice.OpenModeFlag.ReadOnly + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_Orientations_Orientation.py b/tests/qflags/test_QtCore_Orientations_Orientation.py new file mode 100644 index 00000000..0b74b4c0 --- /dev/null +++ b/tests/qflags/test_QtCore_Orientations_Orientation.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.Orientations" and flag class "Qt.Orientation" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.Orientation +MultiFlagClass = QtCore.Qt.Orientations + +oneFlagRefValue1 = QtCore.Qt.Orientation.Horizontal +oneFlagRefValue2 = QtCore.Qt.Orientation.Vertical + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_PatternOptions_PatternOption.py b/tests/qflags/test_QtCore_PatternOptions_PatternOption.py new file mode 100644 index 00000000..dba0a118 --- /dev/null +++ b/tests/qflags/test_QtCore_PatternOptions_PatternOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QRegularExpression.PatternOptions" and flag class "QRegularExpression.PatternOption" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QRegularExpression.PatternOption +MultiFlagClass = QtCore.QRegularExpression.PatternOptions + +oneFlagRefValue1 = QtCore.QRegularExpression.PatternOption.NoPatternOption +oneFlagRefValue2 = QtCore.QRegularExpression.PatternOption.CaseInsensitiveOption + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_Permissions_Permission.py b/tests/qflags/test_QtCore_Permissions_Permission.py new file mode 100644 index 00000000..97575313 --- /dev/null +++ b/tests/qflags/test_QtCore_Permissions_Permission.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QFileDevice.Permissions" and flag class "QFileDevice.Permission" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QFileDevice.Permission +MultiFlagClass = QtCore.QFileDevice.Permissions + +oneFlagRefValue1 = QtCore.QFileDevice.Permission.ReadOwner +oneFlagRefValue2 = QtCore.QFileDevice.Permission.WriteOwner + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_ProcessEventsFlags_ProcessEventsFlag.py b/tests/qflags/test_QtCore_ProcessEventsFlags_ProcessEventsFlag.py new file mode 100644 index 00000000..5426fb3a --- /dev/null +++ b/tests/qflags/test_QtCore_ProcessEventsFlags_ProcessEventsFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QEventLoop.ProcessEventsFlags" and flag class "QEventLoop.ProcessEventsFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QEventLoop.ProcessEventsFlag +MultiFlagClass = QtCore.QEventLoop.ProcessEventsFlags + +oneFlagRefValue1 = QtCore.QEventLoop.ProcessEventsFlag.AllEvents +oneFlagRefValue2 = QtCore.QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_ScreenOrientations_ScreenOrientation.py b/tests/qflags/test_QtCore_ScreenOrientations_ScreenOrientation.py new file mode 100644 index 00000000..c3bfd0e0 --- /dev/null +++ b/tests/qflags/test_QtCore_ScreenOrientations_ScreenOrientation.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.ScreenOrientations" and flag class "Qt.ScreenOrientation" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.ScreenOrientation +MultiFlagClass = QtCore.Qt.ScreenOrientations + +oneFlagRefValue1 = QtCore.Qt.ScreenOrientation.PrimaryOrientation +oneFlagRefValue2 = QtCore.Qt.ScreenOrientation.PortraitOrientation + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_SelectionFlags_SelectionFlag.py b/tests/qflags/test_QtCore_SelectionFlags_SelectionFlag.py new file mode 100644 index 00000000..7139ee33 --- /dev/null +++ b/tests/qflags/test_QtCore_SelectionFlags_SelectionFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QItemSelectionModel.SelectionFlags" and flag class "QItemSelectionModel.SelectionFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QItemSelectionModel.SelectionFlag +MultiFlagClass = QtCore.QItemSelectionModel.SelectionFlags + +oneFlagRefValue1 = QtCore.QItemSelectionModel.SelectionFlag.NoUpdate +oneFlagRefValue2 = QtCore.QItemSelectionModel.SelectionFlag.Clear + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_SortFlags_SortFlag.py b/tests/qflags/test_QtCore_SortFlags_SortFlag.py new file mode 100644 index 00000000..1a340949 --- /dev/null +++ b/tests/qflags/test_QtCore_SortFlags_SortFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QDir.SortFlags" and flag class "QDir.SortFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QDir.SortFlag +MultiFlagClass = QtCore.QDir.SortFlags + +oneFlagRefValue1 = QtCore.QDir.SortFlag.Name +oneFlagRefValue2 = QtCore.QDir.SortFlag.Time + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_TextInteractionFlags_TextInteractionFlag.py b/tests/qflags/test_QtCore_TextInteractionFlags_TextInteractionFlag.py new file mode 100644 index 00000000..3108ae97 --- /dev/null +++ b/tests/qflags/test_QtCore_TextInteractionFlags_TextInteractionFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.TextInteractionFlags" and flag class "Qt.TextInteractionFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.TextInteractionFlag +MultiFlagClass = QtCore.Qt.TextInteractionFlags + +oneFlagRefValue1 = QtCore.Qt.TextInteractionFlag.NoTextInteraction +oneFlagRefValue2 = QtCore.Qt.TextInteractionFlag.TextSelectableByMouse + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_ToolBarAreas_ToolBarArea.py b/tests/qflags/test_QtCore_ToolBarAreas_ToolBarArea.py new file mode 100644 index 00000000..3eff8d7b --- /dev/null +++ b/tests/qflags/test_QtCore_ToolBarAreas_ToolBarArea.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.ToolBarAreas" and flag class "Qt.ToolBarArea" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.ToolBarArea +MultiFlagClass = QtCore.Qt.ToolBarAreas + +oneFlagRefValue1 = QtCore.Qt.ToolBarArea.LeftToolBarArea +oneFlagRefValue2 = QtCore.Qt.ToolBarArea.RightToolBarArea + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_TouchPointStates_TouchPointState.py b/tests/qflags/test_QtCore_TouchPointStates_TouchPointState.py new file mode 100644 index 00000000..60e48426 --- /dev/null +++ b/tests/qflags/test_QtCore_TouchPointStates_TouchPointState.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.TouchPointStates" and flag class "Qt.TouchPointState" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.TouchPointState +MultiFlagClass = QtCore.Qt.TouchPointStates + +oneFlagRefValue1 = QtCore.Qt.TouchPointState.TouchPointPressed +oneFlagRefValue2 = QtCore.Qt.TouchPointState.TouchPointMoved + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_TypeFlags_TypeFlag.py b/tests/qflags/test_QtCore_TypeFlags_TypeFlag.py new file mode 100644 index 00000000..a9516077 --- /dev/null +++ b/tests/qflags/test_QtCore_TypeFlags_TypeFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QMetaType.TypeFlags" and flag class "QMetaType.TypeFlag" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QMetaType.TypeFlag +MultiFlagClass = QtCore.QMetaType.TypeFlags + +oneFlagRefValue1 = QtCore.QMetaType.TypeFlag.NeedsConstruction +oneFlagRefValue2 = QtCore.QMetaType.TypeFlag.NeedsDestruction + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_UserInputResolutionOptions_UserInputResolutionOption.py b/tests/qflags/test_QtCore_UserInputResolutionOptions_UserInputResolutionOption.py new file mode 100644 index 00000000..41d9a397 --- /dev/null +++ b/tests/qflags/test_QtCore_UserInputResolutionOptions_UserInputResolutionOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QUrl.UserInputResolutionOptions" and flag class "QUrl.UserInputResolutionOption" +from PyQt5 import QtCore + +OneFlagClass = QtCore.QUrl.UserInputResolutionOption +MultiFlagClass = QtCore.QUrl.UserInputResolutionOptions + +oneFlagRefValue1 = QtCore.QUrl.UserInputResolutionOption.DefaultResolution +oneFlagRefValue2 = QtCore.QUrl.UserInputResolutionOption.AssumeLocalFile + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_WindowFlags_WindowType.py b/tests/qflags/test_QtCore_WindowFlags_WindowType.py new file mode 100644 index 00000000..7d861d22 --- /dev/null +++ b/tests/qflags/test_QtCore_WindowFlags_WindowType.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.WindowFlags" and flag class "Qt.WindowType" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.WindowType +MultiFlagClass = QtCore.Qt.WindowFlags + +oneFlagRefValue1 = QtCore.Qt.WindowType.Widget +oneFlagRefValue2 = QtCore.Qt.WindowType.Window + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtCore_WindowStates_WindowState.py b/tests/qflags/test_QtCore_WindowStates_WindowState.py new file mode 100644 index 00000000..e8d4b5f4 --- /dev/null +++ b/tests/qflags/test_QtCore_WindowStates_WindowState.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "Qt.WindowStates" and flag class "Qt.WindowState" +from PyQt5 import QtCore + +OneFlagClass = QtCore.Qt.WindowState +MultiFlagClass = QtCore.Qt.WindowStates + +oneFlagRefValue1 = QtCore.Qt.WindowState.WindowNoState +oneFlagRefValue2 = QtCore.Qt.WindowState.WindowMinimized + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtDBus_ConnectionCapabilities_ConnectionCapability.py b/tests/qflags/test_QtDBus_ConnectionCapabilities_ConnectionCapability.py new file mode 100644 index 00000000..56a682fe --- /dev/null +++ b/tests/qflags/test_QtDBus_ConnectionCapabilities_ConnectionCapability.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QDBusConnection.ConnectionCapabilities" and flag class "QDBusConnection.ConnectionCapability" +from PyQt5 import QtDBus + +OneFlagClass = QtDBus.QDBusConnection.ConnectionCapability +MultiFlagClass = QtDBus.QDBusConnection.ConnectionCapabilities + +oneFlagRefValue1 = QtDBus.QDBusConnection.ConnectionCapability.UnixFileDescriptorPassing +oneFlagRefValue2 = QtDBus.QDBusConnection.ConnectionCapability.UnixFileDescriptorPassing + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtDBus_RegisterOptions_RegisterOption.py b/tests/qflags/test_QtDBus_RegisterOptions_RegisterOption.py new file mode 100644 index 00000000..fd360243 --- /dev/null +++ b/tests/qflags/test_QtDBus_RegisterOptions_RegisterOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QDBusConnection.RegisterOptions" and flag class "QDBusConnection.RegisterOption" +from PyQt5 import QtDBus + +OneFlagClass = QtDBus.QDBusConnection.RegisterOption +MultiFlagClass = QtDBus.QDBusConnection.RegisterOptions + +oneFlagRefValue1 = QtDBus.QDBusConnection.RegisterOption.ExportAdaptors +oneFlagRefValue2 = QtDBus.QDBusConnection.RegisterOption.ExportScriptableSlots + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[True] = True +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtDBus_WatchMode_WatchModeFlag.py b/tests/qflags/test_QtDBus_WatchMode_WatchModeFlag.py new file mode 100644 index 00000000..035a52b3 --- /dev/null +++ b/tests/qflags/test_QtDBus_WatchMode_WatchModeFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QDBusServiceWatcher.WatchMode" and flag class "QDBusServiceWatcher.WatchModeFlag" +from PyQt5 import QtDBus + +OneFlagClass = QtDBus.QDBusServiceWatcher.WatchModeFlag +MultiFlagClass = QtDBus.QDBusServiceWatcher.WatchMode + +oneFlagRefValue1 = QtDBus.QDBusServiceWatcher.WatchModeFlag.WatchForRegistration +oneFlagRefValue2 = QtDBus.QDBusServiceWatcher.WatchModeFlag.WatchForUnregistration + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[True] = True +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtDataVisualization_DrawFlags_DrawFlag.py b/tests/qflags/test_QtDataVisualization_DrawFlags_DrawFlag.py new file mode 100644 index 00000000..025881e2 --- /dev/null +++ b/tests/qflags/test_QtDataVisualization_DrawFlags_DrawFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSurface3DSeries.DrawFlags" and flag class "QSurface3DSeries.DrawFlag" +from PyQt5 import QtDataVisualization + +OneFlagClass = QtDataVisualization.QSurface3DSeries.DrawFlag +MultiFlagClass = QtDataVisualization.QSurface3DSeries.DrawFlags + +oneFlagRefValue1 = QtDataVisualization.QSurface3DSeries.DrawFlag.DrawWireframe +oneFlagRefValue2 = QtDataVisualization.QSurface3DSeries.DrawFlag.DrawSurface + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtDataVisualization_OptimizationHints_OptimizationHint.py b/tests/qflags/test_QtDataVisualization_OptimizationHints_OptimizationHint.py new file mode 100644 index 00000000..0b8319f1 --- /dev/null +++ b/tests/qflags/test_QtDataVisualization_OptimizationHints_OptimizationHint.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QAbstract3DGraph.OptimizationHints" and flag class "QAbstract3DGraph.OptimizationHint" +from PyQt5 import QtDataVisualization + +OneFlagClass = QtDataVisualization.QAbstract3DGraph.OptimizationHint +MultiFlagClass = QtDataVisualization.QAbstract3DGraph.OptimizationHints + +oneFlagRefValue1 = QtDataVisualization.QAbstract3DGraph.OptimizationHint.OptimizationDefault +oneFlagRefValue2 = QtDataVisualization.QAbstract3DGraph.OptimizationHint.OptimizationStatic + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtDataVisualization_SelectionFlags_SelectionFlag.py b/tests/qflags/test_QtDataVisualization_SelectionFlags_SelectionFlag.py new file mode 100644 index 00000000..bfa70436 --- /dev/null +++ b/tests/qflags/test_QtDataVisualization_SelectionFlags_SelectionFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QAbstract3DGraph.SelectionFlags" and flag class "QAbstract3DGraph.SelectionFlag" +from PyQt5 import QtDataVisualization + +OneFlagClass = QtDataVisualization.QAbstract3DGraph.SelectionFlag +MultiFlagClass = QtDataVisualization.QAbstract3DGraph.SelectionFlags + +oneFlagRefValue1 = QtDataVisualization.QAbstract3DGraph.SelectionFlag.SelectionNone +oneFlagRefValue2 = QtDataVisualization.QAbstract3DGraph.SelectionFlag.SelectionItem + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtDesigner_Feature_FeatureFlag.py b/tests/qflags/test_QtDesigner_Feature_FeatureFlag.py new file mode 100644 index 00000000..8ae431f3 --- /dev/null +++ b/tests/qflags/test_QtDesigner_Feature_FeatureFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QDesignerFormWindowInterface.Feature" and flag class "QDesignerFormWindowInterface.FeatureFlag" +from PyQt5 import QtDesigner + +OneFlagClass = QtDesigner.QDesignerFormWindowInterface.FeatureFlag +MultiFlagClass = QtDesigner.QDesignerFormWindowInterface.Feature + +oneFlagRefValue1 = QtDesigner.QDesignerFormWindowInterface.FeatureFlag.EditFeature +oneFlagRefValue2 = QtDesigner.QDesignerFormWindowInterface.FeatureFlag.GridFeature + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_Capabilities_CapabilityFlag.py b/tests/qflags/test_QtGui_Capabilities_CapabilityFlag.py new file mode 100644 index 00000000..9c4555e8 --- /dev/null +++ b/tests/qflags/test_QtGui_Capabilities_CapabilityFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTouchDevice.Capabilities" and flag class "QTouchDevice.CapabilityFlag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QTouchDevice.CapabilityFlag +MultiFlagClass = QtGui.QTouchDevice.Capabilities + +oneFlagRefValue1 = QtGui.QTouchDevice.CapabilityFlag.Position +oneFlagRefValue2 = QtGui.QTouchDevice.CapabilityFlag.Area + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_DirtyFlags_DirtyFlag.py b/tests/qflags/test_QtGui_DirtyFlags_DirtyFlag.py new file mode 100644 index 00000000..60ac001f --- /dev/null +++ b/tests/qflags/test_QtGui_DirtyFlags_DirtyFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QPaintEngine.DirtyFlags" and flag class "QPaintEngine.DirtyFlag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QPaintEngine.DirtyFlag +MultiFlagClass = QtGui.QPaintEngine.DirtyFlags + +oneFlagRefValue1 = QtGui.QPaintEngine.DirtyFlag.DirtyPen +oneFlagRefValue2 = QtGui.QPaintEngine.DirtyFlag.DirtyBrush + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_Features_Feature.py b/tests/qflags/test_QtGui_Features_Feature.py new file mode 100644 index 00000000..c92b96cd --- /dev/null +++ b/tests/qflags/test_QtGui_Features_Feature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QOpenGLTexture.Features" and flag class "QOpenGLTexture.Feature" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QOpenGLTexture.Feature +MultiFlagClass = QtGui.QOpenGLTexture.Features + +oneFlagRefValue1 = QtGui.QOpenGLTexture.Feature.ImmutableStorage +oneFlagRefValue2 = QtGui.QOpenGLTexture.Feature.ImmutableMultisampleStorage + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_FindFlags_FindFlag.py b/tests/qflags/test_QtGui_FindFlags_FindFlag.py new file mode 100644 index 00000000..1b66051a --- /dev/null +++ b/tests/qflags/test_QtGui_FindFlags_FindFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTextDocument.FindFlags" and flag class "QTextDocument.FindFlag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QTextDocument.FindFlag +MultiFlagClass = QtGui.QTextDocument.FindFlags + +oneFlagRefValue1 = QtGui.QTextDocument.FindFlag.FindBackward +oneFlagRefValue2 = QtGui.QTextDocument.FindFlag.FindCaseSensitively + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_Flags_Flag.py b/tests/qflags/test_QtGui_Flags_Flag.py new file mode 100644 index 00000000..418999dd --- /dev/null +++ b/tests/qflags/test_QtGui_Flags_Flag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTextOption.Flags" and flag class "QTextOption.Flag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QTextOption.Flag +MultiFlagClass = QtGui.QTextOption.Flags + +oneFlagRefValue1 = QtGui.QTextOption.Flag.IncludeTrailingSpaces +oneFlagRefValue2 = QtGui.QTextOption.Flag.ShowTabsAndSpaces + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_FormatOptions_FormatOption.py b/tests/qflags/test_QtGui_FormatOptions_FormatOption.py new file mode 100644 index 00000000..20624463 --- /dev/null +++ b/tests/qflags/test_QtGui_FormatOptions_FormatOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSurfaceFormat.FormatOptions" and flag class "QSurfaceFormat.FormatOption" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QSurfaceFormat.FormatOption +MultiFlagClass = QtGui.QSurfaceFormat.FormatOptions + +oneFlagRefValue1 = QtGui.QSurfaceFormat.FormatOption.StereoBuffers +oneFlagRefValue2 = QtGui.QSurfaceFormat.FormatOption.DebugContext + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_GlyphRunFlags_GlyphRunFlag.py b/tests/qflags/test_QtGui_GlyphRunFlags_GlyphRunFlag.py new file mode 100644 index 00000000..bfa93edd --- /dev/null +++ b/tests/qflags/test_QtGui_GlyphRunFlags_GlyphRunFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGlyphRun.GlyphRunFlags" and flag class "QGlyphRun.GlyphRunFlag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QGlyphRun.GlyphRunFlag +MultiFlagClass = QtGui.QGlyphRun.GlyphRunFlags + +oneFlagRefValue1 = QtGui.QGlyphRun.GlyphRunFlag.Overline +oneFlagRefValue2 = QtGui.QGlyphRun.GlyphRunFlag.Underline + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_InfoFlags_InfoFlag.py b/tests/qflags/test_QtGui_InfoFlags_InfoFlag.py new file mode 100644 index 00000000..7c47abbc --- /dev/null +++ b/tests/qflags/test_QtGui_InfoFlags_InfoFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTouchEvent.TouchPoint.InfoFlags" and flag class "QTouchEvent.TouchPoint.InfoFlag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QTouchEvent.TouchPoint.InfoFlag +MultiFlagClass = QtGui.QTouchEvent.TouchPoint.InfoFlags + +oneFlagRefValue1 = QtGui.QTouchEvent.TouchPoint.InfoFlag.Pen +oneFlagRefValue2 = QtGui.QTouchEvent.TouchPoint.InfoFlag.Token + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[True] = True +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_LayoutFlags_LayoutFlag.py b/tests/qflags/test_QtGui_LayoutFlags_LayoutFlag.py new file mode 100644 index 00000000..042f9f26 --- /dev/null +++ b/tests/qflags/test_QtGui_LayoutFlags_LayoutFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QRawFont.LayoutFlags" and flag class "QRawFont.LayoutFlag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QRawFont.LayoutFlag +MultiFlagClass = QtGui.QRawFont.LayoutFlags + +oneFlagRefValue1 = QtGui.QRawFont.LayoutFlag.SeparateAdvances +oneFlagRefValue2 = QtGui.QRawFont.LayoutFlag.KernedAdvances + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_MarkdownFeatures_MarkdownFeature.py b/tests/qflags/test_QtGui_MarkdownFeatures_MarkdownFeature.py new file mode 100644 index 00000000..0610c8f9 --- /dev/null +++ b/tests/qflags/test_QtGui_MarkdownFeatures_MarkdownFeature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTextDocument.MarkdownFeatures" and flag class "QTextDocument.MarkdownFeature" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QTextDocument.MarkdownFeature +MultiFlagClass = QtGui.QTextDocument.MarkdownFeatures + +oneFlagRefValue1 = QtGui.QTextDocument.MarkdownFeature.MarkdownNoHTML +oneFlagRefValue2 = QtGui.QTextDocument.MarkdownFeature.MarkdownDialectCommonMark + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_PageBreakFlags_PageBreakFlag.py b/tests/qflags/test_QtGui_PageBreakFlags_PageBreakFlag.py new file mode 100644 index 00000000..25284e63 --- /dev/null +++ b/tests/qflags/test_QtGui_PageBreakFlags_PageBreakFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTextFormat.PageBreakFlags" and flag class "QTextFormat.PageBreakFlag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QTextFormat.PageBreakFlag +MultiFlagClass = QtGui.QTextFormat.PageBreakFlags + +oneFlagRefValue1 = QtGui.QTextFormat.PageBreakFlag.PageBreak_Auto +oneFlagRefValue2 = QtGui.QTextFormat.PageBreakFlag.PageBreak_AlwaysBefore + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_PaintEngineFeatures_PaintEngineFeature.py b/tests/qflags/test_QtGui_PaintEngineFeatures_PaintEngineFeature.py new file mode 100644 index 00000000..f0a6010c --- /dev/null +++ b/tests/qflags/test_QtGui_PaintEngineFeatures_PaintEngineFeature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QPaintEngine.PaintEngineFeatures" and flag class "QPaintEngine.PaintEngineFeature" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QPaintEngine.PaintEngineFeature +MultiFlagClass = QtGui.QPaintEngine.PaintEngineFeatures + +oneFlagRefValue1 = QtGui.QPaintEngine.PaintEngineFeature.PrimitiveTransform +oneFlagRefValue2 = QtGui.QPaintEngine.PaintEngineFeature.PatternTransform + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_PixmapFragmentHints_PixmapFragmentHint.py b/tests/qflags/test_QtGui_PixmapFragmentHints_PixmapFragmentHint.py new file mode 100644 index 00000000..61513f18 --- /dev/null +++ b/tests/qflags/test_QtGui_PixmapFragmentHints_PixmapFragmentHint.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QPainter.PixmapFragmentHints" and flag class "QPainter.PixmapFragmentHint" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QPainter.PixmapFragmentHint +MultiFlagClass = QtGui.QPainter.PixmapFragmentHints + +oneFlagRefValue1 = QtGui.QPainter.PixmapFragmentHint.OpaqueHint +oneFlagRefValue2 = QtGui.QPainter.PixmapFragmentHint.OpaqueHint + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_RangeAccessFlags_RangeAccessFlag.py b/tests/qflags/test_QtGui_RangeAccessFlags_RangeAccessFlag.py new file mode 100644 index 00000000..43a3f008 --- /dev/null +++ b/tests/qflags/test_QtGui_RangeAccessFlags_RangeAccessFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QOpenGLBuffer.RangeAccessFlags" and flag class "QOpenGLBuffer.RangeAccessFlag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QOpenGLBuffer.RangeAccessFlag +MultiFlagClass = QtGui.QOpenGLBuffer.RangeAccessFlags + +oneFlagRefValue1 = QtGui.QOpenGLBuffer.RangeAccessFlag.RangeRead +oneFlagRefValue2 = QtGui.QOpenGLBuffer.RangeAccessFlag.RangeWrite + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_RenderFlags_RenderFlag.py b/tests/qflags/test_QtGui_RenderFlags_RenderFlag.py new file mode 100644 index 00000000..c6df42be --- /dev/null +++ b/tests/qflags/test_QtGui_RenderFlags_RenderFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTextItem.RenderFlags" and flag class "QTextItem.RenderFlag" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QTextItem.RenderFlag +MultiFlagClass = QtGui.QTextItem.RenderFlags + +oneFlagRefValue1 = QtGui.QTextItem.RenderFlag.RightToLeft +oneFlagRefValue2 = QtGui.QTextItem.RenderFlag.Overline + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_RenderHints_RenderHint.py b/tests/qflags/test_QtGui_RenderHints_RenderHint.py new file mode 100644 index 00000000..1c058bc7 --- /dev/null +++ b/tests/qflags/test_QtGui_RenderHints_RenderHint.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QPainter.RenderHints" and flag class "QPainter.RenderHint" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QPainter.RenderHint +MultiFlagClass = QtGui.QPainter.RenderHints + +oneFlagRefValue1 = QtGui.QPainter.RenderHint.Antialiasing +oneFlagRefValue2 = QtGui.QPainter.RenderHint.TextAntialiasing + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_Severities_Severity.py b/tests/qflags/test_QtGui_Severities_Severity.py new file mode 100644 index 00000000..f0d57d58 --- /dev/null +++ b/tests/qflags/test_QtGui_Severities_Severity.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QOpenGLDebugMessage.Severities" and flag class "QOpenGLDebugMessage.Severity" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QOpenGLDebugMessage.Severity +MultiFlagClass = QtGui.QOpenGLDebugMessage.Severities + +oneFlagRefValue1 = QtGui.QOpenGLDebugMessage.Severity.InvalidSeverity +oneFlagRefValue2 = QtGui.QOpenGLDebugMessage.Severity.HighSeverity + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_ShaderType_ShaderTypeBit.py b/tests/qflags/test_QtGui_ShaderType_ShaderTypeBit.py new file mode 100644 index 00000000..0b884ce1 --- /dev/null +++ b/tests/qflags/test_QtGui_ShaderType_ShaderTypeBit.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QOpenGLShader.ShaderType" and flag class "QOpenGLShader.ShaderTypeBit" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QOpenGLShader.ShaderTypeBit +MultiFlagClass = QtGui.QOpenGLShader.ShaderType + +oneFlagRefValue1 = QtGui.QOpenGLShader.ShaderTypeBit.Vertex +oneFlagRefValue2 = QtGui.QOpenGLShader.ShaderTypeBit.Fragment + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_Sources_Source.py b/tests/qflags/test_QtGui_Sources_Source.py new file mode 100644 index 00000000..9e324026 --- /dev/null +++ b/tests/qflags/test_QtGui_Sources_Source.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QOpenGLDebugMessage.Sources" and flag class "QOpenGLDebugMessage.Source" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QOpenGLDebugMessage.Source +MultiFlagClass = QtGui.QOpenGLDebugMessage.Sources + +oneFlagRefValue1 = QtGui.QOpenGLDebugMessage.Source.InvalidSource +oneFlagRefValue2 = QtGui.QOpenGLDebugMessage.Source.APISource + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_Transformations_Transformation.py b/tests/qflags/test_QtGui_Transformations_Transformation.py new file mode 100644 index 00000000..68b403a1 --- /dev/null +++ b/tests/qflags/test_QtGui_Transformations_Transformation.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QImageIOHandler.Transformations" and flag class "QImageIOHandler.Transformation" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QImageIOHandler.Transformation +MultiFlagClass = QtGui.QImageIOHandler.Transformations + +oneFlagRefValue1 = QtGui.QImageIOHandler.Transformation.TransformationNone +oneFlagRefValue2 = QtGui.QImageIOHandler.Transformation.TransformationMirror + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtGui_Types_Type.py b/tests/qflags/test_QtGui_Types_Type.py new file mode 100644 index 00000000..0e7a3b19 --- /dev/null +++ b/tests/qflags/test_QtGui_Types_Type.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QOpenGLDebugMessage.Types" and flag class "QOpenGLDebugMessage.Type" +from PyQt5 import QtGui + +OneFlagClass = QtGui.QOpenGLDebugMessage.Type +MultiFlagClass = QtGui.QOpenGLDebugMessage.Types + +oneFlagRefValue1 = QtGui.QOpenGLDebugMessage.Type.InvalidType +oneFlagRefValue2 = QtGui.QOpenGLDebugMessage.Type.ErrorType + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_FeatureTypes_FeatureType.py b/tests/qflags/test_QtLocation_FeatureTypes_FeatureType.py new file mode 100644 index 00000000..cae1fd69 --- /dev/null +++ b/tests/qflags/test_QtLocation_FeatureTypes_FeatureType.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoRouteRequest.FeatureTypes" and flag class "QGeoRouteRequest.FeatureType" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoRouteRequest.FeatureType +MultiFlagClass = QtLocation.QGeoRouteRequest.FeatureTypes + +oneFlagRefValue1 = QtLocation.QGeoRouteRequest.FeatureType.NoFeature +oneFlagRefValue2 = QtLocation.QGeoRouteRequest.FeatureType.TollFeature + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_FeatureWeights_FeatureWeight.py b/tests/qflags/test_QtLocation_FeatureWeights_FeatureWeight.py new file mode 100644 index 00000000..2e810ff4 --- /dev/null +++ b/tests/qflags/test_QtLocation_FeatureWeights_FeatureWeight.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoRouteRequest.FeatureWeights" and flag class "QGeoRouteRequest.FeatureWeight" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoRouteRequest.FeatureWeight +MultiFlagClass = QtLocation.QGeoRouteRequest.FeatureWeights + +oneFlagRefValue1 = QtLocation.QGeoRouteRequest.FeatureWeight.NeutralFeatureWeight +oneFlagRefValue2 = QtLocation.QGeoRouteRequest.FeatureWeight.PreferFeatureWeight + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_GeocodingFeatures_GeocodingFeature.py b/tests/qflags/test_QtLocation_GeocodingFeatures_GeocodingFeature.py new file mode 100644 index 00000000..e261ef5e --- /dev/null +++ b/tests/qflags/test_QtLocation_GeocodingFeatures_GeocodingFeature.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoServiceProvider.GeocodingFeatures" and flag class "QGeoServiceProvider.GeocodingFeature" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoServiceProvider.GeocodingFeature +MultiFlagClass = QtLocation.QGeoServiceProvider.GeocodingFeatures + +oneFlagRefValue1 = QtLocation.QGeoServiceProvider.GeocodingFeature.NoGeocodingFeatures +oneFlagRefValue2 = QtLocation.QGeoServiceProvider.GeocodingFeature.OnlineGeocodingFeature + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_ManeuverDetails_ManeuverDetail.py b/tests/qflags/test_QtLocation_ManeuverDetails_ManeuverDetail.py new file mode 100644 index 00000000..ff2be1b6 --- /dev/null +++ b/tests/qflags/test_QtLocation_ManeuverDetails_ManeuverDetail.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoRouteRequest.ManeuverDetails" and flag class "QGeoRouteRequest.ManeuverDetail" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoRouteRequest.ManeuverDetail +MultiFlagClass = QtLocation.QGeoRouteRequest.ManeuverDetails + +oneFlagRefValue1 = QtLocation.QGeoRouteRequest.ManeuverDetail.NoManeuvers +oneFlagRefValue2 = QtLocation.QGeoRouteRequest.ManeuverDetail.BasicManeuvers + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_MappingFeatures_MappingFeature.py b/tests/qflags/test_QtLocation_MappingFeatures_MappingFeature.py new file mode 100644 index 00000000..4d911ffe --- /dev/null +++ b/tests/qflags/test_QtLocation_MappingFeatures_MappingFeature.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoServiceProvider.MappingFeatures" and flag class "QGeoServiceProvider.MappingFeature" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoServiceProvider.MappingFeature +MultiFlagClass = QtLocation.QGeoServiceProvider.MappingFeatures + +oneFlagRefValue1 = QtLocation.QGeoServiceProvider.MappingFeature.NoMappingFeatures +oneFlagRefValue2 = QtLocation.QGeoServiceProvider.MappingFeature.OnlineMappingFeature + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_NavigationFeatures_NavigationFeature.py b/tests/qflags/test_QtLocation_NavigationFeatures_NavigationFeature.py new file mode 100644 index 00000000..a46ec582 --- /dev/null +++ b/tests/qflags/test_QtLocation_NavigationFeatures_NavigationFeature.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoServiceProvider.NavigationFeatures" and flag class "QGeoServiceProvider.NavigationFeature" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoServiceProvider.NavigationFeature +MultiFlagClass = QtLocation.QGeoServiceProvider.NavigationFeatures + +oneFlagRefValue1 = QtLocation.QGeoServiceProvider.NavigationFeature.NoNavigationFeatures +oneFlagRefValue2 = QtLocation.QGeoServiceProvider.NavigationFeature.OnlineNavigationFeature + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_PlacesFeatures_PlacesFeature.py b/tests/qflags/test_QtLocation_PlacesFeatures_PlacesFeature.py new file mode 100644 index 00000000..663daacf --- /dev/null +++ b/tests/qflags/test_QtLocation_PlacesFeatures_PlacesFeature.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoServiceProvider.PlacesFeatures" and flag class "QGeoServiceProvider.PlacesFeature" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoServiceProvider.PlacesFeature +MultiFlagClass = QtLocation.QGeoServiceProvider.PlacesFeatures + +oneFlagRefValue1 = QtLocation.QGeoServiceProvider.PlacesFeature.NoPlacesFeatures +oneFlagRefValue2 = QtLocation.QGeoServiceProvider.PlacesFeature.OnlinePlacesFeature + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_RouteOptimizations_RouteOptimization.py b/tests/qflags/test_QtLocation_RouteOptimizations_RouteOptimization.py new file mode 100644 index 00000000..547ebd37 --- /dev/null +++ b/tests/qflags/test_QtLocation_RouteOptimizations_RouteOptimization.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoRouteRequest.RouteOptimizations" and flag class "QGeoRouteRequest.RouteOptimization" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoRouteRequest.RouteOptimization +MultiFlagClass = QtLocation.QGeoRouteRequest.RouteOptimizations + +oneFlagRefValue1 = QtLocation.QGeoRouteRequest.RouteOptimization.ShortestRoute +oneFlagRefValue2 = QtLocation.QGeoRouteRequest.RouteOptimization.FastestRoute + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_RoutingFeatures_RoutingFeature.py b/tests/qflags/test_QtLocation_RoutingFeatures_RoutingFeature.py new file mode 100644 index 00000000..1d95b466 --- /dev/null +++ b/tests/qflags/test_QtLocation_RoutingFeatures_RoutingFeature.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoServiceProvider.RoutingFeatures" and flag class "QGeoServiceProvider.RoutingFeature" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoServiceProvider.RoutingFeature +MultiFlagClass = QtLocation.QGeoServiceProvider.RoutingFeatures + +oneFlagRefValue1 = QtLocation.QGeoServiceProvider.RoutingFeature.NoRoutingFeatures +oneFlagRefValue2 = QtLocation.QGeoServiceProvider.RoutingFeature.OnlineRoutingFeature + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_SegmentDetails_SegmentDetail.py b/tests/qflags/test_QtLocation_SegmentDetails_SegmentDetail.py new file mode 100644 index 00000000..05046780 --- /dev/null +++ b/tests/qflags/test_QtLocation_SegmentDetails_SegmentDetail.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoRouteRequest.SegmentDetails" and flag class "QGeoRouteRequest.SegmentDetail" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoRouteRequest.SegmentDetail +MultiFlagClass = QtLocation.QGeoRouteRequest.SegmentDetails + +oneFlagRefValue1 = QtLocation.QGeoRouteRequest.SegmentDetail.NoSegmentData +oneFlagRefValue2 = QtLocation.QGeoRouteRequest.SegmentDetail.BasicSegmentData + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_TravelModes_TravelMode.py b/tests/qflags/test_QtLocation_TravelModes_TravelMode.py new file mode 100644 index 00000000..cf59ca96 --- /dev/null +++ b/tests/qflags/test_QtLocation_TravelModes_TravelMode.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoRouteRequest.TravelModes" and flag class "QGeoRouteRequest.TravelMode" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QGeoRouteRequest.TravelMode +MultiFlagClass = QtLocation.QGeoRouteRequest.TravelModes + +oneFlagRefValue1 = QtLocation.QGeoRouteRequest.TravelMode.CarTravel +oneFlagRefValue2 = QtLocation.QGeoRouteRequest.TravelMode.PedestrianTravel + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtLocation_VisibilityScope_Visibility.py b/tests/qflags/test_QtLocation_VisibilityScope_Visibility.py new file mode 100644 index 00000000..3a66ca49 --- /dev/null +++ b/tests/qflags/test_QtLocation_VisibilityScope_Visibility.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QLocation.VisibilityScope" and flag class "QLocation.Visibility" +from PyQt5 import QtLocation + +OneFlagClass = QtLocation.QLocation.Visibility +MultiFlagClass = QtLocation.QLocation.VisibilityScope + +oneFlagRefValue1 = QtLocation.QLocation.Visibility.UnspecifiedVisibility +oneFlagRefValue2 = QtLocation.QLocation.Visibility.DeviceVisibility + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtMultimedia_CaptureDestinations_CaptureDestination.py b/tests/qflags/test_QtMultimedia_CaptureDestinations_CaptureDestination.py new file mode 100644 index 00000000..a4a9210b --- /dev/null +++ b/tests/qflags/test_QtMultimedia_CaptureDestinations_CaptureDestination.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QCameraImageCapture.CaptureDestinations" and flag class "QCameraImageCapture.CaptureDestination" +from PyQt5 import QtMultimedia + +OneFlagClass = QtMultimedia.QCameraImageCapture.CaptureDestination +MultiFlagClass = QtMultimedia.QCameraImageCapture.CaptureDestinations + +oneFlagRefValue1 = QtMultimedia.QCameraImageCapture.CaptureDestination.CaptureToFile +oneFlagRefValue2 = QtMultimedia.QCameraImageCapture.CaptureDestination.CaptureToBuffer + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtMultimedia_CaptureModes_CaptureMode.py b/tests/qflags/test_QtMultimedia_CaptureModes_CaptureMode.py new file mode 100644 index 00000000..5734ba91 --- /dev/null +++ b/tests/qflags/test_QtMultimedia_CaptureModes_CaptureMode.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QCamera.CaptureModes" and flag class "QCamera.CaptureMode" +from PyQt5 import QtMultimedia + +OneFlagClass = QtMultimedia.QCamera.CaptureMode +MultiFlagClass = QtMultimedia.QCamera.CaptureModes + +oneFlagRefValue1 = QtMultimedia.QCamera.CaptureMode.CaptureViewfinder +oneFlagRefValue2 = QtMultimedia.QCamera.CaptureMode.CaptureStillImage + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtMultimedia_Flags_Flag.py b/tests/qflags/test_QtMultimedia_Flags_Flag.py new file mode 100644 index 00000000..0ec3bc98 --- /dev/null +++ b/tests/qflags/test_QtMultimedia_Flags_Flag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QMediaPlayer.Flags" and flag class "QMediaPlayer.Flag" +from PyQt5 import QtMultimedia + +OneFlagClass = QtMultimedia.QMediaPlayer.Flag +MultiFlagClass = QtMultimedia.QMediaPlayer.Flags + +oneFlagRefValue1 = QtMultimedia.QMediaPlayer.Flag.LowLatency +oneFlagRefValue2 = QtMultimedia.QMediaPlayer.Flag.StreamPlayback + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtMultimedia_FlashModes_FlashMode.py b/tests/qflags/test_QtMultimedia_FlashModes_FlashMode.py new file mode 100644 index 00000000..9d1f5ee6 --- /dev/null +++ b/tests/qflags/test_QtMultimedia_FlashModes_FlashMode.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QCameraExposure.FlashModes" and flag class "QCameraExposure.FlashMode" +from PyQt5 import QtMultimedia + +OneFlagClass = QtMultimedia.QCameraExposure.FlashMode +MultiFlagClass = QtMultimedia.QCameraExposure.FlashModes + +oneFlagRefValue1 = QtMultimedia.QCameraExposure.FlashMode.FlashAuto +oneFlagRefValue2 = QtMultimedia.QCameraExposure.FlashMode.FlashOff + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtMultimedia_FocusModes_FocusMode.py b/tests/qflags/test_QtMultimedia_FocusModes_FocusMode.py new file mode 100644 index 00000000..8ea29e5e --- /dev/null +++ b/tests/qflags/test_QtMultimedia_FocusModes_FocusMode.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QCameraFocus.FocusModes" and flag class "QCameraFocus.FocusMode" +from PyQt5 import QtMultimedia + +OneFlagClass = QtMultimedia.QCameraFocus.FocusMode +MultiFlagClass = QtMultimedia.QCameraFocus.FocusModes + +oneFlagRefValue1 = QtMultimedia.QCameraFocus.FocusMode.ManualFocus +oneFlagRefValue2 = QtMultimedia.QCameraFocus.FocusMode.HyperfocalFocus + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtMultimedia_LockTypes_LockType.py b/tests/qflags/test_QtMultimedia_LockTypes_LockType.py new file mode 100644 index 00000000..acaa6b1f --- /dev/null +++ b/tests/qflags/test_QtMultimedia_LockTypes_LockType.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QCamera.LockTypes" and flag class "QCamera.LockType" +from PyQt5 import QtMultimedia + +OneFlagClass = QtMultimedia.QCamera.LockType +MultiFlagClass = QtMultimedia.QCamera.LockTypes + +oneFlagRefValue1 = QtMultimedia.QCamera.LockType.NoLock +oneFlagRefValue2 = QtMultimedia.QCamera.LockType.LockExposure + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtMultimedia_RunFlags_RunFlag.py b/tests/qflags/test_QtMultimedia_RunFlags_RunFlag.py new file mode 100644 index 00000000..67de9c24 --- /dev/null +++ b/tests/qflags/test_QtMultimedia_RunFlags_RunFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QVideoFilterRunnable.RunFlags" and flag class "QVideoFilterRunnable.RunFlag" +from PyQt5 import QtMultimedia + +OneFlagClass = QtMultimedia.QVideoFilterRunnable.RunFlag +MultiFlagClass = QtMultimedia.QVideoFilterRunnable.RunFlags + +oneFlagRefValue1 = QtMultimedia.QVideoFilterRunnable.RunFlag.LastInChain +oneFlagRefValue2 = QtMultimedia.QVideoFilterRunnable.RunFlag.LastInChain + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_BindMode_BindFlag.py b/tests/qflags/test_QtNetwork_BindMode_BindFlag.py new file mode 100644 index 00000000..fce29fac --- /dev/null +++ b/tests/qflags/test_QtNetwork_BindMode_BindFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QAbstractSocket.BindMode" and flag class "QAbstractSocket.BindFlag" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QAbstractSocket.BindFlag +MultiFlagClass = QtNetwork.QAbstractSocket.BindMode + +oneFlagRefValue1 = QtNetwork.QAbstractSocket.BindFlag.DefaultForPlatform +oneFlagRefValue2 = QtNetwork.QAbstractSocket.BindFlag.ShareAddress + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_Capabilities_Capability.py b/tests/qflags/test_QtNetwork_Capabilities_Capability.py new file mode 100644 index 00000000..150a8949 --- /dev/null +++ b/tests/qflags/test_QtNetwork_Capabilities_Capability.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QNetworkProxy.Capabilities" and flag class "QNetworkProxy.Capability" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QNetworkProxy.Capability +MultiFlagClass = QtNetwork.QNetworkProxy.Capabilities + +oneFlagRefValue1 = QtNetwork.QNetworkProxy.Capability.TunnelingCapability +oneFlagRefValue2 = QtNetwork.QNetworkProxy.Capability.ListeningCapability + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_ConversionMode_ConversionModeFlag.py b/tests/qflags/test_QtNetwork_ConversionMode_ConversionModeFlag.py new file mode 100644 index 00000000..ae275d5d --- /dev/null +++ b/tests/qflags/test_QtNetwork_ConversionMode_ConversionModeFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QHostAddress.ConversionMode" and flag class "QHostAddress.ConversionModeFlag" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QHostAddress.ConversionModeFlag +MultiFlagClass = QtNetwork.QHostAddress.ConversionMode + +oneFlagRefValue1 = QtNetwork.QHostAddress.ConversionModeFlag.ConvertV4MappedToIPv4 +oneFlagRefValue2 = QtNetwork.QHostAddress.ConversionModeFlag.ConvertV4CompatToIPv4 + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_InterfaceFlags_InterfaceFlag.py b/tests/qflags/test_QtNetwork_InterfaceFlags_InterfaceFlag.py new file mode 100644 index 00000000..4ab0e7c8 --- /dev/null +++ b/tests/qflags/test_QtNetwork_InterfaceFlags_InterfaceFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QNetworkInterface.InterfaceFlags" and flag class "QNetworkInterface.InterfaceFlag" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QNetworkInterface.InterfaceFlag +MultiFlagClass = QtNetwork.QNetworkInterface.InterfaceFlags + +oneFlagRefValue1 = QtNetwork.QNetworkInterface.InterfaceFlag.IsUp +oneFlagRefValue2 = QtNetwork.QNetworkInterface.InterfaceFlag.IsRunning + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_PauseModes_PauseMode.py b/tests/qflags/test_QtNetwork_PauseModes_PauseMode.py new file mode 100644 index 00000000..724aa9fb --- /dev/null +++ b/tests/qflags/test_QtNetwork_PauseModes_PauseMode.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QAbstractSocket.PauseModes" and flag class "QAbstractSocket.PauseMode" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QAbstractSocket.PauseMode +MultiFlagClass = QtNetwork.QAbstractSocket.PauseModes + +oneFlagRefValue1 = QtNetwork.QAbstractSocket.PauseMode.PauseNever +oneFlagRefValue2 = QtNetwork.QAbstractSocket.PauseMode.PauseOnSslErrors + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_PolicyFlags_PolicyFlag.py b/tests/qflags/test_QtNetwork_PolicyFlags_PolicyFlag.py new file mode 100644 index 00000000..35edd3ec --- /dev/null +++ b/tests/qflags/test_QtNetwork_PolicyFlags_PolicyFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QHstsPolicy.PolicyFlags" and flag class "QHstsPolicy.PolicyFlag" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QHstsPolicy.PolicyFlag +MultiFlagClass = QtNetwork.QHstsPolicy.PolicyFlags + +oneFlagRefValue1 = QtNetwork.QHstsPolicy.PolicyFlag.IncludeSubDomains +oneFlagRefValue2 = QtNetwork.QHstsPolicy.PolicyFlag.IncludeSubDomains + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_SocketOptions_SocketOption.py b/tests/qflags/test_QtNetwork_SocketOptions_SocketOption.py new file mode 100644 index 00000000..c117e1c6 --- /dev/null +++ b/tests/qflags/test_QtNetwork_SocketOptions_SocketOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QLocalServer.SocketOptions" and flag class "QLocalServer.SocketOption" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QLocalServer.SocketOption +MultiFlagClass = QtNetwork.QLocalServer.SocketOptions + +oneFlagRefValue1 = QtNetwork.QLocalServer.SocketOption.UserAccessOption +oneFlagRefValue2 = QtNetwork.QLocalServer.SocketOption.GroupAccessOption + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_SslOptions_SslOption.py b/tests/qflags/test_QtNetwork_SslOptions_SslOption.py new file mode 100644 index 00000000..6b801072 --- /dev/null +++ b/tests/qflags/test_QtNetwork_SslOptions_SslOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSsl.SslOptions" and flag class "QSsl.SslOption" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QSsl.SslOption +MultiFlagClass = QtNetwork.QSsl.SslOptions + +oneFlagRefValue1 = QtNetwork.QSsl.SslOption.SslOptionDisableEmptyFragments +oneFlagRefValue2 = QtNetwork.QSsl.SslOption.SslOptionDisableSessionTickets + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_StateFlags_StateFlag.py b/tests/qflags/test_QtNetwork_StateFlags_StateFlag.py new file mode 100644 index 00000000..79e175d3 --- /dev/null +++ b/tests/qflags/test_QtNetwork_StateFlags_StateFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QNetworkConfiguration.StateFlags" and flag class "QNetworkConfiguration.StateFlag" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QNetworkConfiguration.StateFlag +MultiFlagClass = QtNetwork.QNetworkConfiguration.StateFlags + +oneFlagRefValue1 = QtNetwork.QNetworkConfiguration.StateFlag.Undefined +oneFlagRefValue2 = QtNetwork.QNetworkConfiguration.StateFlag.Defined + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNetwork_UsagePolicies_UsagePolicy.py b/tests/qflags/test_QtNetwork_UsagePolicies_UsagePolicy.py new file mode 100644 index 00000000..bf2f4034 --- /dev/null +++ b/tests/qflags/test_QtNetwork_UsagePolicies_UsagePolicy.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QNetworkSession.UsagePolicies" and flag class "QNetworkSession.UsagePolicy" +from PyQt5 import QtNetwork + +OneFlagClass = QtNetwork.QNetworkSession.UsagePolicy +MultiFlagClass = QtNetwork.QNetworkSession.UsagePolicies + +oneFlagRefValue1 = QtNetwork.QNetworkSession.UsagePolicy.NoPolicy +oneFlagRefValue2 = QtNetwork.QNetworkSession.UsagePolicy.NoBackgroundTrafficPolicy + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNfc_AccessMethods_AccessMethod.py b/tests/qflags/test_QtNfc_AccessMethods_AccessMethod.py new file mode 100644 index 00000000..435189f1 --- /dev/null +++ b/tests/qflags/test_QtNfc_AccessMethods_AccessMethod.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QNearFieldTarget.AccessMethods" and flag class "QNearFieldTarget.AccessMethod" +from PyQt5 import QtNfc + +OneFlagClass = QtNfc.QNearFieldTarget.AccessMethod +MultiFlagClass = QtNfc.QNearFieldTarget.AccessMethods + +oneFlagRefValue1 = QtNfc.QNearFieldTarget.AccessMethod.UnknownAccess +oneFlagRefValue2 = QtNfc.QNearFieldTarget.AccessMethod.NdefAccess + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNfc_ShareModes_ShareMode.py b/tests/qflags/test_QtNfc_ShareModes_ShareMode.py new file mode 100644 index 00000000..83b6de06 --- /dev/null +++ b/tests/qflags/test_QtNfc_ShareModes_ShareMode.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QNearFieldShareManager.ShareModes" and flag class "QNearFieldShareManager.ShareMode" +from PyQt5 import QtNfc + +OneFlagClass = QtNfc.QNearFieldShareManager.ShareMode +MultiFlagClass = QtNfc.QNearFieldShareManager.ShareModes + +oneFlagRefValue1 = QtNfc.QNearFieldShareManager.ShareMode.NoShare +oneFlagRefValue2 = QtNfc.QNearFieldShareManager.ShareMode.NdefShare + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtNfc_TargetAccessModes_TargetAccessMode.py b/tests/qflags/test_QtNfc_TargetAccessModes_TargetAccessMode.py new file mode 100644 index 00000000..91ba2167 --- /dev/null +++ b/tests/qflags/test_QtNfc_TargetAccessModes_TargetAccessMode.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QNearFieldManager.TargetAccessModes" and flag class "QNearFieldManager.TargetAccessMode" +from PyQt5 import QtNfc + +OneFlagClass = QtNfc.QNearFieldManager.TargetAccessMode +MultiFlagClass = QtNfc.QNearFieldManager.TargetAccessModes + +oneFlagRefValue1 = QtNfc.QNearFieldManager.TargetAccessMode.NoTargetAccess +oneFlagRefValue2 = QtNfc.QNearFieldManager.TargetAccessMode.NdefReadTargetAccess + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtOpenGL_BindOptions_BindOption.py b/tests/qflags/test_QtOpenGL_BindOptions_BindOption.py new file mode 100644 index 00000000..6d5753cd --- /dev/null +++ b/tests/qflags/test_QtOpenGL_BindOptions_BindOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGLContext.BindOptions" and flag class "QGLContext.BindOption" +from PyQt5 import QtOpenGL + +OneFlagClass = QtOpenGL.QGLContext.BindOption +MultiFlagClass = QtOpenGL.QGLContext.BindOptions + +oneFlagRefValue1 = QtOpenGL.QGLContext.BindOption.NoBindOption +oneFlagRefValue2 = QtOpenGL.QGLContext.BindOption.InvertedYBindOption + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtOpenGL_FormatOptions_FormatOption.py b/tests/qflags/test_QtOpenGL_FormatOptions_FormatOption.py new file mode 100644 index 00000000..3039902f --- /dev/null +++ b/tests/qflags/test_QtOpenGL_FormatOptions_FormatOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGL.FormatOptions" and flag class "QGL.FormatOption" +from PyQt5 import QtOpenGL + +OneFlagClass = QtOpenGL.QGL.FormatOption +MultiFlagClass = QtOpenGL.QGL.FormatOptions + +oneFlagRefValue1 = QtOpenGL.QGL.FormatOption.DoubleBuffer +oneFlagRefValue2 = QtOpenGL.QGL.FormatOption.DepthBuffer + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtOpenGL_OpenGLVersionFlags_OpenGLVersionFlag.py b/tests/qflags/test_QtOpenGL_OpenGLVersionFlags_OpenGLVersionFlag.py new file mode 100644 index 00000000..25400de5 --- /dev/null +++ b/tests/qflags/test_QtOpenGL_OpenGLVersionFlags_OpenGLVersionFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGLFormat.OpenGLVersionFlags" and flag class "QGLFormat.OpenGLVersionFlag" +from PyQt5 import QtOpenGL + +OneFlagClass = QtOpenGL.QGLFormat.OpenGLVersionFlag +MultiFlagClass = QtOpenGL.QGLFormat.OpenGLVersionFlags + +oneFlagRefValue1 = QtOpenGL.QGLFormat.OpenGLVersionFlag.OpenGL_Version_None +oneFlagRefValue2 = QtOpenGL.QGLFormat.OpenGLVersionFlag.OpenGL_Version_1_1 + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtPositioning_AreaMonitorFeatures_AreaMonitorFeature.py b/tests/qflags/test_QtPositioning_AreaMonitorFeatures_AreaMonitorFeature.py new file mode 100644 index 00000000..a0813aea --- /dev/null +++ b/tests/qflags/test_QtPositioning_AreaMonitorFeatures_AreaMonitorFeature.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoAreaMonitorSource.AreaMonitorFeatures" and flag class "QGeoAreaMonitorSource.AreaMonitorFeature" +from PyQt5 import QtPositioning + +OneFlagClass = QtPositioning.QGeoAreaMonitorSource.AreaMonitorFeature +MultiFlagClass = QtPositioning.QGeoAreaMonitorSource.AreaMonitorFeatures + +oneFlagRefValue1 = QtPositioning.QGeoAreaMonitorSource.AreaMonitorFeature.PersistentAreaMonitorFeature +oneFlagRefValue2 = QtPositioning.QGeoAreaMonitorSource.AreaMonitorFeature.AnyAreaMonitorFeature + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtPositioning_PositioningMethods_PositioningMethod.py b/tests/qflags/test_QtPositioning_PositioningMethods_PositioningMethod.py new file mode 100644 index 00000000..511d532e --- /dev/null +++ b/tests/qflags/test_QtPositioning_PositioningMethods_PositioningMethod.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGeoPositionInfoSource.PositioningMethods" and flag class "QGeoPositionInfoSource.PositioningMethod" +from PyQt5 import QtPositioning + +OneFlagClass = QtPositioning.QGeoPositionInfoSource.PositioningMethod +MultiFlagClass = QtPositioning.QGeoPositionInfoSource.PositioningMethods + +oneFlagRefValue1 = QtPositioning.QGeoPositionInfoSource.PositioningMethod.NoPositioningMethods +oneFlagRefValue2 = QtPositioning.QGeoPositionInfoSource.PositioningMethod.SatellitePositioningMethods + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtPrintSupport_PrintDialogOptions_PrintDialogOption.py b/tests/qflags/test_QtPrintSupport_PrintDialogOptions_PrintDialogOption.py new file mode 100644 index 00000000..7cc178b1 --- /dev/null +++ b/tests/qflags/test_QtPrintSupport_PrintDialogOptions_PrintDialogOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QAbstractPrintDialog.PrintDialogOptions" and flag class "QAbstractPrintDialog.PrintDialogOption" +from PyQt5 import QtPrintSupport + +OneFlagClass = QtPrintSupport.QAbstractPrintDialog.PrintDialogOption +MultiFlagClass = QtPrintSupport.QAbstractPrintDialog.PrintDialogOptions + +oneFlagRefValue1 = QtPrintSupport.QAbstractPrintDialog.PrintDialogOption.None_ +oneFlagRefValue2 = QtPrintSupport.QAbstractPrintDialog.PrintDialogOption.PrintToFile + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQml_Extensions_Extension.py b/tests/qflags/test_QtQml_Extensions_Extension.py new file mode 100644 index 00000000..d1e25c7d --- /dev/null +++ b/tests/qflags/test_QtQml_Extensions_Extension.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QJSEngine.Extensions" and flag class "QJSEngine.Extension" +from PyQt5 import QtQml + +OneFlagClass = QtQml.QJSEngine.Extension +MultiFlagClass = QtQml.QJSEngine.Extensions + +oneFlagRefValue1 = QtQml.QJSEngine.Extension.TranslationExtension +oneFlagRefValue2 = QtQml.QJSEngine.Extension.ConsoleExtension + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQml_Flags_Flag.py b/tests/qflags/test_QtQml_Flags_Flag.py new file mode 100644 index 00000000..f4abeeb6 --- /dev/null +++ b/tests/qflags/test_QtQml_Flags_Flag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QQmlImageProviderBase.Flags" and flag class "QQmlImageProviderBase.Flag" +from PyQt5 import QtQml + +OneFlagClass = QtQml.QQmlImageProviderBase.Flag +MultiFlagClass = QtQml.QQmlImageProviderBase.Flags + +oneFlagRefValue1 = QtQml.QQmlImageProviderBase.Flag.ForceAsynchronousImageLoading +oneFlagRefValue2 = QtQml.QQmlImageProviderBase.Flag.ForceAsynchronousImageLoading + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_ClearMode_ClearModeBit.py b/tests/qflags/test_QtQuick_ClearMode_ClearModeBit.py new file mode 100644 index 00000000..2dda0ff1 --- /dev/null +++ b/tests/qflags/test_QtQuick_ClearMode_ClearModeBit.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGAbstractRenderer.ClearMode" and flag class "QSGAbstractRenderer.ClearModeBit" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGAbstractRenderer.ClearModeBit +MultiFlagClass = QtQuick.QSGAbstractRenderer.ClearMode + +oneFlagRefValue1 = QtQuick.QSGAbstractRenderer.ClearModeBit.ClearColorBuffer +oneFlagRefValue2 = QtQuick.QSGAbstractRenderer.ClearModeBit.ClearDepthBuffer + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_ColorMask_ColorMaskComponent.py b/tests/qflags/test_QtQuick_ColorMask_ColorMaskComponent.py new file mode 100644 index 00000000..6e77a54d --- /dev/null +++ b/tests/qflags/test_QtQuick_ColorMask_ColorMaskComponent.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGMaterialRhiShader.GraphicsPipelineState.ColorMask" and flag class "QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent +MultiFlagClass = QtQuick.QSGMaterialRhiShader.GraphicsPipelineState.ColorMask + +oneFlagRefValue1 = QtQuick.QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent.R +oneFlagRefValue2 = QtQuick.QSGMaterialRhiShader.GraphicsPipelineState.ColorMaskComponent.G + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_CreateTextureOptions_CreateTextureOption.py b/tests/qflags/test_QtQuick_CreateTextureOptions_CreateTextureOption.py new file mode 100644 index 00000000..822cf323 --- /dev/null +++ b/tests/qflags/test_QtQuick_CreateTextureOptions_CreateTextureOption.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGEngine.CreateTextureOptions" and flag class "QSGEngine.CreateTextureOption" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGEngine.CreateTextureOption +MultiFlagClass = QtQuick.QSGEngine.CreateTextureOptions + +oneFlagRefValue1 = QtQuick.QSGEngine.CreateTextureOption.TextureHasAlphaChannel +oneFlagRefValue2 = QtQuick.QSGEngine.CreateTextureOption.TextureOwnsGLTexture + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_DirtyState_DirtyStateBit.py b/tests/qflags/test_QtQuick_DirtyState_DirtyStateBit.py new file mode 100644 index 00000000..e6811c98 --- /dev/null +++ b/tests/qflags/test_QtQuick_DirtyState_DirtyStateBit.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGNode.DirtyState" and flag class "QSGNode.DirtyStateBit" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGNode.DirtyStateBit +MultiFlagClass = QtQuick.QSGNode.DirtyState + +oneFlagRefValue1 = QtQuick.QSGNode.DirtyStateBit.DirtyMatrix +oneFlagRefValue2 = QtQuick.QSGNode.DirtyStateBit.DirtyNodeAdded + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_Flags_Flag.py b/tests/qflags/test_QtQuick_Flags_Flag.py new file mode 100644 index 00000000..3e047b10 --- /dev/null +++ b/tests/qflags/test_QtQuick_Flags_Flag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGMaterialRhiShader.Flags" and flag class "QSGMaterialRhiShader.Flag" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGMaterialRhiShader.Flag +MultiFlagClass = QtQuick.QSGMaterialRhiShader.Flags + +oneFlagRefValue1 = QtQuick.QSGMaterialRhiShader.Flag.UpdatesGraphicsPipelineState +oneFlagRefValue2 = QtQuick.QSGMaterialRhiShader.Flag.UpdatesGraphicsPipelineState + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_MatrixTransformFlags_MatrixTransformFlag.py b/tests/qflags/test_QtQuick_MatrixTransformFlags_MatrixTransformFlag.py new file mode 100644 index 00000000..1c8a7b05 --- /dev/null +++ b/tests/qflags/test_QtQuick_MatrixTransformFlags_MatrixTransformFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGAbstractRenderer.MatrixTransformFlags" and flag class "QSGAbstractRenderer.MatrixTransformFlag" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGAbstractRenderer.MatrixTransformFlag +MultiFlagClass = QtQuick.QSGAbstractRenderer.MatrixTransformFlags + +oneFlagRefValue1 = QtQuick.QSGAbstractRenderer.MatrixTransformFlag.MatrixTransformFlipY +oneFlagRefValue2 = QtQuick.QSGAbstractRenderer.MatrixTransformFlag.MatrixTransformFlipY + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_PerformanceHints_PerformanceHint.py b/tests/qflags/test_QtQuick_PerformanceHints_PerformanceHint.py new file mode 100644 index 00000000..d6d19f48 --- /dev/null +++ b/tests/qflags/test_QtQuick_PerformanceHints_PerformanceHint.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QQuickPaintedItem.PerformanceHints" and flag class "QQuickPaintedItem.PerformanceHint" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QQuickPaintedItem.PerformanceHint +MultiFlagClass = QtQuick.QQuickPaintedItem.PerformanceHints + +oneFlagRefValue1 = QtQuick.QQuickPaintedItem.PerformanceHint.FastFBOResizing +oneFlagRefValue2 = QtQuick.QQuickPaintedItem.PerformanceHint.FastFBOResizing + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_RenderingFlags_RenderingFlag.py b/tests/qflags/test_QtQuick_RenderingFlags_RenderingFlag.py new file mode 100644 index 00000000..53900aec --- /dev/null +++ b/tests/qflags/test_QtQuick_RenderingFlags_RenderingFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGRenderNode.RenderingFlags" and flag class "QSGRenderNode.RenderingFlag" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGRenderNode.RenderingFlag +MultiFlagClass = QtQuick.QSGRenderNode.RenderingFlags + +oneFlagRefValue1 = QtQuick.QSGRenderNode.RenderingFlag.BoundedRectRendering +oneFlagRefValue2 = QtQuick.QSGRenderNode.RenderingFlag.DepthAwareRendering + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_ShaderCompilationTypes_ShaderCompilationType.py b/tests/qflags/test_QtQuick_ShaderCompilationTypes_ShaderCompilationType.py new file mode 100644 index 00000000..30e909f3 --- /dev/null +++ b/tests/qflags/test_QtQuick_ShaderCompilationTypes_ShaderCompilationType.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGRendererInterface.ShaderCompilationTypes" and flag class "QSGRendererInterface.ShaderCompilationType" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGRendererInterface.ShaderCompilationType +MultiFlagClass = QtQuick.QSGRendererInterface.ShaderCompilationTypes + +oneFlagRefValue1 = QtQuick.QSGRendererInterface.ShaderCompilationType.RuntimeCompilation +oneFlagRefValue2 = QtQuick.QSGRendererInterface.ShaderCompilationType.OfflineCompilation + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_ShaderSourceTypes_ShaderSourceType.py b/tests/qflags/test_QtQuick_ShaderSourceTypes_ShaderSourceType.py new file mode 100644 index 00000000..7a7689e3 --- /dev/null +++ b/tests/qflags/test_QtQuick_ShaderSourceTypes_ShaderSourceType.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGRendererInterface.ShaderSourceTypes" and flag class "QSGRendererInterface.ShaderSourceType" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGRendererInterface.ShaderSourceType +MultiFlagClass = QtQuick.QSGRendererInterface.ShaderSourceTypes + +oneFlagRefValue1 = QtQuick.QSGRendererInterface.ShaderSourceType.ShaderSourceString +oneFlagRefValue2 = QtQuick.QSGRendererInterface.ShaderSourceType.ShaderSourceFile + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_StateFlags_StateFlag.py b/tests/qflags/test_QtQuick_StateFlags_StateFlag.py new file mode 100644 index 00000000..aad01618 --- /dev/null +++ b/tests/qflags/test_QtQuick_StateFlags_StateFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGRenderNode.StateFlags" and flag class "QSGRenderNode.StateFlag" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGRenderNode.StateFlag +MultiFlagClass = QtQuick.QSGRenderNode.StateFlags + +oneFlagRefValue1 = QtQuick.QSGRenderNode.StateFlag.DepthState +oneFlagRefValue2 = QtQuick.QSGRenderNode.StateFlag.StencilState + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtQuick_TextureCoordinatesTransformMode_TextureCoordinatesTransformFlag.py b/tests/qflags/test_QtQuick_TextureCoordinatesTransformMode_TextureCoordinatesTransformFlag.py new file mode 100644 index 00000000..a3bc3338 --- /dev/null +++ b/tests/qflags/test_QtQuick_TextureCoordinatesTransformMode_TextureCoordinatesTransformFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSGSimpleTextureNode.TextureCoordinatesTransformMode" and flag class "QSGSimpleTextureNode.TextureCoordinatesTransformFlag" +from PyQt5 import QtQuick + +OneFlagClass = QtQuick.QSGSimpleTextureNode.TextureCoordinatesTransformFlag +MultiFlagClass = QtQuick.QSGSimpleTextureNode.TextureCoordinatesTransformMode + +oneFlagRefValue1 = QtQuick.QSGSimpleTextureNode.TextureCoordinatesTransformFlag.NoTransform +oneFlagRefValue2 = QtQuick.QSGSimpleTextureNode.TextureCoordinatesTransformFlag.MirrorHorizontally + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtSerialPort_Directions_Direction.py b/tests/qflags/test_QtSerialPort_Directions_Direction.py new file mode 100644 index 00000000..f85a0d56 --- /dev/null +++ b/tests/qflags/test_QtSerialPort_Directions_Direction.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSerialPort.Directions" and flag class "QSerialPort.Direction" +from PyQt5 import QtSerialPort + +OneFlagClass = QtSerialPort.QSerialPort.Direction +MultiFlagClass = QtSerialPort.QSerialPort.Directions + +oneFlagRefValue1 = QtSerialPort.QSerialPort.Direction.Input +oneFlagRefValue2 = QtSerialPort.QSerialPort.Direction.Output + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtSerialPort_PinoutSignals_PinoutSignal.py b/tests/qflags/test_QtSerialPort_PinoutSignals_PinoutSignal.py new file mode 100644 index 00000000..1db5c045 --- /dev/null +++ b/tests/qflags/test_QtSerialPort_PinoutSignals_PinoutSignal.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSerialPort.PinoutSignals" and flag class "QSerialPort.PinoutSignal" +from PyQt5 import QtSerialPort + +OneFlagClass = QtSerialPort.QSerialPort.PinoutSignal +MultiFlagClass = QtSerialPort.QSerialPort.PinoutSignals + +oneFlagRefValue1 = QtSerialPort.QSerialPort.PinoutSignal.NoSignal +oneFlagRefValue2 = QtSerialPort.QSerialPort.PinoutSignal.TransmittedDataSignal + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtSql_ParamType_ParamTypeFlag.py b/tests/qflags/test_QtSql_ParamType_ParamTypeFlag.py new file mode 100644 index 00000000..f3fbc3a2 --- /dev/null +++ b/tests/qflags/test_QtSql_ParamType_ParamTypeFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSql.ParamType" and flag class "QSql.ParamTypeFlag" +from PyQt5 import QtSql + +OneFlagClass = QtSql.QSql.ParamTypeFlag +MultiFlagClass = QtSql.QSql.ParamType + +oneFlagRefValue1 = QtSql.QSql.ParamTypeFlag.In +oneFlagRefValue2 = QtSql.QSql.ParamTypeFlag.Out + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWebEngineCore_Flags_Flag.py b/tests/qflags/test_QtWebEngineCore_Flags_Flag.py new file mode 100644 index 00000000..3678f783 --- /dev/null +++ b/tests/qflags/test_QtWebEngineCore_Flags_Flag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QWebEngineUrlScheme.Flags" and flag class "QWebEngineUrlScheme.Flag" +from PyQt5 import QtWebEngineCore + +OneFlagClass = QtWebEngineCore.QWebEngineUrlScheme.Flag +MultiFlagClass = QtWebEngineCore.QWebEngineUrlScheme.Flags + +oneFlagRefValue1 = QtWebEngineCore.QWebEngineUrlScheme.Flag.SecureScheme +oneFlagRefValue2 = QtWebEngineCore.QWebEngineUrlScheme.Flag.LocalScheme + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWebEngineWidgets_EditFlags_EditFlag.py b/tests/qflags/test_QtWebEngineWidgets_EditFlags_EditFlag.py new file mode 100644 index 00000000..6717cc6f --- /dev/null +++ b/tests/qflags/test_QtWebEngineWidgets_EditFlags_EditFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QWebEngineContextMenuData.EditFlags" and flag class "QWebEngineContextMenuData.EditFlag" +from PyQt5 import QtWebEngineWidgets + +OneFlagClass = QtWebEngineWidgets.QWebEngineContextMenuData.EditFlag +MultiFlagClass = QtWebEngineWidgets.QWebEngineContextMenuData.EditFlags + +oneFlagRefValue1 = QtWebEngineWidgets.QWebEngineContextMenuData.EditFlag.CanUndo +oneFlagRefValue2 = QtWebEngineWidgets.QWebEngineContextMenuData.EditFlag.CanRedo + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWebEngineWidgets_FindFlags_FindFlag.py b/tests/qflags/test_QtWebEngineWidgets_FindFlags_FindFlag.py new file mode 100644 index 00000000..f911102a --- /dev/null +++ b/tests/qflags/test_QtWebEngineWidgets_FindFlags_FindFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QWebEnginePage.FindFlags" and flag class "QWebEnginePage.FindFlag" +from PyQt5 import QtWebEngineWidgets + +OneFlagClass = QtWebEngineWidgets.QWebEnginePage.FindFlag +MultiFlagClass = QtWebEngineWidgets.QWebEnginePage.FindFlags + +oneFlagRefValue1 = QtWebEngineWidgets.QWebEnginePage.FindFlag.FindBackward +oneFlagRefValue2 = QtWebEngineWidgets.QWebEnginePage.FindFlag.FindCaseSensitively + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWebEngineWidgets_MediaFlags_MediaFlag.py b/tests/qflags/test_QtWebEngineWidgets_MediaFlags_MediaFlag.py new file mode 100644 index 00000000..c8541810 --- /dev/null +++ b/tests/qflags/test_QtWebEngineWidgets_MediaFlags_MediaFlag.py @@ -0,0 +1,272 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QWebEngineContextMenuData.MediaFlags" and flag class "QWebEngineContextMenuData.MediaFlag" +from PyQt5 import QtWebEngineWidgets + +OneFlagClass = QtWebEngineWidgets.QWebEngineContextMenuData.MediaFlag +MultiFlagClass = QtWebEngineWidgets.QWebEngineContextMenuData.MediaFlags + +oneFlagRefValue1 = QtWebEngineWidgets.QWebEngineContextMenuData.MediaFlag.MediaInError +oneFlagRefValue2 = QtWebEngineWidgets.QWebEngineContextMenuData.MediaFlag.MediaPaused + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +SUPPORTS_ONE_OP_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + if SUPPORTS_ONE_OP_MULTI: + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + if not SUPPORTS_ONE_OP_MULTI: + pytest.raises(TypeError, lambda: oneFlagValue1 | multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 & multiFlagValue1) + pytest.raises(TypeError, lambda: oneFlagValue1 ^ multiFlagValue1) + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_AreaOptions_AreaOption.py b/tests/qflags/test_QtWidgets_AreaOptions_AreaOption.py new file mode 100644 index 00000000..aaade60b --- /dev/null +++ b/tests/qflags/test_QtWidgets_AreaOptions_AreaOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QMdiArea.AreaOptions" and flag class "QMdiArea.AreaOption" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QMdiArea.AreaOption +MultiFlagClass = QtWidgets.QMdiArea.AreaOptions + +oneFlagRefValue1 = QtWidgets.QMdiArea.AreaOption.DontMaximizeSubWindowOnActivation +oneFlagRefValue2 = QtWidgets.QMdiArea.AreaOption.DontMaximizeSubWindowOnActivation + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_AutoFormatting_AutoFormattingFlag.py b/tests/qflags/test_QtWidgets_AutoFormatting_AutoFormattingFlag.py new file mode 100644 index 00000000..c089771c --- /dev/null +++ b/tests/qflags/test_QtWidgets_AutoFormatting_AutoFormattingFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTextEdit.AutoFormatting" and flag class "QTextEdit.AutoFormattingFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QTextEdit.AutoFormattingFlag +MultiFlagClass = QtWidgets.QTextEdit.AutoFormatting + +oneFlagRefValue1 = QtWidgets.QTextEdit.AutoFormattingFlag.AutoNone +oneFlagRefValue2 = QtWidgets.QTextEdit.AutoFormattingFlag.AutoBulletList + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_BlurHints_BlurHint.py b/tests/qflags/test_QtWidgets_BlurHints_BlurHint.py new file mode 100644 index 00000000..55b225fd --- /dev/null +++ b/tests/qflags/test_QtWidgets_BlurHints_BlurHint.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGraphicsBlurEffect.BlurHints" and flag class "QGraphicsBlurEffect.BlurHint" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QGraphicsBlurEffect.BlurHint +MultiFlagClass = QtWidgets.QGraphicsBlurEffect.BlurHints + +oneFlagRefValue1 = QtWidgets.QGraphicsBlurEffect.BlurHint.PerformanceHint +oneFlagRefValue2 = QtWidgets.QGraphicsBlurEffect.BlurHint.QualityHint + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_ButtonFeatures_ButtonFeature.py b/tests/qflags/test_QtWidgets_ButtonFeatures_ButtonFeature.py new file mode 100644 index 00000000..7a47e537 --- /dev/null +++ b/tests/qflags/test_QtWidgets_ButtonFeatures_ButtonFeature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStyleOptionButton.ButtonFeatures" and flag class "QStyleOptionButton.ButtonFeature" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QStyleOptionButton.ButtonFeature +MultiFlagClass = QtWidgets.QStyleOptionButton.ButtonFeatures + +oneFlagRefValue1 = QtWidgets.QStyleOptionButton.ButtonFeature.None_ +oneFlagRefValue2 = QtWidgets.QStyleOptionButton.ButtonFeature.Flat + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_CacheMode_CacheModeFlag.py b/tests/qflags/test_QtWidgets_CacheMode_CacheModeFlag.py new file mode 100644 index 00000000..e9c3d889 --- /dev/null +++ b/tests/qflags/test_QtWidgets_CacheMode_CacheModeFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGraphicsView.CacheMode" and flag class "QGraphicsView.CacheModeFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QGraphicsView.CacheModeFlag +MultiFlagClass = QtWidgets.QGraphicsView.CacheMode + +oneFlagRefValue1 = QtWidgets.QGraphicsView.CacheModeFlag.CacheNone +oneFlagRefValue2 = QtWidgets.QGraphicsView.CacheModeFlag.CacheBackground + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_ChangeFlags_ChangeFlag.py b/tests/qflags/test_QtWidgets_ChangeFlags_ChangeFlag.py new file mode 100644 index 00000000..f62e8683 --- /dev/null +++ b/tests/qflags/test_QtWidgets_ChangeFlags_ChangeFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGraphicsEffect.ChangeFlags" and flag class "QGraphicsEffect.ChangeFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QGraphicsEffect.ChangeFlag +MultiFlagClass = QtWidgets.QGraphicsEffect.ChangeFlags + +oneFlagRefValue1 = QtWidgets.QGraphicsEffect.ChangeFlag.SourceAttached +oneFlagRefValue2 = QtWidgets.QGraphicsEffect.ChangeFlag.SourceDetached + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_ColorDialogOptions_ColorDialogOption.py b/tests/qflags/test_QtWidgets_ColorDialogOptions_ColorDialogOption.py new file mode 100644 index 00000000..aa4227dd --- /dev/null +++ b/tests/qflags/test_QtWidgets_ColorDialogOptions_ColorDialogOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QColorDialog.ColorDialogOptions" and flag class "QColorDialog.ColorDialogOption" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QColorDialog.ColorDialogOption +MultiFlagClass = QtWidgets.QColorDialog.ColorDialogOptions + +oneFlagRefValue1 = QtWidgets.QColorDialog.ColorDialogOption.ShowAlphaChannel +oneFlagRefValue2 = QtWidgets.QColorDialog.ColorDialogOption.NoButtons + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_ControlTypes_ControlType.py b/tests/qflags/test_QtWidgets_ControlTypes_ControlType.py new file mode 100644 index 00000000..d649c98a --- /dev/null +++ b/tests/qflags/test_QtWidgets_ControlTypes_ControlType.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QSizePolicy.ControlTypes" and flag class "QSizePolicy.ControlType" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QSizePolicy.ControlType +MultiFlagClass = QtWidgets.QSizePolicy.ControlTypes + +oneFlagRefValue1 = QtWidgets.QSizePolicy.ControlType.DefaultType +oneFlagRefValue2 = QtWidgets.QSizePolicy.ControlType.ButtonBox + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_CornerWidgets_CornerWidget.py b/tests/qflags/test_QtWidgets_CornerWidgets_CornerWidget.py new file mode 100644 index 00000000..731b71e7 --- /dev/null +++ b/tests/qflags/test_QtWidgets_CornerWidgets_CornerWidget.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStyleOptionTab.CornerWidgets" and flag class "QStyleOptionTab.CornerWidget" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QStyleOptionTab.CornerWidget +MultiFlagClass = QtWidgets.QStyleOptionTab.CornerWidgets + +oneFlagRefValue1 = QtWidgets.QStyleOptionTab.CornerWidget.NoCornerWidgets +oneFlagRefValue2 = QtWidgets.QStyleOptionTab.CornerWidget.LeftCornerWidget + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_DockOptions_DockOption.py b/tests/qflags/test_QtWidgets_DockOptions_DockOption.py new file mode 100644 index 00000000..2688ed8a --- /dev/null +++ b/tests/qflags/test_QtWidgets_DockOptions_DockOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QMainWindow.DockOptions" and flag class "QMainWindow.DockOption" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QMainWindow.DockOption +MultiFlagClass = QtWidgets.QMainWindow.DockOptions + +oneFlagRefValue1 = QtWidgets.QMainWindow.DockOption.AnimatedDocks +oneFlagRefValue2 = QtWidgets.QMainWindow.DockOption.AllowNestedDocks + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_DockWidgetFeatures_DockWidgetFeature.py b/tests/qflags/test_QtWidgets_DockWidgetFeatures_DockWidgetFeature.py new file mode 100644 index 00000000..a8b45ed1 --- /dev/null +++ b/tests/qflags/test_QtWidgets_DockWidgetFeatures_DockWidgetFeature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QDockWidget.DockWidgetFeatures" and flag class "QDockWidget.DockWidgetFeature" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QDockWidget.DockWidgetFeature +MultiFlagClass = QtWidgets.QDockWidget.DockWidgetFeatures + +oneFlagRefValue1 = QtWidgets.QDockWidget.DockWidgetFeature.DockWidgetClosable +oneFlagRefValue2 = QtWidgets.QDockWidget.DockWidgetFeature.DockWidgetMovable + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_EditTriggers_EditTrigger.py b/tests/qflags/test_QtWidgets_EditTriggers_EditTrigger.py new file mode 100644 index 00000000..a0a259c2 --- /dev/null +++ b/tests/qflags/test_QtWidgets_EditTriggers_EditTrigger.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QAbstractItemView.EditTriggers" and flag class "QAbstractItemView.EditTrigger" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QAbstractItemView.EditTrigger +MultiFlagClass = QtWidgets.QAbstractItemView.EditTriggers + +oneFlagRefValue1 = QtWidgets.QAbstractItemView.EditTrigger.NoEditTriggers +oneFlagRefValue2 = QtWidgets.QAbstractItemView.EditTrigger.CurrentChanged + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_FontDialogOptions_FontDialogOption.py b/tests/qflags/test_QtWidgets_FontDialogOptions_FontDialogOption.py new file mode 100644 index 00000000..e917b5e0 --- /dev/null +++ b/tests/qflags/test_QtWidgets_FontDialogOptions_FontDialogOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QFontDialog.FontDialogOptions" and flag class "QFontDialog.FontDialogOption" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QFontDialog.FontDialogOption +MultiFlagClass = QtWidgets.QFontDialog.FontDialogOptions + +oneFlagRefValue1 = QtWidgets.QFontDialog.FontDialogOption.NoButtons +oneFlagRefValue2 = QtWidgets.QFontDialog.FontDialogOption.DontUseNativeDialog + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_FontFilters_FontFilter.py b/tests/qflags/test_QtWidgets_FontFilters_FontFilter.py new file mode 100644 index 00000000..5d567d86 --- /dev/null +++ b/tests/qflags/test_QtWidgets_FontFilters_FontFilter.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QFontComboBox.FontFilters" and flag class "QFontComboBox.FontFilter" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QFontComboBox.FontFilter +MultiFlagClass = QtWidgets.QFontComboBox.FontFilters + +oneFlagRefValue1 = QtWidgets.QFontComboBox.FontFilter.AllFonts +oneFlagRefValue2 = QtWidgets.QFontComboBox.FontFilter.ScalableFonts + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_FrameFeatures_FrameFeature.py b/tests/qflags/test_QtWidgets_FrameFeatures_FrameFeature.py new file mode 100644 index 00000000..1c6014c9 --- /dev/null +++ b/tests/qflags/test_QtWidgets_FrameFeatures_FrameFeature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStyleOptionFrame.FrameFeatures" and flag class "QStyleOptionFrame.FrameFeature" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QStyleOptionFrame.FrameFeature +MultiFlagClass = QtWidgets.QStyleOptionFrame.FrameFeatures + +oneFlagRefValue1 = QtWidgets.QStyleOptionFrame.FrameFeature.None_ +oneFlagRefValue2 = QtWidgets.QStyleOptionFrame.FrameFeature.Flat + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_GraphicsItemFlags_GraphicsItemFlag.py b/tests/qflags/test_QtWidgets_GraphicsItemFlags_GraphicsItemFlag.py new file mode 100644 index 00000000..179f956b --- /dev/null +++ b/tests/qflags/test_QtWidgets_GraphicsItemFlags_GraphicsItemFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGraphicsItem.GraphicsItemFlags" and flag class "QGraphicsItem.GraphicsItemFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QGraphicsItem.GraphicsItemFlag +MultiFlagClass = QtWidgets.QGraphicsItem.GraphicsItemFlags + +oneFlagRefValue1 = QtWidgets.QGraphicsItem.GraphicsItemFlag.ItemIsMovable +oneFlagRefValue2 = QtWidgets.QGraphicsItem.GraphicsItemFlag.ItemIsSelectable + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_InputDialogOptions_InputDialogOption.py b/tests/qflags/test_QtWidgets_InputDialogOptions_InputDialogOption.py new file mode 100644 index 00000000..29819c40 --- /dev/null +++ b/tests/qflags/test_QtWidgets_InputDialogOptions_InputDialogOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QInputDialog.InputDialogOptions" and flag class "QInputDialog.InputDialogOption" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QInputDialog.InputDialogOption +MultiFlagClass = QtWidgets.QInputDialog.InputDialogOptions + +oneFlagRefValue1 = QtWidgets.QInputDialog.InputDialogOption.NoButtons +oneFlagRefValue2 = QtWidgets.QInputDialog.InputDialogOption.UseListViewForComboBoxItems + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_IteratorFlags_IteratorFlag.py b/tests/qflags/test_QtWidgets_IteratorFlags_IteratorFlag.py new file mode 100644 index 00000000..02f40eae --- /dev/null +++ b/tests/qflags/test_QtWidgets_IteratorFlags_IteratorFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QTreeWidgetItemIterator.IteratorFlags" and flag class "QTreeWidgetItemIterator.IteratorFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QTreeWidgetItemIterator.IteratorFlag +MultiFlagClass = QtWidgets.QTreeWidgetItemIterator.IteratorFlags + +oneFlagRefValue1 = QtWidgets.QTreeWidgetItemIterator.IteratorFlag.All +oneFlagRefValue2 = QtWidgets.QTreeWidgetItemIterator.IteratorFlag.Hidden + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_OptimizationFlags_OptimizationFlag.py b/tests/qflags/test_QtWidgets_OptimizationFlags_OptimizationFlag.py new file mode 100644 index 00000000..735eef27 --- /dev/null +++ b/tests/qflags/test_QtWidgets_OptimizationFlags_OptimizationFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGraphicsView.OptimizationFlags" and flag class "QGraphicsView.OptimizationFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QGraphicsView.OptimizationFlag +MultiFlagClass = QtWidgets.QGraphicsView.OptimizationFlags + +oneFlagRefValue1 = QtWidgets.QGraphicsView.OptimizationFlag.DontClipPainter +oneFlagRefValue2 = QtWidgets.QGraphicsView.OptimizationFlag.DontSavePainterState + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_Options_Option.py b/tests/qflags/test_QtWidgets_Options_Option.py new file mode 100644 index 00000000..6731b740 --- /dev/null +++ b/tests/qflags/test_QtWidgets_Options_Option.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QFileSystemModel.Options" and flag class "QFileSystemModel.Option" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QFileSystemModel.Option +MultiFlagClass = QtWidgets.QFileSystemModel.Options + +oneFlagRefValue1 = QtWidgets.QFileSystemModel.Option.DontWatchForChanges +oneFlagRefValue2 = QtWidgets.QFileSystemModel.Option.DontResolveSymlinks + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_RenderFlags_RenderFlag.py b/tests/qflags/test_QtWidgets_RenderFlags_RenderFlag.py new file mode 100644 index 00000000..fa7a1921 --- /dev/null +++ b/tests/qflags/test_QtWidgets_RenderFlags_RenderFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QWidget.RenderFlags" and flag class "QWidget.RenderFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QWidget.RenderFlag +MultiFlagClass = QtWidgets.QWidget.RenderFlags + +oneFlagRefValue1 = QtWidgets.QWidget.RenderFlag.DrawWindowBackground +oneFlagRefValue2 = QtWidgets.QWidget.RenderFlag.DrawChildren + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_Result_ResultFlag.py b/tests/qflags/test_QtWidgets_Result_ResultFlag.py new file mode 100644 index 00000000..2ec56fb3 --- /dev/null +++ b/tests/qflags/test_QtWidgets_Result_ResultFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGestureRecognizer.Result" and flag class "QGestureRecognizer.ResultFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QGestureRecognizer.ResultFlag +MultiFlagClass = QtWidgets.QGestureRecognizer.Result + +oneFlagRefValue1 = QtWidgets.QGestureRecognizer.ResultFlag.Ignore +oneFlagRefValue2 = QtWidgets.QGestureRecognizer.ResultFlag.MayBeGesture + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_SceneLayers_SceneLayer.py b/tests/qflags/test_QtWidgets_SceneLayers_SceneLayer.py new file mode 100644 index 00000000..ad70e282 --- /dev/null +++ b/tests/qflags/test_QtWidgets_SceneLayers_SceneLayer.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QGraphicsScene.SceneLayers" and flag class "QGraphicsScene.SceneLayer" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QGraphicsScene.SceneLayer +MultiFlagClass = QtWidgets.QGraphicsScene.SceneLayers + +oneFlagRefValue1 = QtWidgets.QGraphicsScene.SceneLayer.ItemLayer +oneFlagRefValue2 = QtWidgets.QGraphicsScene.SceneLayer.BackgroundLayer + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_Sections_Section.py b/tests/qflags/test_QtWidgets_Sections_Section.py new file mode 100644 index 00000000..07addbb6 --- /dev/null +++ b/tests/qflags/test_QtWidgets_Sections_Section.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QDateTimeEdit.Sections" and flag class "QDateTimeEdit.Section" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QDateTimeEdit.Section +MultiFlagClass = QtWidgets.QDateTimeEdit.Sections + +oneFlagRefValue1 = QtWidgets.QDateTimeEdit.Section.NoSection +oneFlagRefValue2 = QtWidgets.QDateTimeEdit.Section.AmPmSection + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_StandardButtons_StandardButton.py b/tests/qflags/test_QtWidgets_StandardButtons_StandardButton.py new file mode 100644 index 00000000..6ef52b8b --- /dev/null +++ b/tests/qflags/test_QtWidgets_StandardButtons_StandardButton.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QMessageBox.StandardButtons" and flag class "QMessageBox.StandardButton" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QMessageBox.StandardButton +MultiFlagClass = QtWidgets.QMessageBox.StandardButtons + +oneFlagRefValue1 = QtWidgets.QMessageBox.StandardButton.NoButton +oneFlagRefValue2 = QtWidgets.QMessageBox.StandardButton.Ok + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_State_StateFlag.py b/tests/qflags/test_QtWidgets_State_StateFlag.py new file mode 100644 index 00000000..fda1de44 --- /dev/null +++ b/tests/qflags/test_QtWidgets_State_StateFlag.py @@ -0,0 +1,253 @@ +# mypy: no-warn-unreachable + +from typing import Union, TypeVar, Type +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStyle.State" and flag class "QStyle.StateFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QStyle.StateFlag +MultiFlagClass = QtWidgets.QStyle.State + +oneFlagRefValue1 = QtWidgets.QStyle.StateFlag.State_None +oneFlagRefValue2 = QtWidgets.QStyle.StateFlag.State_Enabled + +OR_CONVERTS_TO_MULTI = True +OR_INT_CONVERTS_TO_MULTI = False +INT_OR_CONVERTS_TO_MULTI = True +### End of specific part + +T = TypeVar('T') +def assert_type_of_value(expected_type: Type[T], value: T) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == expected_type + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + assert_type_of_value(OneFlagClass, oneFlagValue1) + assert_type_of_value(OneFlagClass, oneFlagValue2) + assert_type_of_value(OneFlagClass, oneFlagValueTest) + assert_type_of_value(int, intValue) + + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 33 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(33) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value(MultiFlagClass, oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value(int, oneFlagValue1 | oneFlagValue2) + + assert_type_of_value(int, ~oneFlagValue1) + assert_type_of_value(int, oneFlagValue1 & oneFlagValue2) + assert_type_of_value(int, oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value(MultiFlagClass, oneFlagValue1 | 33) + else: + assert_type_of_value(int, oneFlagValue1 | 33) + assert_type_of_value(int, oneFlagValue1 & 33) + assert_type_of_value(int, oneFlagValue1 ^ 33) + assert_type_of_value(int, oneFlagValue1 + 33) + assert_type_of_value(int, oneFlagValue1 - 33) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value(MultiFlagClass, 33 | oneFlagValue1) + else: + assert_type_of_value(int, 33 | oneFlagValue1) + assert_type_of_value(int, 33 & oneFlagValue1) + assert_type_of_value(int, 33 ^ oneFlagValue1) + assert_type_of_value(int, 33 + oneFlagValue1) + assert_type_of_value(int, 33 - oneFlagValue1) + + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value(OneFlagClass, oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + if OR_CONVERTS_TO_MULTI: + assert_type_of_value(MultiFlagClass, oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + assert_type_of_value(int, oneOrMultiFlagValueTest) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value(OneFlagClass, oneFlagOrIntValue) + oneFlagOrIntValue |= 33 + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value(MultiFlagClass, oneFlagOrIntValue) + else: + assert_type_of_value(int, oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value(OneFlagClass, oneFlagOrIntValue) + oneFlagOrIntValue &= 33 + assert_type_of_value(int, oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value(OneFlagClass, oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value(int, oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value(OneFlagClass, oneFlagOrIntValue) + oneFlagOrIntValue ^= 33 + assert_type_of_value(int, oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value(OneFlagClass, oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value(int, oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value(OneFlagClass, oneFlagValue1) + assert_type_of_value(MultiFlagClass, multiFlagValue1) + assert_type_of_value(MultiFlagClass, multiFlagValue2) + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + assert_type_of_value(int, intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value(MultiFlagClass, ~multiFlagValue1 ) + assert_type_of_value(MultiFlagClass, multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value(MultiFlagClass, multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value(MultiFlagClass, multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value(MultiFlagClass, multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value(MultiFlagClass, multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value(MultiFlagClass, multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value(MultiFlagClass, oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value(MultiFlagClass, oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value(MultiFlagClass, oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value(MultiFlagClass, multiFlagValue1 | 33) + assert_type_of_value(MultiFlagClass, multiFlagValue1 & 33) + assert_type_of_value(MultiFlagClass, multiFlagValue1 ^ 33) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value(int, intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 33 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(33) + + # assignments operations with OneFlagClass + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + + # assignments operations with int + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + multiFlagValueTest |= 33 + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + multiFlagValueTest &= 33 + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + multiFlagValueTest ^= 33 + assert_type_of_value(MultiFlagClass, multiFlagValueTest) + + #########################################################3 + # + # Exploring errors + # + #########################################################3 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 33 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 33 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 33 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 33) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 33) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 33 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 33 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 33 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 33 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_StepEnabled_StepEnabledFlag.py b/tests/qflags/test_QtWidgets_StepEnabled_StepEnabledFlag.py new file mode 100644 index 00000000..2bf3f0ad --- /dev/null +++ b/tests/qflags/test_QtWidgets_StepEnabled_StepEnabledFlag.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QAbstractSpinBox.StepEnabled" and flag class "QAbstractSpinBox.StepEnabledFlag" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QAbstractSpinBox.StepEnabledFlag +MultiFlagClass = QtWidgets.QAbstractSpinBox.StepEnabled + +oneFlagRefValue1 = QtWidgets.QAbstractSpinBox.StepEnabledFlag.StepNone +oneFlagRefValue2 = QtWidgets.QAbstractSpinBox.StepEnabledFlag.StepUpEnabled + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_SubControls_SubControl.py b/tests/qflags/test_QtWidgets_SubControls_SubControl.py new file mode 100644 index 00000000..68c62de3 --- /dev/null +++ b/tests/qflags/test_QtWidgets_SubControls_SubControl.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStyle.SubControls" and flag class "QStyle.SubControl" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QStyle.SubControl +MultiFlagClass = QtWidgets.QStyle.SubControls + +oneFlagRefValue1 = QtWidgets.QStyle.SubControl.SC_None +oneFlagRefValue2 = QtWidgets.QStyle.SubControl.SC_ScrollBarAddLine + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_SubWindowOptions_SubWindowOption.py b/tests/qflags/test_QtWidgets_SubWindowOptions_SubWindowOption.py new file mode 100644 index 00000000..becbe72c --- /dev/null +++ b/tests/qflags/test_QtWidgets_SubWindowOptions_SubWindowOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QMdiSubWindow.SubWindowOptions" and flag class "QMdiSubWindow.SubWindowOption" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QMdiSubWindow.SubWindowOption +MultiFlagClass = QtWidgets.QMdiSubWindow.SubWindowOptions + +oneFlagRefValue1 = QtWidgets.QMdiSubWindow.SubWindowOption.RubberBandResize +oneFlagRefValue2 = QtWidgets.QMdiSubWindow.SubWindowOption.RubberBandMove + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_TabFeatures_TabFeature.py b/tests/qflags/test_QtWidgets_TabFeatures_TabFeature.py new file mode 100644 index 00000000..9a206982 --- /dev/null +++ b/tests/qflags/test_QtWidgets_TabFeatures_TabFeature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStyleOptionTab.TabFeatures" and flag class "QStyleOptionTab.TabFeature" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QStyleOptionTab.TabFeature +MultiFlagClass = QtWidgets.QStyleOptionTab.TabFeatures + +oneFlagRefValue1 = QtWidgets.QStyleOptionTab.TabFeature.None_ +oneFlagRefValue2 = QtWidgets.QStyleOptionTab.TabFeature.HasFrame + +OR_CONVERTS_TO_MULTI: Literal[False] = False +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[False] = False +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_ToolBarFeatures_ToolBarFeature.py b/tests/qflags/test_QtWidgets_ToolBarFeatures_ToolBarFeature.py new file mode 100644 index 00000000..8e4b86c2 --- /dev/null +++ b/tests/qflags/test_QtWidgets_ToolBarFeatures_ToolBarFeature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStyleOptionToolBar.ToolBarFeatures" and flag class "QStyleOptionToolBar.ToolBarFeature" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QStyleOptionToolBar.ToolBarFeature +MultiFlagClass = QtWidgets.QStyleOptionToolBar.ToolBarFeatures + +oneFlagRefValue1 = QtWidgets.QStyleOptionToolBar.ToolBarFeature.None_ +oneFlagRefValue2 = QtWidgets.QStyleOptionToolBar.ToolBarFeature.Movable + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_ToolButtonFeatures_ToolButtonFeature.py b/tests/qflags/test_QtWidgets_ToolButtonFeatures_ToolButtonFeature.py new file mode 100644 index 00000000..62aa5042 --- /dev/null +++ b/tests/qflags/test_QtWidgets_ToolButtonFeatures_ToolButtonFeature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStyleOptionToolButton.ToolButtonFeatures" and flag class "QStyleOptionToolButton.ToolButtonFeature" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QStyleOptionToolButton.ToolButtonFeature +MultiFlagClass = QtWidgets.QStyleOptionToolButton.ToolButtonFeatures + +oneFlagRefValue1 = QtWidgets.QStyleOptionToolButton.ToolButtonFeature.None_ +oneFlagRefValue2 = QtWidgets.QStyleOptionToolButton.ToolButtonFeature.Arrow + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_ViewItemFeatures_ViewItemFeature.py b/tests/qflags/test_QtWidgets_ViewItemFeatures_ViewItemFeature.py new file mode 100644 index 00000000..ccf34743 --- /dev/null +++ b/tests/qflags/test_QtWidgets_ViewItemFeatures_ViewItemFeature.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QStyleOptionViewItem.ViewItemFeatures" and flag class "QStyleOptionViewItem.ViewItemFeature" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QStyleOptionViewItem.ViewItemFeature +MultiFlagClass = QtWidgets.QStyleOptionViewItem.ViewItemFeatures + +oneFlagRefValue1 = QtWidgets.QStyleOptionViewItem.ViewItemFeature.None_ +oneFlagRefValue2 = QtWidgets.QStyleOptionViewItem.ViewItemFeature.WrapText + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qflags/test_QtWidgets_WizardOptions_WizardOption.py b/tests/qflags/test_QtWidgets_WizardOptions_WizardOption.py new file mode 100644 index 00000000..a169178f --- /dev/null +++ b/tests/qflags/test_QtWidgets_WizardOptions_WizardOption.py @@ -0,0 +1,266 @@ +# mypy: no-warn-unreachable + +import sys +from typing import Union, TypeVar, Type +if sys.version_info[:2] >= (3,8): + from typing import Literal +else: + from typing_extensions import Literal +import pytest + +### Specific part +# file generated from qflags_test_template.py for QFlags class "QWizard.WizardOptions" and flag class "QWizard.WizardOption" +from PyQt5 import QtWidgets + +OneFlagClass = QtWidgets.QWizard.WizardOption +MultiFlagClass = QtWidgets.QWizard.WizardOptions + +oneFlagRefValue1 = QtWidgets.QWizard.WizardOption.IndependentPages +oneFlagRefValue2 = QtWidgets.QWizard.WizardOption.IgnoreSubTitles + +OR_CONVERTS_TO_MULTI: Literal[True] = True +OR_INT_CONVERTS_TO_MULTI: Literal[False] = False +INT_OR_CONVERTS_TO_MULTI: Literal[True] = True +### End of specific part + +def assert_type_of_value_int(value: int) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert isinstance(value, int) + +def assert_type_of_value_oneFlag(value: OneFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == OneFlagClass + +def assert_type_of_value_multiFlag(value: MultiFlagClass) -> None: + '''Raise an exception if the value is not of type expected_type''' + assert type(value) == MultiFlagClass + + + +def test_on_one_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + oneFlagValue2 = oneFlagRefValue2 + oneFlagValueTest = oneFlagValue1 # type: OneFlagClass + intValue = 0 # type: int + oneOrMultiFlagValueTest = oneFlagValue1 # type: Union[OneFlagClass, MultiFlagClass] + oneFlagOrIntValue = oneFlagValue1 # type: Union[int, OneFlagClass] + + # upcast from OneFlagClass to int + intValue = oneFlagValue1 + + # conversion also accepted + intValue = int(oneFlagValue1) + + # this is not supported type-safely for a good reason + oneFlagValueTest = 1 # type: ignore + + # correct way to do it + oneFlagValueTest = OneFlagClass(1) + oneFlagValueTest = OneFlagClass(oneFlagValue1) + + # The rules of OneFlagClass conversion defined in PyQt5 are: + # 1. | ~= with OneFlagClass return a MultiFlagClass (which is not compatible to int) + # Note that this breaks Liskov principle + # 2. everything else returns int: & ^ &= ^= + # 3. operations with int return int. + + if OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | oneFlagValue2) + else: + assert_type_of_value_int(oneFlagValue1 | oneFlagValue2) + + assert_type_of_value_int(~oneFlagValue1) + assert_type_of_value_int(oneFlagValue1 & oneFlagValue2) + assert_type_of_value_int(oneFlagValue1 ^ oneFlagValue2) + + # right operand + if OR_INT_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(oneFlagValue1 | 1) + else: + assert_type_of_value_int(oneFlagValue1 | 1) + assert_type_of_value_int(oneFlagValue1 & 1) + assert_type_of_value_int(oneFlagValue1 ^ 1) + assert_type_of_value_int(oneFlagValue1 + 1) + assert_type_of_value_int(oneFlagValue1 - 1) + + # left operand + if INT_OR_CONVERTS_TO_MULTI: + assert_type_of_value_multiFlag(1 | oneFlagValue1) + else: + assert_type_of_value_int(1 | oneFlagValue1) + assert_type_of_value_int(1 & oneFlagValue1) + assert_type_of_value_int(1 ^ oneFlagValue1) + assert_type_of_value_int(1 + oneFlagValue1) + assert_type_of_value_int(1 - oneFlagValue1) + + if OR_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= oneFlagValue2 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) # nice violation of Liskov principle here + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + if OR_INT_CONVERTS_TO_MULTI: + oneOrMultiFlagValueTest = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneOrMultiFlagValueTest) + oneOrMultiFlagValueTest |= 1 + assert_type_of_value_multiFlag(oneOrMultiFlagValueTest) + else: + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue |= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue &= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= 1 + assert_type_of_value_int(oneFlagOrIntValue) + + oneFlagOrIntValue = oneFlagValue1 # reset type and value + assert_type_of_value_oneFlag(oneFlagOrIntValue) + oneFlagOrIntValue ^= oneFlagValue2 + assert_type_of_value_int(oneFlagOrIntValue) + + + +def test_on_multi_flag_class() -> None: + oneFlagValue1 = oneFlagRefValue1 + multiFlagValue1 = MultiFlagClass() + multiFlagValue2 = MultiFlagClass() + multiFlagValueTest = multiFlagValue1 # type: MultiFlagClass + intValue = 0 + + assert_type_of_value_oneFlag(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue1) + assert_type_of_value_multiFlag(multiFlagValue2) + assert_type_of_value_multiFlag(multiFlagValueTest) + assert_type_of_value_int(intValue) + + + # MultiFlagClass may be created by combining MultiFlagClass together + assert_type_of_value_multiFlag( ~multiFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 | multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 & multiFlagValue2 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ multiFlagValue2 ) + + + # MultiFlagClass may be created by combining MultiFlagClass and OneFlagClass, left or right + assert_type_of_value_multiFlag( multiFlagValue1 | oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 & oneFlagValue1 ) + assert_type_of_value_multiFlag( multiFlagValue1 ^ oneFlagValue1 ) + + assert_type_of_value_multiFlag( oneFlagValue1 | multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 & multiFlagValue1 ) + assert_type_of_value_multiFlag( oneFlagValue1 ^ multiFlagValue1 ) + + + # MultClassFlag may be created by combining MultiFlagClass and int, right only + assert_type_of_value_multiFlag(multiFlagValue1 | 1) + assert_type_of_value_multiFlag(multiFlagValue1 & 1) + assert_type_of_value_multiFlag(multiFlagValue1 ^ 1) + + + # this is rejected by mypy and is slightly annoying: you can not pass a OneFlagClass variable to a method expecting a MultiFlagClass + # explicit typing must be used on those methods to accept both OneFlagClass and MultiFlagClass + multiFlagValueTest = oneFlagValue1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(oneFlagValue1) + assert_type_of_value_multiFlag(multiFlagValueTest) + + # this is rejected for the same reason as for OneFlagClass. + intValue = multiFlagValueTest # type: ignore + + # correct way to do it + intValue = int(multiFlagValueTest) + assert_type_of_value_int(intValue) + + # rejected by mypy rightfully + multiFlagValueTest = 1 # type: ignore + + # correct way to do it + multiFlagValueTest = MultiFlagClass(1) + + # assignments operations with OneFlagClass + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= oneFlagValue1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + # assignments operations with int + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest |= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest &= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + assert_type_of_value_multiFlag(multiFlagValueTest) + multiFlagValueTest ^= 1 + assert_type_of_value_multiFlag(multiFlagValueTest) + + #########################################################1 + # + # Exploring errors + # + #########################################################1 + + # This checks the following: + # + and - operations are not supported on MultiFlagClass + # combining int with MultiFlagClass does not work + + pytest.raises(TypeError, lambda: 1 | multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 & multiFlagValue1 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 ^ multiFlagValue1 ) # type: ignore[operator] + + pytest.raises(TypeError, lambda: multiFlagValue1 + multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - multiFlagValue2 ) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - oneFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 + 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: multiFlagValue1 - 1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: oneFlagValue1 - multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 + multiFlagValue1) # type: ignore[operator] + pytest.raises(TypeError, lambda: 1 - multiFlagValue1) # type: ignore[operator] + + def f1() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += oneFlagValue1 # type: ignore[assignment, operator] + def f2() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest += 1 # type: ignore[assignment, operator] + def f3() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= oneFlagValue1 # type: ignore[assignment, operator] + def f4() -> None: + multiFlagValueTest = MultiFlagClass() + multiFlagValueTest -= 1 # type: ignore[assignment, operator] + + pytest.raises(TypeError, f1) + pytest.raises(TypeError, f2) + pytest.raises(TypeError, f3) + pytest.raises(TypeError, f4) + diff --git a/tests/qlineedit.py b/tests/qlineedit.py new file mode 100644 index 00000000..e24bbe34 --- /dev/null +++ b/tests/qlineedit.py @@ -0,0 +1,7 @@ +"""Tests for QLineEdit.""" +from PyQt5.QtWidgets import QApplication, QLineEdit + +# test that QLineEdit.setText() accepts None as parameter +app = QApplication(['my_program', '-platform', 'offscreen']) +edit = QLineEdit() +edit.setText(None) diff --git a/tests/qsize.py b/tests/qsize.py new file mode 100644 index 00000000..4966cd97 --- /dev/null +++ b/tests/qsize.py @@ -0,0 +1,72 @@ +from PyQt5 import QtCore + +# QSize tests +qs1 = QtCore.QSize(1,2) +qs2 = QtCore.QSize(3,4) +qs3 = QtCore.QSize(5,6) + +qs3 = qs1 + qs2 +assert type(qs3) == QtCore.QSize +qs3 = qs1 - qs2 +assert type(qs3) == QtCore.QSize +qs3 += qs1 +assert type(qs3) == QtCore.QSize +qs3 -= qs2 +assert type(qs3) == QtCore.QSize + +qs3 = qs1 * 3 +assert type(qs3) == QtCore.QSize +qs3 = qs1 * 3.0 +assert type(qs3) == QtCore.QSize + +qs3 = 3 * qs1 +assert type(qs3) == QtCore.QSize +qs3 = 3.0 * qs1 +assert type(qs3) == QtCore.QSize + +qs3 = qs1 / 2.0 +assert type(qs3) == QtCore.QSize + +qs3 *= 3 +assert type(qs3) == QtCore.QSize +qs3 *= 3.0 +assert type(qs3) == QtCore.QSize + +qs3 /= 3.0 +assert type(qs3) == QtCore.QSize + + +# QSizeF tests +qsf1 = QtCore.QSizeF(1.0,2.0) +qsf2 = QtCore.QSizeF(3.0,4.0) +qsf3 = QtCore.QSizeF(5.0,6.0) + +qsf3 = qsf1 + qsf2 +assert type(qsf3) == QtCore.QSizeF +qsf3 = qsf1 - qsf2 +assert type(qsf3) == QtCore.QSizeF +qsf3 += qsf1 +assert type(qsf3) == QtCore.QSizeF +qsf3 -= qsf2 +assert type(qsf3) == QtCore.QSizeF + +qsf3 = qsf1 * 3 +assert type(qsf3) == QtCore.QSizeF +qsf3 = qsf1 * 3.0 +assert type(qsf3) == QtCore.QSizeF + +qsf3 = 3 * qsf1 +assert type(qsf3) == QtCore.QSizeF +qsf3 = 3.0 * qsf1 +assert type(qsf3) == QtCore.QSizeF + +qsf3 = qsf1 / 2.0 +assert type(qsf3) == QtCore.QSizeF + +qsf3 *= 3 +assert type(qsf3) == QtCore.QSizeF +qsf3 *= 3.0 +assert type(qsf3) == QtCore.QSizeF + +qsf3 /= 3.0 +assert type(qsf3) == QtCore.QSizeF diff --git a/tests/test_stubs.py b/tests/test_stubs.py index b56bf85b..2ed54b44 100644 --- a/tests/test_stubs.py +++ b/tests/test_stubs.py @@ -1,34 +1,59 @@ -import os.path +import os +from pathlib import Path import pytest from mypy import api -TESTS_DIR = os.path.dirname(__file__) +TESTS_DIR = Path(__file__).parent def gen_tests(): - for filename in os.listdir(TESTS_DIR): - if filename.endswith('.py') and not filename.startswith('test_'): - yield filename + """List of all tests files included in the directory tests""" + for path in TESTS_DIR.glob('*.py'): + if not path.name.startswith('test_'): + yield path +def gen_abs_qflags_tests(): + """List of all tests included in the directory qflags""" + yield from TESTS_DIR.joinpath('qflags').glob('test_*.py') -@pytest.mark.parametrize('filename', list(gen_tests())) -def test_stubs(filename): + +@pytest.mark.parametrize('filepath', + list(gen_tests()), + ids=[v.relative_to(TESTS_DIR).as_posix() for v in gen_tests()] + ) +def test_stubs(filepath: Path) -> None: """Run mypy over example files.""" - path = os.path.join(TESTS_DIR, filename) - stdout, stderr, exitcode = api.run([path]) + stdout, stderr, exitcode = api.run([os.fspath(filepath)]) + if stdout: + print(stdout) + if stderr: + print(stderr) + + assert stdout.startswith("Success: no issues found") + assert not stderr + assert exitcode == 0 + + +def test_stubs_qflags() -> None: + """Run mypy over qflags files.""" + stdout, stderr, exitcode = api.run([os.fspath(path) for path in gen_abs_qflags_tests()]) if stdout: print(stdout) + if stderr: + print(stderr) assert stdout.startswith("Success: no issues found") assert not stderr assert exitcode == 0 +# note: no need to run explicitly pytest over qflags, because pytest finds them automatically -@pytest.mark.parametrize('filename', list(gen_tests())) -def test_files(filename): +@pytest.mark.parametrize('filepath', + list(gen_tests()), + ids=[v.name for v in gen_tests()] + ) +def test_files(filepath): """Run the test files to make sure they work properly.""" - path = os.path.join(TESTS_DIR, filename) - with open(path, 'r') as f: - code = f.read() - exec(compile(code, filename, 'exec'), {}) + code = filepath.read_text(encoding='utf-8') + exec(compile(code, filepath, 'exec'), {}) diff --git a/tox.ini b/tox.ini index 5d97a76e..726866b3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,20 @@ [tox] -envlist = py3{5,6,7,8,9} +envlist = py3{6,7,8,9,10}-{windows,linux} [testenv] deps = - mypy @ git+https://github.com/python/mypy@538d36481526135c44b90383663eaa177cfc32e3 - pytest pip>=20.0 -commands = - pip install PyQt5==5.15.* PyQt3D==5.15.* PyQtChart==5.15.* PyQtDataVisualization==5.15.* PyQtNetworkAuth==5.15.* PyQtPurchasing==5.15.* PyQtWebEngine==5.15.* +setenv: + linux: OS_MARKER = linux + macos: OS_MARKER = macos + windows: OS_MARKER = windows +extras = + dev +commands = + pip install PyQt5==5.15.6 PyQt3D==5.15.5 PyQtChart==5.15.5 PyQtDataVisualization==5.15.5 PyQtNetworkAuth==5.15.5 PyQtPurchasing==5.15.5 PyQtWebEngine==5.15.5 + pip freeze --all mypy --show-error-codes -p PyQt5-stubs - stubtest --allowlist {toxinidir}/stubtest.allowlist --allowlist {toxinidir}/stubtest.allowlist.to_review PyQt5 + stubtest --allowlist {toxinidir}/stubtest.allowlist --allowlist {toxinidir}/stubtest.allowlist.to_review --allowlist {toxinidir}/stubtest.allowlist.{env:OS_MARKER} PyQt5 pytest --capture=no --verbose {posargs} [pytest]