diff options
author | Christian Tismer <[email protected]> | 2021-11-19 10:35:27 +0100 |
---|---|---|
committer | Christian Tismer <[email protected]> | 2021-11-22 15:43:05 +0100 |
commit | 2149a45fddeedea317dccbfe5e5b14e13888e5c9 (patch) | |
tree | 4a1fa7832bef8225b67dc3423cc1c504b3b63c72 | |
parent | 0377d62cc71dda587b01d641bc8d13385402142c (diff) |
signature: improve error handling for embedded applications
Entering something like
"""
mainWindow.setPointer(None)
"""
crashes in an old version of scriptableapplication, which
shows an omission in the signature interface. The error
shows up whenever a builtin module cannot be imported.
The error does not show up in PySide 6, because the
module is declared as a builtin via `PyImport_AppendInittab`.
* add registration of AppLib as a builtin (5.15)
* insert builtin modules per default into the mapping module
* simple recovery if a module cannot be found in sys.modules
[ChangeLog][shiboken6] Error handling was improved for embedded
applications and builtin modules are trusted as valid modules.
Change-Id: I722212a52a5e3aae924f0b965578485ecaf185a9
Fixes: PYSIDE-1710
Pick-to: 6.2 5.15
Reviewed-by: Friedemann Kleint <[email protected]>
3 files changed, 6 insertions, 5 deletions
diff --git a/sources/shiboken6/libshiboken/signature/signature.cpp b/sources/shiboken6/libshiboken/signature/signature.cpp index b25f458f4..43145b4f2 100644 --- a/sources/shiboken6/libshiboken/signature/signature.cpp +++ b/sources/shiboken6/libshiboken/signature/signature.cpp @@ -520,9 +520,10 @@ static PyObject *adjustFuncName(const char *func_name) return nullptr; // Run `eval` on the type string to get the object. + // PYSIDE-1710: If the eval does not work, return the given string. AutoDecRef obtype(PyRun_String(_path, Py_eval_input, ns, ns)); if (obtype.isNull()) - return nullptr; + return String::fromCString(func_name); if (PyModule_Check(obtype.object())) { // This is a plain function. Return the unmangled name. diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py index 0c1b72644..4c436eafd 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py @@ -104,8 +104,8 @@ def seterror_argument(args, func_name, info): try: func = eval(func_name, namespace) except Exception as e: - msg = f"Internal error evaluating {func_name}: " + str(e) - return TypeError, msg + msg = f"Error evaluating `{func_name}`: {e}" + return type(e), msg if info and type(info) is str: err = TypeError if info == "<": diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index 434da910b..4c232a750 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -54,7 +54,7 @@ import typing from pathlib import Path from typing import TypeVar, Generic -from shibokensupport.signature.lib.tool import with_metaclass +from _imp import is_builtin class ellipsis(object): def __repr__(self): @@ -179,7 +179,7 @@ class Reloader(object): if getattr(mod, "__file__", None) and not Path(mod.__file__).is_dir(): ending = Path(mod.__file__).suffix return ending not in (".py", ".pyc", ".pyo", ".pyi") - return False + return bool(is_builtin(mod.__name__)) def update(self): """ |