-
-
Notifications
You must be signed in to change notification settings - Fork 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
Deprecation Warning for Enum Access #352
Comments
Hey, thanks for the detailed proposal. With PR #271 , QtPy >=2.0.0 (first version supporting Qt6) supports unscoped enum access even on PyQt versions that don't support it natively, for consistency and abstraction between bindings (since PySide handles this differently). Indeed, our tests contain this assert testing that an example assert QtCore.QEvent.ActionAdded == QtCore.QEvent.Type.ActionAdded Therefore, unless I'm mistaken about what you're asking, I'm not sure there's a need for a DeprecationWarning on QtPy's side. @dalthviz , any thoughts here? |
@CAM-Gerlach Thank you for the pointing me to PR #271 . I noticed here that enums were promoted for I'm wondering because I'm using these PySide6 stubs and the (relevant part of the) implementation for from enum import IntFlag # was "from enum import Enum"
from typing import overload
import PySide6.QtCore
import shiboken6 as Shiboken
class QEvent(Shiboken.Object): # was "QEvent(object)"
None_: QEvent.Type = ...
Timer: QEvent.Type = ...
...
class Type(IntFlag): # was "Type(Enum)"
None_: QEvent.Type = ...
Timer: QEvent.Type = ...
... # same enums as in top-level
@overload
def __init__(self, arg__1: PySide6.QtCore.QEvent) -> None:
...
@overload
def __init__(self, arg__1: PySide6.QtCore.QEvent.Type) -> None:
...
... # remaining methods overloaded but I am still receiving a mypy linting error. |
+1 on that. No! I wasn't aware! I'm going to look right now. |
@CAM-Gerlach After reading the docs, I'm still a little confused. How would I use the Specifically though, I'd like it to work in VSCode. I have a Python 3.8.10 virtual environment created through I've tried this in my workspace {
"python.linting.mypyEnabled": true,
"python.linting.mypyPath": "${workspaceFolder}/.venv/Scripts/pylint.exe",
"python.linting.mypyArgs": [
"--config-file",
"mypy.ini",
"--always-true=PYSIDE6",
"--always-false=PYQT5,PYSIDE2,PYQT6"
],
"mypy.dmypyExecutable": "${workspaceFolder}/.venv/Scripts/dmypy.exe"
} and the [mypy]
disallow_untyped_defs = True |
Can the above also be given/passed to |
I can confirm (using the
as opposed to
and I know how to fix the stubs to solve the error However, I have yet to figure out a way to get this to work for |
The above is a little strange considering that the
|
I figured out the last piece of the puzzle here. I mispoke: I wasn't needing an argument for In a [tool.pyright]
defineConstant = [
{ PYSIDE6 = true },
{ PYQT5 = false },
{ PYSIDE2 = false },
{ PYQT6 = false }
] One can also define a Finally, it was important for me to ONLY have the Microsoft Python extension installed in VSCode, and not this 3rd party mypy extension. The problem with this extension is that you cannot pass extra arguments to it beyond the path to the "python.linting.mypyArgs": [
"--config-file",
"mypy.ini",
"--always-true=PYSIDE6",
"--always-false=PYQT5",
"--always-false=PYSIDE2",
"--always-false=PYQT6",
] |
Great, sorry it was so much trouble and thanks for all the info—might certainly be helpful for someone else in the future. Are there any changes you would recommend to QtPy based on this, either in the code or in the docs? If so, we'd welcome a PR, or I can try to give it a shot if you can advise me accordingly. Thanks! |
@CAM-Gerlach I'd still like to know why enums weren't promoted for PySide6. If you could have someone answer that for me, that would be great! |
Sure; @dalthviz ? |
Thank you! The code works (obviously), so I'm guessing perhaps it's something to do with the difference between the how |
Hi @adam-grant-hendry, thank you for the feedback and sharing with us the things you did to configure your setup with 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 For more details you can check some comments like #233 (comment) 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 If you have any other question or comment let us know! |
I guess the one potential concern I'd have would be if |
@CAM-Gerlach @dalthviz Thank you both SO MUCH! There was a lot of discussion here and I really appreciate all the help and explanation. This was a wonderful experience! Top marks! As a follow up to @CAM-Gerlach 's question about suggestions for the docs, only two things come to mind:
This issue post helped me understand "system" basically means rely on whatever state the user's machine is in, so you'll have to configure settings appropriately in CI vs on your system |
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 - 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 |
I have not, personally (thankfully). I was also concerned about the discrepancy across bindings and versions. As long as They would only be necessary in the individual |
Completely fine by me. However you would like to do it. You don't even have to add anything if you don't want to 😃 . And thank you for the other advice about |
@CAM-Gerlach @dalthviz Whenever you're ready, feel free to close this issue. Thank you again! |
Thanks for all your help and detailed comments! I opened PR #353 which adds such a note, and will close this issue when merged. |
Per this comment here:
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 aDeprecationWarning
for the corresponding versions? (most likely this could be determined at runtime viaQT_API
)e.g. I noticed a
"Type[QEvent]" has no attribute "Gesture"
mypy error in legacy code whereGesture
was accessed like so:and the fix was instead to use
QtCore.QEvent.Type.Gesture
.Perhaps something like:
The text was updated successfully, but these errors were encountered: