Details
-
Suggestion
-
Resolution: Unresolved
-
P4: Low
-
None
-
6.6.2
-
None
-
VSCode + Pylance, Python 3.10, PySide 6.6
Description
Currently, using the QmlElement decorator erases type information, because it is defined to return object/Any. Users can work around this issue by wrapping the decorator with a generic function, for example:
from PySide6.QtCore import QObject from PySide6.QtQml import QmlElement @QmlElement class Erased(QObject): pass E = TypeVar("E") def TypedQmlElement(arg: E) -> E: return QmlElement(arg) @TypedQmlElement class NotErased(QObject): pass def do_something(): return Erased(), NotErased() erased, not_erased = do_something() # Pylance shows "erased: Any, not_erased: NotErased"
This is fixed either by adding the typevar to the .pyi file instead, or apparently by removing the type hints entirely:
E = TypeVar("E")
def QmlElement(arg__1: E) -> E: ...
# or
def QmlElement(arg__1): ...
Attachments
Issue Links
- duplicates
-
PYSIDE-2365 @QmlElement decorator doesn't return original type
- Closed
- is duplicated by
-
PYSIDE-2947 Type stub for QmlElement (and others) obscure decorated type from type checkers
- Closed
- relates to
-
PYSIDE-2767 MyPy/PyRight error with PySide6.QtCore.Property
- Closed
-
PYSIDE-2542 QtCore.QSettings.value should infer return type from type parameter
- Closed