aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/shibokenmodule/support/signature/loader.py
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2019-02-01 11:12:43 +0100
committerChristian Tismer <tismer@stackless.com>2019-02-05 14:17:48 +0000
commit3748e8fa9830e97466f12104501d4acf104260a5 (patch)
tree67dc037767dce0f87568b4a27beac69010742026 /sources/shiboken2/shibokenmodule/support/signature/loader.py
parent295061d00be3dedf60d8adc97bd14ff46931ef4c (diff)
Type Hints: Handle Container Types Correctly
An error was reported that we had a bug in this .pyi line: def parseErrors(self) -> PySide2.QtScxml.QScxmlError: ... which actually had to be a list like def parseErrors(self) -> typing.List[PySide2.QtScxml.QScxmlError]: ... A deeper look revealed that we had very many other examples, also in the argument lists, were we did not handle containers properly. (For example, 90 times in QtCore!) This is a leftover from the type error messages which were generated in C++, and never really understood. This is now a clean rewrite of the C++ part to expose all information and an extension of the Python parser that systematically uses the container types from the typing module. The implementation became a bit more complex because of Python 2: We need to provide our own copy of the public typing module, because it is not safe to assume that this module can be loaded. Importing it from support.signature gave a problem because we now need to find the names of instances to produce List[...], which needed to be implemented in the loader. Implemented the "Pair" type now as a native generic type. This is more correct than the former implementation and shorter in the .pyi files. Additionally, an own definition of "Char" was provided for brevity. This was not important to implement and could also be done with "int", but it is helpful for the future to know how to implement own types (and it was fun). Task-number: PYSIDE-921 Task-number: PYSIDE-795 Change-Id: I0e565b38d7b4fff39dd606950f9f8d97c45acbf5 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/shibokenmodule/support/signature/loader.py')
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/loader.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/sources/shiboken2/shibokenmodule/support/signature/loader.py b/sources/shiboken2/shibokenmodule/support/signature/loader.py
index 8c7739d9a..40ad95bdd 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/loader.py
+++ b/sources/shiboken2/shibokenmodule/support/signature/loader.py
@@ -148,6 +148,15 @@ with ensure_import_support():
namespace = inspect.__dict__
from support.signature import typing27 as typing
typing.__name__ = "typing"
+ # Fix the module names in typing if possible. This is important since
+ # the typing names should be I/O compatible, so that typing.Dict
+ # shows itself as "typing.Dict".
+ for name, obj in typing.__dict__.items():
+ if hasattr(obj, "__module__"):
+ try:
+ obj.__module__ = "typing"
+ except (TypeError, AttributeError):
+ pass
from support.signature import backport_inspect as inspect
_doc = inspect.__doc__
inspect.__dict__.update(namespace)