-
Notifications
You must be signed in to change notification settings - Fork 29
Add all qflags bases classes #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
230 commits
Select commit
Hold shift + click to select a range
79a24e4
Fix WindowType and WindowFlags integer operations
bluebird75 542d527
Full testing on WindowType, WindowFlags and int combinations + correc…
bluebird75 ba5b984
Update changelog
bluebird75 b328383
Make WindowType inherit int again (revert a previous change)
bluebird75 e1c67d4
Ignore the errors reported from breaking Liskov principle
bluebird75 1ad195a
add one more test for windowFlags usage
bluebird75 aee419b
Merge remote-tracking branch 'origin/master' into fix-windowflags-win…
bluebird75 53c1105
WindowType as working cross verfication with mypy and py.test
bluebird75 eebb2cb
WindowFlags operations are verified by both mypy and pytest
bluebird75 af26357
Also test assignment operator
bluebird75 8f1d77f
Fix CI: overload not needed, breaking Liskov is OK here
bluebird75 64d3934
Fix CI
bluebird75 77af902
Make stubtest happy: there is no need for a __init__ method on int su…
bluebird75 e277af3
Fix CI: functions are not needed
bluebird75 8a93e15
Make mypy happy
bluebird75 5d76dde
work in progress on making windowFlags test generic
bluebird75 38d86c3
Make test completely generic
bluebird75 891f062
Add tests and fixes for Alignment flags
bluebird75 dcc0368
Generator for testing QFlag based classes
bluebird75 3b1fb57
concept of automating qflags validation
bluebird75 464f1d6
Sanitize input
pfremy 4c62110
Can associate a module with most QFlags
pfremy 73ce858
Look for qflags in all modules of qtbase
pfremy 4ea15c5
Merge branch 'master' into all-qflags
altendky 0585948
Update PyQt5-stubs/QtCore.pyi
bluebird75 52254c9
Remove unneeded #type: ignore and QtWidgets import to make CI happy
bluebird75 0484eaa
Merge branch 'master' into all-qflags
altendky f1f54c5
improvements
bluebird75 17e4270
Can locate QFlag into pyqt module
bluebird75 8949a28
Work in progress for testing qflags
bluebird75 cba2436
work in progress
bluebird75 40589d4
Can parse pyi and check for enum class and its methods
bluebird75 74a8066
work in progress: check for all method presence done
bluebird75 90554e8
wip: module is modified for the enum class
bluebird75 a90e5c4
wip: full code modification is working
bluebird75 7077b60
wip: move code modification back to generate_qflags_stubs_and_tests
bluebird75 1ee9864
work in progress
bluebird75 6adfdc6
Fix typo
bluebird75 4d48d55
Renaming and documentation update
bluebird75 376e8ae
work in progress
bluebird75 40cfc4a
work in progress
bluebird75 2b3818e
Now working: running this script creates one more supported QFlag
bluebird75 797d167
Add all QFlag operations to QDBusConnection.ConnectionCabability in m…
bluebird75 e518b6a
Adding all QFlag operations to QGLFormat.OpenGLVersionFlags, QGLForma…
bluebird75 d24856a
Description of how to use the generation script
bluebird75 e806c20
QFlag operations for QTextCodec.ConversionFlags, QTextCodec.Conversio…
bluebird75 b7fd9bf
More documentation and script cleaning
bluebird75 a8b4e95
Restore the module when test fail
bluebird75 5ee9320
QFlag operations for QDir.Filters, QDir.Filter in module QtCore
bluebird75 a41b9fa
QFlag operations for QDir.SortFlags, QDir.SortFlag in module QtCore
bluebird75 2c2cc63
Merge branch 'all-qflags-phil' into all-qflags
bluebird75 cb7788f
QFlag operations for QFileDevice.Permissions, QFileDevice.Permission …
bluebird75 d5717fb
QFlag operations for QItemSelectionModel.SelectionFlags, QItemSelecti…
bluebird75 e0e776d
QFlag operations for Qt.KeyboardModifiers, Qt.KeyboardModifier in mod…
bluebird75 97f0402
QFlag operations for Qt.MouseButtons, Qt.MouseButton in module QtCore
bluebird75 5ceb0ac
QFlag operations for Qt.Orientations, Qt.Orientation in module QtCore
bluebird75 9fc46ee
QFlag operations for Qt.WindowStates, Qt.WindowState in module QtCore
bluebird75 3ddf8fd
QFlag operations for Qt.ScreenOrientations, Qt.ScreenOrientation in m…
bluebird75 c7a9d64
QFlag operations for Qt.ImageConversionFlags, Qt.ImageConversionFlag …
bluebird75 f7f3a06
QFlag operations for Qt.DockWidgetAreas, Qt.DockWidgetArea in module …
bluebird75 a8ae4f7
QFlag operations for Qt.ToolBarAreas, Qt.ToolBarArea in module QtCore
bluebird75 25fbaec
QFlag operations for Qt.Edges, Qt.Edge in module QtCore
bluebird75 3d93d29
Individual qflags test files no longer needed.
bluebird75 1bbc115
Less global variables
bluebird75 fc5f576
Re-run the failing commands to capture the actual error
bluebird75 fb12a40
QFlag operations for QGLContext.BindOptions, QGLContext.BindOption in…
bluebird75 3399dbc
Add missing test file for WindowFlags / WindowType
bluebird75 fe8f92b
QFlag test files for InputMethodQuery / InputMethodQueries
bluebird75 8415cc0
QFlag operations for Qt.InputMethodHints, Qt.InputMethodHint in modul…
bluebird75 a3cf031
QFlag operations for Qt.DropActions, Qt.DropAction in module QtCore
bluebird75 8455cdc
QFlag operations for Qt.ItemFlags, Qt.ItemFlag in module QtCore
bluebird75 674a0b6
QFlag operations for Qt.MatchFlags, Qt.MatchFlag in module QtCore
bluebird75 1ff8290
More explanation about --auto-commit
bluebird75 d339eb7
Merge branch 'all-qflags-phil' into all-qflags
bluebird75 46584cd
QFlag operations for Qt.TextInteractionFlags, Qt.TextInteractionFlag …
bluebird75 5f6581c
QFlag operations for Qt.TouchPointStates, Qt.TouchPointState in modul…
bluebird75 a27a1ee
QFlag operations for Qt.GestureFlags, Qt.GestureFlag in module QtCore
bluebird75 e815ef2
QFlag operations for Qt.MouseEventFlags, Qt.MouseEventFlag in module …
bluebird75 c279682
QFlag operations for QSurfaceFormat.FormatOptions, QSurfaceFormat.For…
bluebird75 31baf20
QFlag operations for QGL.FormatOptions, QGL.FormatOption in module Qt…
bluebird75 ab68eba
Proper handling of flags in multiple modules or multiple times in the…
bluebird75 7feab15
QFlag operations for QOpenGLShader.ShaderType, QOpenGLShader.ShaderTy…
bluebird75 6464c8e
Merge branch 'all-qflags-phil' into all-qflags
bluebird75 2d5bcc3
QFlag operations for QMessageBox.StandardButtons, QMessageBox.Standar…
bluebird75 a91b59e
QFlag operations for QDirIterator.IteratorFlags, QDirIterator.Iterato…
bluebird75 4e0f0bd
QFlag operations for QTreeWidgetItemIterator.IteratorFlags, QTreeWidg…
bluebird75 5daa496
QFlag operations for Qt.Alignment, Qt.AlignmentFlag in module QtCore
bluebird75 c0aa306
QFlag operations for Qt.InputMethodQueries, Qt.InputMethodQuery in mo…
bluebird75 69355e3
QFlag operations for QEventLoop.ProcessEventsFlags, QEventLoop.Proces…
bluebird75 7832128
QFlag operations for QLibrary.LoadHints, QLibrary.LoadHint in module …
bluebird75 0634c26
QFlag operations for QOpenGLBuffer.RangeAccessFlags, QOpenGLBuffer.Ra…
bluebird75 d254fd8
QFlag operations for QOpenGLDebugMessage.Sources, QOpenGLDebugMessage…
bluebird75 d329d0b
QFlag operations for QOpenGLDebugMessage.Severities, QOpenGLDebugMess…
bluebird75 37f9a2d
QFlag operations for QMetaType.TypeFlags, QMetaType.TypeFlag in modul…
bluebird75 37c93a0
QFlag operations for QStandardPaths.LocateOptions, QStandardPaths.Loc…
bluebird75 29cb729
QFlag operations for QTextOption.Flags, QTextOption.Flag in module QtGui
bluebird75 ecd2f81
Store error on multiple lines for more readability
bluebird75 21f2ea1
QFlag operations for QCommandLineOption.Flags, QCommandLineOption.Fla…
bluebird75 b5a66c9
Fix QIODevice.OpenMode / OpenModeFlags
bluebird75 c46f7bc
QFlag operations for QHstsPolicy.PolicyFlags, QHstsPolicy.PolicyFlag …
bluebird75 eaec5a3
Prepare for variations of OR support between QFlags
bluebird75 46a090d
QFlag operations for QColorDialog.ColorDialogOptions, QColorDialog.Co…
bluebird75 a735231
QFlag operations for QFontDialog.FontDialogOptions, QFontDialog.FontD…
bluebird75 7b71654
QFlag operations for QUrl.ComponentFormattingOptions, QUrl.ComponentF…
bluebird75 8e093a7
QFlag operations for QWidget.RenderFlags, QWidget.RenderFlag in modul…
bluebird75 0638e70
QFlag operations for QTextItem.RenderFlags, QTextItem.RenderFlag in m…
bluebird75 d095a6b
QFlag operations for QPaintEngine.PaintEngineFeatures, QPaintEngine.P…
bluebird75 98e9a21
QFlag operations for QTouchDevice.Capabilities, QTouchDevice.Capabili…
bluebird75 78e89b8
QFlag operations for QOpenGLTexture.Features, QOpenGLTexture.Feature …
bluebird75 a1cb6bc
QFlag operations for QPainter.RenderHints, QPainter.RenderHint in mod…
bluebird75 75f7410
QFlag operations for QSizePolicy.ControlTypes, QSizePolicy.ControlTyp…
bluebird75 868bf4b
QFlag operations for QRawFont.LayoutFlags, QRawFont.LayoutFlag in mod…
bluebird75 b281dbf
QFlag operations for QTextDocument.FindFlags, QTextDocument.FindFlag …
bluebird75 d0ecac4
QFlag operations for QHostAddress.ConversionMode, QHostAddress.Conver…
bluebird75 a2b7825
QFlag operations for QAbstractSocket.BindMode, QAbstractSocket.BindFl…
bluebird75 a786b05
QFlag operations for QAbstractSocket.PauseModes, QAbstractSocket.Paus…
bluebird75 150e08a
QFlag operations for QTextFormat.PageBreakFlags, QTextFormat.PageBrea…
bluebird75 6bc6354
QFlag operations for QNetworkInterface.InterfaceFlags, QNetworkInterf…
bluebird75 e194110
QFlag operations for QSsl.SslOptions, QSsl.SslOption in module QtNetwork
bluebird75 01a7a1b
QFlag operations for QByteArray.Base64Options, QByteArray.Base64Optio…
bluebird75 b0013f7
QFlag operations for QLocale.NumberOptions, QLocale.NumberOption in m…
bluebird75 d3c16b7
QFlag operations for QDateTimeEdit.Sections, QDateTimeEdit.Section in…
bluebird75 757b039
QFlag operations for QRegularExpression.PatternOptions, QRegularExpre…
bluebird75 a4c8b34
QFlag operations for QRegularExpression.MatchOptions, QRegularExpress…
bluebird75 a077857
QFlag operations for QTextStream.NumberFlags, QTextStream.NumberFlag …
bluebird75 5b0194f
QFlag operations for QTextBoundaryFinder.BoundaryReasons, QTextBounda…
bluebird75 1d7381f
QFlag operations for QSql.ParamType, QSql.ParamTypeFlag in module QtSql
bluebird75 09408e3
QFlag operations for QFileDialog.Options, QFileDialog.Option in modul…
bluebird75 47576e1
QFlag operations for QFileIconProvider.Options, QFileIconProvider.Opt…
bluebird75 0e7e035
QFlag operations for QFileSystemModel.Options, QFileSystemModel.Optio…
bluebird75 b2ec7b6
QFlag operations for QGraphicsEffect.ChangeFlags, QGraphicsEffect.Cha…
bluebird75 0ca37f7
QFlag operations for QGraphicsBlurEffect.BlurHints, QGraphicsBlurEffe…
bluebird75 92a0834
QFlag operations for QInputDialog.InputDialogOptions, QInputDialog.In…
bluebird75 3fab7aa
QFlag operations for QWizard.WizardOptions, QWizard.WizardOption in m…
bluebird75 768e473
QFlag operations for QAbstractItemView.EditTriggers, QAbstractItemVie…
bluebird75 f32379d
QFlag operations for QGraphicsItem.GraphicsItemFlags, QGraphicsItem.G…
bluebird75 49e3224
QFlag operations for QGestureRecognizer.Result, QGestureRecognizer.Re…
bluebird75 3d35da7
QFlag operations for QGraphicsScene.SceneLayers, QGraphicsScene.Scene…
bluebird75 d749891
Propagate the full class names to the final output
bluebird75 f3abc3b
Merge branch 'all-qflags-phil' into all-qflags
bluebird75 637dab7
QFlag operations for QGraphicsView.OptimizationFlags, QGraphicsView.O…
bluebird75 2d113a9
QFlag operations for QStyle.SubControls, QStyle.SubControl in module …
bluebird75 55ab3a5
QFlag operations for QAbstractSpinBox.StepEnabled, QAbstractSpinBox.S…
bluebird75 12fbeee
QFlag operations for QStyleOptionFrame.FrameFeatures, QStyleOptionFra…
bluebird75 c178321
QFlag operations for QStyleOptionButton.ButtonFeatures, QStyleOptionB…
bluebird75 449ae03
QFlag operations for QStyleOptionTab.CornerWidgets, QStyleOptionTab.C…
bluebird75 27f1968
QFlag operations for QStyleOptionToolBar.ToolBarFeatures, QStyleOptio…
bluebird75 102ac89
QFlag operations for QStyleOptionViewItem.ViewItemFeatures, QStyleOpt…
bluebird75 ce9e300
QFlag operations for QStyleOptionToolButton.ToolButtonFeatures, QStyl…
bluebird75 e237a24
QFlag operations for QDockWidget.DockWidgetFeatures, QDockWidget.Dock…
bluebird75 e91147a
QFlag operations for QFontComboBox.FontFilters, QFontComboBox.FontFil…
bluebird75 4612864
QFlag operations for QMdiArea.AreaOptions, QMdiArea.AreaOption in mod…
bluebird75 6ec6572
QFlag operations for QMdiSubWindow.SubWindowOptions, QMdiSubWindow.Su…
bluebird75 28631ec
QFlag operations for QMainWindow.DockOptions, QMainWindow.DockOption …
bluebird75 3ce0e9a
QFlag operations for QTextEdit.AutoFormatting, QTextEdit.AutoFormatti…
bluebird75 2c2a42c
Display number of remaining flags to process
bluebird75 1657713
Also catch errors during transformation of the CST
bluebird75 733a933
Remove unneeded init method
bluebird75 29bb062
Merge branch 'master' into all-qflags
bluebird75 04193ae
Add mypy verifications of all qflags tests (and switch to Path API)
bluebird75 78c599c
Accelerate mypy execution by grouping all qflags test files
bluebird75 8cfe737
Merge branch 'all-qflags' of https://github.com/bluebird75/PyQt5-stub…
bluebird75 b5fd4d2
Do not run mypy on test_stubs.py but on other files.
bluebird75 50d2170
Check that qflag class inherits from sip.simplewrapper
bluebird75 c3222a5
Ensure filename part does not start with test_
bluebird75 a88673c
QFlag operations for QStyle.State, QStyle.StateFlag in module QtWidgets
bluebird75 7b0ba49
Add ability to help finding the right class
bluebird75 207b460
Add changelog entry for qflags stubs
bluebird75 ba6eb2c
Adjust template to support more QFlag implementations
bluebird75 a8ef769
Support more QFlag behaviors
bluebird75 022c977
QFlag operations for QImageIOHandler.Transformations, QImageIOHandler…
bluebird75 bb7359c
QFlag operations for QTouchEvent.TouchPoint.InfoFlags, QTouchEvent.To…
bluebird75 6d88158
Generates test file and method according to QFlag behavior
bluebird75 4f31854
QFlag operations for QNetworkProxy.Capabilities, QNetworkProxy.Capabi…
bluebird75 50247b1
QFlag operations for QDBusConnection.RegisterOptions, QDBusConnection…
bluebird75 d88f8c7
QFlag operations for QDBusServiceWatcher.WatchMode, QDBusServiceWatch…
bluebird75 c54b8a1
QFlag operations for QFileDevice.FileHandleFlags, QFileDevice.FileHan…
bluebird75 169c3ff
QFlag operations for Qt.ApplicationStates, Qt.ApplicationState in mod…
bluebird75 7d5b471
QFlag operations for Qt.FindChildOptions, Qt.FindChildOption in modul…
bluebird75 9867de5
QFlag operations for QUrl.UserInputResolutionOptions, QUrl.UserInputR…
bluebird75 f18082c
QFlag operations for QNetworkConfiguration.StateFlags, QNetworkConfig…
bluebird75 fae94de
QFlag operations for QNetworkSession.UsagePolicies, QNetworkSession.U…
bluebird75 037ed19
QFlag operations for QPaintEngine.DirtyFlags, QPaintEngine.DirtyFlag …
bluebird75 0eab567
QFlag operations for QPainter.PixmapFragmentHints, QPainter.PixmapFra…
bluebird75 df0d117
QFlag operations for QGlyphRun.GlyphRunFlags, QGlyphRun.GlyphRunFlag …
bluebird75 fb6ac6f
QFlag operations for QTextDocument.MarkdownFeatures, QTextDocument.Ma…
bluebird75 2baa9c7
QFlag operations for QLocale.DataSizeFormats, QLocale.DataSizeFormat …
bluebird75 5a34c9b
QFlag operations for QAbstractPrintDialog.PrintDialogOptions, QAbstra…
bluebird75 b0ca33b
QFlag operations for QPinchGesture.ChangeFlags, QPinchGesture.ChangeF…
bluebird75 953fe00
QFlag operations for QStyleOptionTab.TabFeatures, QStyleOptionTab.Tab…
bluebird75 59bca99
Fix dataclass incorrectly declared
bluebird75 dd2e406
wip: test file regeneration
bluebird75 0c805f3
QFlag operations for QDialogButtonBox.StandardButtons, QDialogButtonB…
bluebird75 b2512c7
Use a low value 1 for testing QFlag conversion from value
bluebird75 6e78b72
Result of processing the grep results. Basis for processing flags.
bluebird75 e482758
Regenerate grep results
bluebird75 1cabba9
Fix and improve grep results analysis
bluebird75 b69eba6
Better handling of missing expected attributes in classes
bluebird75 bc1ce9a
Improved grep results
bluebird75 9484b71
Fix typo
bluebird75 d8116ea
QFlag operations for QOpenGLDebugMessage.Types, QOpenGLDebugMessage.T…
bluebird75 93b8ff7
QFlag operations for QLocalServer.SocketOptions, QLocalServer.SocketO…
bluebird75 6c64e76
QFlag operations for QGraphicsView.CacheMode, QGraphicsView.CacheMode…
bluebird75 e0f4ac1
QFlag operations for QUrl.FormattingOptions, QUrl.UrlFormattingOption…
bluebird75 b622b9f
Add qflag support for CheckIndexOption in QtCore
bluebird75 f60e5d1
README clarifications
bluebird75 8518722
Add result of our processing for history archiving
bluebird75 93b2fe0
Message when we are finished
bluebird75 d2b14c9
QFlag operations for QAbstractItemModel.CheckIndexOptions, QAbstractI…
bluebird75 1df6e54
Notify when everything is finished.
bluebird75 9169b50
Merge remote-tracking branch 'bluebird75/patch-2' into all-qflags-phil
bluebird75 cab1654
Merge branch 'all-qflags-phil' into all-qflags
bluebird75 50f769f
Add proper type: ignore[override] where needed
bluebird75 6223e88
Remove __or__ and __ror__ for enum class
bluebird75 b3cebd5
Remove __or__ and __ror__ where int base class already does the job.
bluebird75 5d2e242
Tell mypy to ignore unreachable code.
bluebird75 82b4a78
Int compatible enum do not need any changes.
bluebird75 79b9c36
Prevent mypy from reporting unreachable code (by design)
bluebird75 49c24d6
Regnerate test files to support Python 3.6 - 3.10
bluebird75 3bf959c
Regnerate test files to support Python 3.6 - 3.10
bluebird75 4e38eeb
Merge branch 'master' into all-qflags
bluebird75 5146d68
Update tests/test_stubs.py
bluebird75 e048028
Use triple quotes for docstrings
bluebird75 c086de2
Update tests/test_stubs.py
bluebird75 f93442b
Update tests/test_stubs.py
bluebird75 3d24115
Update tests/test_stubs.py
bluebird75 f53eb62
Use os.fspath instead of str()
bluebird75 7a41588
Typo
bluebird75 8234819
Improve style: use """ instead of ''', better use of Path, ...
bluebird75 52f70a9
Merge remote-tracking branch 'bluebird75/all-qflags' into all-qflags
bluebird75 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from typing import Tuple, List | ||
|
|
||
| SOURCE = 'windowFlags.py' | ||
| MARKER_SPECIFIC_START = '### Specific part' | ||
| MARKER_SPECIFIC_END = '### End of specific part' | ||
|
|
||
| # Content is: | ||
| # - name of the file to generate | ||
| # - name of the QFlags<> class | ||
| # - name of the individual flag class (inheriting from int) | ||
| # - one individual flag value | ||
| # - a second individual flag value | ||
| FLAGS_FILES = [ | ||
| ('qflags_alignmentflags.py', 'QtCore.Qt.Alignment', 'QtCore.Qt.AlignmentFlag', 'QtCore.Qt.AlignLeft', 'QtCore.Qt.AlignRight'), | ||
|
|
||
| ] | ||
|
bluebird75 marked this conversation as resolved.
Outdated
|
||
|
|
||
| # global values for simplicity of the code | ||
| sourcePart1, sourcePart2, sourcePart3 = [], [], [] # type: Tuple[List[str], List[str], List[str]] | ||
|
bluebird75 marked this conversation as resolved.
Outdated
|
||
|
|
||
| def generate_qflags_files() -> None: | ||
| global sourcePart1, sourcePart2, sourcePart3 | ||
| with open(SOURCE) as f: | ||
| lines = f.readlines() | ||
|
|
||
| sourcePart1, sourcePart2, sourcePart3 = [], [], [] | ||
| fillPart2, fillPart3 = False, False | ||
| for l in lines: | ||
| if fillPart3: | ||
| sourcePart3.append(l) | ||
| continue | ||
|
|
||
| if fillPart2: | ||
| if MARKER_SPECIFIC_END in l: | ||
| fillPart3 = True | ||
| sourcePart3.append(l) | ||
| continue | ||
|
|
||
| sourcePart2.append(l) | ||
| continue | ||
|
|
||
| sourcePart1.append(l) | ||
| if MARKER_SPECIFIC_START in l: | ||
| fillPart2 = True | ||
|
|
||
| for qflag_info in FLAGS_FILES: | ||
| generate_one_qflag_file(*qflag_info) | ||
|
|
||
|
|
||
| def generate_one_qflag_file(qflag_fname: str, multiFlagName: str, oneFlagName: str, oneFlagValue1: str, oneFlagValue2: str) -> None: | ||
| with open(qflag_fname, 'w') as f: | ||
| f.writelines(sourcePart1) | ||
| f.write('''# file generated from {source} for QFlags class "{multiFlagName}" and flag class "{oneFlagName}" | ||
|
|
||
| OneFlagClass = {oneFlagName} | ||
| MultiFlagClass = {multiFlagName} | ||
|
|
||
| oneFlagRefValue1 = {oneFlagValue1} | ||
| oneFlagRefValue2 = {oneFlagValue2} | ||
| '''.format(source=SOURCE, multiFlagName=multiFlagName, oneFlagName=oneFlagName, | ||
| oneFlagValue1=oneFlagValue1, oneFlagValue2=oneFlagValue2 | ||
| )) | ||
| f.writelines(sourcePart3) | ||
| print('File %s generated' % qflag_fname) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| generate_qflags_files() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| from typing import Union, TypeVar, Type | ||
| import pytest # type: ignore | ||
| from PyQt5 import QtCore, QtWidgets | ||
|
|
||
| ### Specific part | ||
| # file generated from windowFlags.py for QFlags class "QtCore.Qt.Alignment" and flag class "QtCore.Qt.AlignmentFlag" | ||
|
|
||
| OneFlagClass = QtCore.Qt.AlignmentFlag | ||
| MultiFlagClass = QtCore.Qt.Alignment | ||
|
|
||
| oneFlagRefValue1 = QtCore.Qt.AlignLeft | ||
| oneFlagRefValue2 = QtCore.Qt.AlignRight | ||
| ### 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. | ||
|
|
||
| assert_type_of_value(MultiFlagClass, oneFlagValue1 | oneFlagValue2) | ||
| assert_type_of_value(int, ~oneFlagValue1) | ||
| assert_type_of_value(int, oneFlagValue1 & oneFlagValue2) | ||
| assert_type_of_value(int, oneFlagValue1 ^ oneFlagValue2) | ||
|
|
||
| # right operand | ||
| 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 | ||
| assert_type_of_value(MultiFlagClass, 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 | ||
| assert_type_of_value(MultiFlagClass, oneOrMultiFlagValueTest) # nice violation of Liskov principle here | ||
|
|
||
| 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 &= 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) | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.