-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
BUG: upgrade 1.1.392
-> 1.1.393
: can not resolve @overload
__init__()
#9784
Comments
Could you please provide a more complete example? The code above contains a bunch of symbols that are not defined or imported. I don't know which library (or library version) these come from. Pyright 1.1.393 includes some changes to the overload call evaluation logic, which is probably the explanation for the change in behavior that you're seeing. We're working to standardize the behavior for calls to overloaded functions, and the latest version of pyright follows (or at least attempts to follow) the latest draft spec in this regard. |
Thank you for looking into this. Here is a more complete example: from typing import TypeAlias
from PySide6 import QtCore
from PySide6 import QtGui
from PySide6.QtGui import QKeySequence
PressEntry_QT: TypeAlias = (
QKeySequence | QKeySequence.StandardKey | QtCore.QKeyCombination | str | int
)
class AnyKeyNav_QT:
@classmethod
def render_press_entry_QT(cls, press_entry: PressEntry_QT) -> str:
press_keyseq = QKeySequence(press_entry)
press_render = press_keyseq.toString(QKeySequence.SequenceFormat.NativeText)
return press_render
@classmethod
def render_press_event_QT(cls, press_event: QtGui.QKeyEvent) -> str:
press_render = cls.render_press_entry_QT(press_event.key())
return press_render with error output report in version XXX/src/pyright_9784.py
XXX/src/pyright_9784.py:17:24 - error: No overloads for "__init__" match the provided arguments (reportCallIssue)
XXX/src/pyright_9784.py:17:37 - error: Argument of type "PressEntry_QT" cannot be assigned to parameter "k1" of type "int" in function "__init__"
Type "PressEntry_QT" is not assignable to type "int"
"QKeyCombination" is not assignable to "int" (reportArgumentType)
2 errors, 0 warnings, 0 informations where line press_keyseq = QKeySequence(press_entry) and [tool.pyright]
verboseOutput = true
pythonVersion = "3.12"
venv = ".venv"
venvPath = "."
include = [
"src/**/*.py",
]
exclude = [
"**/fc_lib/vendor/**",
]
reportUnusedImport = true
reportMissingImports = true
reportSelfClsParameterName = false
# https://github.com/spyder-ide/qtpy
[tool.pyright.defineConstant]
DEBUG = true
PYQT5 = false
PYQT6 = false
PYSIDE2 = false
PYSIDE6 = true The with /usr/lib/python3.13/site-packages/PySide6/QtGui.pyi
/usr/lib/python3.13/site-packages/PySide6/QtCore.pyi which could be downloaded and extracted from |
Thanks for the additional details. I'm able to repro the problem, and on first analysis it does appear to be a bug. I'll investigate further. |
Here's what's going on here. The typing spec update proposes that type checkers should perform "type expansion" for arguments whose types include enums when evaluating the type of a call to an overloaded function. An enum is equivalent to a union of its constituent literal members. The updated spec also notes that argument type expansion can result in unions with a large number of subtypes, and type checkers may choose to limit this to some reasonable number for performance reasons. Pyright's internal limit is currently 64. In your code sample, the type I'll need to think about how best to handle this. I may need to do "progressive expansion" (first expanding unions, then expanding enums, tuples, etc.). This would complicate an already-complicated algorithm. I may also need to increase the internal limit from 64 to some larger number, but that won't fully address this problem. @carljm, @JelleZijlstra just FYI... This raises an interesting point about the current draft update to the typing spec that I hadn't considered when I wrote the proposal. |
I think progressive expansion makes sense conceptually, but I don't think we need to spell that out in the typing check; it can just be a part of how type checkers implement this limit. |
I agree with @JelleZijlstra ; I think the proposed spec has enough detail on the conceptually correct algorithm. Progressive expansion seems like part of implementing performance-based limits on that algorithm (if there's no limit specified in the spec / in principle, there's also no need for progressive expansion); that seems like it can be left up to individual type checkers as an implementation question. |
RE: pyright doesn't perform any expansion: |
…ing a call expression that targets an overloaded method and one of the arguments is an enum with more than 64 members. This addresses #9784.
This is addressed in pyright 1.1.394. |
This now works in |
The
PySide6
library : https://pypi.org/project/PySide6/6.8.1.1/Comes with the following
@overload
__init__()
definitions in.../PySide6/QtGui.pyi
:The following user code:
is working fine with
1.1.392
, but results in error with1.1.393
:The text was updated successfully, but these errors were encountered: