py3.10-prep: Fix parser.py for changed typing module
authorChristian Tismer <tismer@stackless.com>
Sat, 8 May 2021 14:06:23 +0000 (16:06 +0200)
committerChristian Marillat <marillat@debian.org>
Fri, 17 Jun 2022 15:49:37 +0000 (16:49 +0100)
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.

(cherry picked from commit 2530cb3f165ac02b8f7132e3f5ab4f7f6896dbd9)

Gbp-Pq: Name py3.10-prep-Fix-parser.py-for-changed-typing-module.patch

sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py

index 20c791cc1a6c7e57762568f54bd36bdb86ffce1d..1a29df57ae761eb260182aeaf25afd094caf2b8d 100644 (file)
@@ -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