question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecation Warning for Enum Access

See original GitHub issue

Per 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:

image

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:closed
  • Created a year ago
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
CAM-Gerlachcommented, Jun 30, 2022

If you could add how to configure pyright and to add to settings.json https://github.com/spyder-ide/qtpy/issues/352#issuecomment-1170684412, I think that would help future developers.

Maybe we could just include a short note with a link to your aforementioned comment here, rather than pasting the whole thing there?

  • (b) the mypy in pre-commit runs in an isolated environment, so it won’t have access to your dependencies (i.e. stub file packages) unless you specify them as dependencies (using additional_dependencies) or if you add the language: system argument to the hook.

Typically, unless the project has relatively few or no third party deps, I typically run mypy (as well as Pylint and Pyanalyze) using system in a local hook, where I also use mypy . as the invocation and pass_filenames: false, which (incidentally) avoids issue (a) as well. I typically also have a check-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:

  - id: check-env-activated
    name: Check that a suitable Python env is activated
    entry: 'python tools/check_env_activated.py'
    language: system
    types: [python]
    pass_filenames: false
  - id: mypy
    name: Lint Python with MyPy
    entry: 'mypy .'
    language: system
    types: [python]
    pass_filenames: false

and here’s the check_env_activated script.

1reaction
dalthvizcommented, Jun 30, 2022

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 and shiboken 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found