Skip to content

Deprecation Warning for Enum Access #352

@adam-grant-hendry

Description

@adam-grant-hendry

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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions