diff options
| -rw-r--r-- | sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py | 24 | ||||
| -rw-r--r-- | sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py | 8 |
2 files changed, 30 insertions, 2 deletions
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py index 4ef7fb013..3de750544 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py @@ -19,6 +19,8 @@ used literally as strings like "signature", "existence", etc. """ import inspect +import sys +import types import typing from types import SimpleNamespace @@ -30,6 +32,28 @@ from shibokensupport.signature import make_snake_case_name DEFAULT_PARAM_KIND = inspect.Parameter.POSITIONAL_ONLY +def formatannotation(annotation, base_module=None): + if getattr(annotation, '__module__', None) == 'typing': + return repr(annotation).replace('typing.', '') + if isinstance(annotation, types.GenericAlias): + return str(annotation) + if isinstance(annotation, type): + if annotation.__module__ in ('builtins', base_module): + return annotation.__qualname__ + return annotation.__module__ + '.' + annotation.__qualname__ + return repr(annotation) + + +# PYSIDE-3012: Patching Python < 3.9.8 or Python < 3.10.1 +def install_typing_patch(): + v = sys.version_info[:3] + if v[1] == 9 and v[2] < 8 or v[1] == 10 and v[2] < 1: + inspect.formatannotation = formatannotation + + +install_typing_patch() + + class SignatureLayout(SimpleNamespace): """ Configure a signature. diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py index 0f582fe24..b170d63d6 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -10,6 +10,7 @@ import re import sys import typing import warnings +import abc from types import SimpleNamespace from shibokensupport.signature.mapping import (type_map, type_map_tuple, update_mapping, @@ -243,7 +244,7 @@ def get_name(thing): def _resolve_value(thing, valtype, line): if thing in ("0", "None") and valtype: - if valtype.startswith("PySide6.") or valtype.startswith("typing."): + if valtype.startswith(("PySide6.", "typing.", "collections.abc.")): return None mapped = type_map.get(valtype) # typing.Any: '_SpecialForm' object has no attribute '__name__' @@ -297,13 +298,16 @@ def to_string(thing): # so we fall back to use __name__ before the next condition. if isinstance(thing, typing.TypeVar): return get_name(thing) - if hasattr(thing, "__name__") and thing.__module__ != "typing": + if hasattr(thing, "__name__") and thing.__module__ not in ("typing", "collections.abc"): m = thing.__module__ dot = "." in str(thing) or m not in (thing.__qualname__, "builtins") name = get_name(thing) ret = m + "." + name if dot else name assert (eval(ret, globals(), namespace)) return ret + elif type(thing) is abc.ABCMeta: + # collections.abc.Sequence without argument is very different from typing. + return f"{thing.__module__}.{thing.__name__}" # Note: This captures things from the typing module: return str(thing) |
