diff options
| author | Christian Tismer <tismer@stackless.com> | 2024-11-10 16:58:09 +0100 |
|---|---|---|
| committer | Christian Tismer <tismer@stackless.com> | 2024-11-11 12:51:32 +0100 |
| commit | db81f0cb861bec320104e2ec4b312d973e0700fa (patch) | |
| tree | 67970f4493f1b591ffacd8a3eb2bf43a4e73e827 | |
| parent | 1ef1fefc26038a80ba81a860cff5024db44dca37 (diff) | |
type hints: Fix some return annotations which should be optional
Some signatures should return optional which are marked
as such, others are not marked at all.
Maintain a set of functions with missing Optional[result]
signature.
Change-Id: Ia27f07cf295bc216c3545ed6f735983cf7324317
Fixes: PYSIDE-2440
Task-number: PYSIDE-2846
Pick-to: 6.8
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
3 files changed, 42 insertions, 8 deletions
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py index 9318b78ae..ae6207bf5 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py @@ -23,7 +23,7 @@ import typing from types import SimpleNamespace from textwrap import dedent -from shibokensupport.signature.mapping import ellipsis +from shibokensupport.signature.mapping import ellipsis, missing_optional_return class SignatureLayout(SimpleNamespace): @@ -355,8 +355,11 @@ def create_signature(props, key): params.append(param) if kind == _VAR_POSITIONAL: kind = _KEYWORD_ONLY + ret_anno = annotations.get('return', _empty) + if ret_anno is not _empty and props["fullname"] in missing_optional_return: + ret_anno = typing.Optional[ret_anno] sig = inspect.Signature(params, - return_annotation=annotations.get('return', _empty), + return_annotation=ret_anno, __validate_parameters__=False) # the special case of nameless parameters diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index 95245b8af..8e12cc907 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -91,12 +91,7 @@ class _NotCalled(str): return eval(text, namespace) -USE_PEP563 = False -# Note: we cannot know if this feature has been imported. -# Otherwise it would be "sys.version_info[:2] >= (3, 7)". -# We *can* eventually inspect sys.modules and look if -# the calling module has this future statement set, -# but should we do that? +USE_PEP563 = sys.version_info[:2] >= (3, 10) # Some types are abstract. They just show their name. @@ -734,4 +729,39 @@ def init_testbinding(): }) return locals() + +# Functions which should return Optional(result) but don't. +missing_optional_return = { + "PySide6.QtWidgets.QApplication.activeModalWidget", + "PySide6.QtWidgets.QApplication.activePopupWidget", + "PySide6.QtWidgets.QApplication.activeWindow", + "PySide6.QtWidgets.QApplication.focusWidget", + "PySide6.QtWidgets.QApplication.setStyle", + "PySide6.QtWidgets.QApplication.topLevelAt", + "PySide6.QtWidgets.QApplication.widgetAt", + "PySide6.QtWidgets.QComboBox.completer", + "PySide6.QtWidgets.QComboBox.lineEdit", + "PySide6.QtWidgets.QComboBox.validator", + "PySide6.QtWidgets.QGridLayout.itemAt", + "PySide6.QtWidgets.QGridLayout.itemAtPosition", + "PySide6.QtWidgets.QLayout.itemAt", + "PySide6.QtWidgets.QTableWidget.horizontalHeaderItem", + "PySide6.QtWidgets.QTableWidget.item", + "PySide6.QtWidgets.QTableWidget.itemAt", + "PySide6.QtWidgets.QTableWidget.mimeData", + "PySide6.QtWidgets.QWidget.childAt", + "PySide6.QtWidgets.QWidget.find", + "PySide6.QtWidgets.QWidget.focusProxy", + "PySide6.QtWidgets.QWidget.graphicsEffect", + "PySide6.QtWidgets.QWidget.graphicsProxyWidget", + "PySide6.QtWidgets.QWidget.keyboardGrabber", + "PySide6.QtWidgets.QWidget.layout", + "PySide6.QtWidgets.QWidget.mouseGrabber", + "PySide6.QtWidgets.QWidget.nativeParentWidget", + "PySide6.QtWidgets.QWidget.nextInFocusChain", + "PySide6.QtWidgets.QWidget.parentWidget", + "PySide6.QtWidgets.QWidget.previousInFocusChain", + "PySide6.QtWidgets.QWidget.window", +} + # end of file diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py index 1b2562c42..490b8a6ec 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -456,6 +456,7 @@ def calculate_props(line): funcname = parsed.funcname shortname = funcname[funcname.rindex(".") + 1:] props.name = shortname + props.fullname = funcname props.multi = parsed.multi fix_variables(props, line) return vars(props) |
