aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-05-08 16:06:23 +0200
committerCristián Maureira-Fredes <cristian.maureira-fredes@qt.io>2022-01-07 14:07:38 +0100
commit4792fd22a38f2f2c0c97ff7b3aadf8c4cf8bc2fd (patch)
tree4795819b47cd5d6a00d9f8db877ea245c9df5fd9
parent91a222c3cac542e2acdf9709ea80c5ed8ab73619 (diff)
py3.10-prep: Fix parser.py for changed typing module
The typing module has subtle changes that are not even documented: Typing types now have a __name__ attribute. That confused the parser of the pyi generator because suddenly stingizing Callable[..., Optional[str]] resulted in Callable[..., Optional] because of special rules that return the generic name of a typing type, which was very unexpected. Finding this bug took a lot of debugging of the recursive `_resolve_type` function. We finally move the debugging_aid string as a function into lib/tool.py, because this was very helpful. [ChangeLog][shiboken6] The parser for .pyi files needed an update because of undocumented changes in typing.py for Python 3.10 . Task-number: PYSIDE-1436 Change-Id: I3b8f2c1aa52a23014a8a915a0c677af96dfc536f Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 2530cb3f165ac02b8f7132e3f5ab4f7f6896dbd9) Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py8
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py15
2 files changed, 11 insertions, 12 deletions
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py
index 24e75e42c..c8dbd51cc 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/tool.py
@@ -47,6 +47,7 @@ On the function with_metaclass see the answer from Martijn Pieters on
https://stackoverflow.com/questions/18513821/python-metaclass-understanding-the-with-metaclass
"""
+from inspect import currentframe
from textwrap import dedent
@@ -151,4 +152,11 @@ def with_metaclass(meta, *bases):
return meta.__prepare__(name, bases)
return type.__new__(metaclass, 'temporary_class', (), {})
+
+# A handy tool that shows the current line number and indents.
+def lno(level):
+ lineno = currentframe().f_back.f_lineno
+ spaces = level * " "
+ return "{}{}".format(lineno, spaces)
+
# eof
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
index 20c791cc1..7200dc270 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
@@ -43,10 +43,11 @@ import sys
import re
import warnings
import types
+import typing
import keyword
import functools
from shibokensupport.signature.mapping import (type_map, update_mapping,
- namespace, typing, _NotCalled, ResultVariable, ArrayLikeVariable)
+ namespace, _NotCalled, ResultVariable, ArrayLikeVariable)
from shibokensupport.signature.lib.tool import (SimpleNamespace,
build_brace_pattern)
@@ -222,7 +223,7 @@ def _resolve_arraytype(thing, line):
def to_string(thing):
if isinstance(thing, str):
return thing
- if hasattr(thing, "__name__"):
+ if hasattr(thing, "__name__") and thing.__module__ != "typing":
dot = "." in str(thing)
name = get_name(thing)
return thing.__module__ + "." + name if dot else name
@@ -239,16 +240,6 @@ def handle_matrix(arg):
return eval(result, namespace)
-debugging_aid = """
-from inspect import currentframe
-
-def lno(level):
- lineno = currentframe().f_back.f_lineno
- spaces = level * " "
- return "{lineno}{spaces}".format(**locals())
-"""
-
-
def _resolve_type(thing, line, level, var_handler):
# Capture total replacements, first. Happens in
# "PySide2.QtCore.QCborStreamReader.StringResult[PySide2.QtCore.QByteArray]"