Deprecation Warning for Enum Access
See original GitHub issuePer this comment here:
starting with sip v4.19.9 (around PyQt 5.11) all enums are now scoped, and starting in PyQt6, the backwards compatibility allowing enums to be accessed in their top level namespace has been removed
This is confirmed by the PyQt5 Gotcha’s docs.
Since end users may be accessing different versions of PyQt/PySide through qtpy
, would it be possible to add a DeprecationWarning
for the corresponding versions? (most likely this could be determined at runtime via QT_API
)
e.g. I noticed a "Type[QEvent]" has no attribute "Gesture"
mypy error in legacy code where Gesture
was accessed like so:
and the fix was instead to use QtCore.QEvent.Type.Gesture
.
Perhaps something like:
DeprecationWarning: Enums are scoped beginning with PyQt 5.11 (and its corresponding PySide 2 version). Access to enums through top-level namespaces has been deprecated beginning in PyQt 6.
Use the full path to the enumeration instead. For example:
QtCore.QEvent.Type.Gesture
instead of
QtCore.QEvent.Gesture
Issue Analytics
- State:
- Created a year ago
- Comments:21 (8 by maintainers)
Top Results From Across the Web
How do I detect and invoke a function when a python enum ...
BAZ , a DeprecationWarning is issued using warnings.warn("BAZ is deprecated", DeprecationWarning) . Afterwards everything behaves normally. The ...
Read more >No warning for [[deprecated]] enum type or enum value - MSDN
Hi Visual C++ expert, According to C++ standard and this MSDN page, C++ 17 key word [[deprecated] should emit warning for enum type...
Read more >No warning for [[deprecated]] enum value in VS 2017 15.4.0
Compile the following code in Visual Studio 2017 15.4.0, there is no warning emitting for the deprecated enum value. ... E a =...
Read more >Issue 43162: Enum regression: AttributeError when accessing ...
I believe I found a regression in Enum in Python 3.10.0a5. This is Python 3.9: >>> import enum >>> class C(enum.Enum): ... A...
Read more >Enumerations - Scala 3 - EPFL
This means that enum case declarations cannot access inner members of the enum ... Pluto will produce a deprecation warning, but within those...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe we could just include a short note with a link to your aforementioned comment here, rather than pasting the whole thing there?
Typically, unless the project has relatively few or no third party deps, I typically run
mypy
(as well as Pylint and Pyanalyze) usingsystem
in alocal
hook, where I also usemypy .
as the invocation andpass_filenames: false
, which (incidentally) avoids issue (a) as well. I typically also have acheck-env-activated
custom hook that runs before it and checks if an appropriate Python environment (i.e. containing the required dependencies for the package itself and the hooks) is activated, as a quick and obvious check in case it isn’t. Here’s what the config looks like:and here’s the check_env_activated script.
Hi @adam-grant-hendry, thank you for the feedback and sharing with us the things you did to configure your setup with
qtpy
! Also thank you @CAM-Gerlach for giving guidance to @adam-grant-hendry to find the correct setup 👍Regarding the reason behind why enums where not promoted for PySide6 is basically because it was not necessary. As you guessed/checked, there is a difference between what
sip
andshiboken
enable regarding the unscoped access of enums. For the moment PyQt6 is the only binding which fully removed the unscoped access to enums. Following that, and since we try follow the modules layout available with Qt5, we decided to keep the access here by promoting the enums when using PyQt6.For more details you can check some comments like https://github.com/spyder-ide/qtpy/issues/233#issuecomment-946618277 where we discussed the unscoped vs scoped enums access.
Also, you can check the logic we are using to allow the unscoped enums access here: https://github.com/dalthviz/qtpy/blob/b02425b2f884ccefaca25d904f5d61bae14756a4/qtpy/enums_compat.py#L19-L37 (basically looping from a given module all the
sip.wrappertype
classes available and then adding the attributes/values available on their enums).If you have any other question or comment let us know!