aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2020-04-19 16:46:18 +0200
committerChristian Tismer <tismer@stackless.com>2020-04-21 13:20:45 +0200
commit205f77e056cc1bf0b48ac334fb106c1490d84f77 (patch)
treeb20c75523a1976985ee061c1cc52b0e680f441a4 /sources
parentb0bfeaf894344e31b5175dbbd3ce371fae5dee5b (diff)
signature: Fix and simplify for mypy compatibility
There was a problem with the typing module for Python2 that showed the wrong name. The generated signature files are further simplified. They no longer contain fancy definitions like "Char", which made little sense and was replaced by "int", which our competitor does as well. The mypy compatibility should be considered mostly complete. Update.. QChar was not changed to "int" but "str" because we got clashes. Therefore, recreation of the registry was necessary. Hard to solve stay the definitions "Virtual, Missing, Invalid, Default, Instance". They are very rarely used for special cases. Mypy cannot see these definitions since the module path does not exist in the file system. I tried hard to fix this by building a mypy plugin, but I seem to be forced to generate real files in a temp dir. This was too much effort. A plugin may make sense in the future when we need to improve the type support. Change-Id: Id80c2da1a4a379a80ec5f3019a916a9c00cc87ff Task-number: PYSIDE-1100 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside2/PySide2/support/generate_pyi.py1
-rw-r--r--sources/pyside2/tests/registry/exists_darwin_5_14_0_ci.py1
-rw-r--r--sources/pyside2/tests/registry/exists_red_hat_enterprise_linux_workstation7_6_5_14_0_ci.py1
-rw-r--r--sources/pyside2/tests/registry/exists_win32_5_14_0_ci.py1
-rw-r--r--sources/pyside2/tests/registry/exists_x86_64_suse_linux_5_14_0_ci.py1
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py6
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py55
7 files changed, 16 insertions, 50 deletions
diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py
index f173ec2fc..f92367c82 100644
--- a/sources/pyside2/PySide2/support/generate_pyi.py
+++ b/sources/pyside2/PySide2/support/generate_pyi.py
@@ -142,7 +142,6 @@ class Formatter(Writer):
self.print(" import typing")
self.print("except ImportError:")
self.print(" from PySide2.support.signature import typing")
- self.print("from PySide2.support.signature import typing")
self.print("from PySide2.support.signature.mapping import (")
self.print(" Virtual, Missing, Invalid, Default, Instance)")
self.print()
diff --git a/sources/pyside2/tests/registry/exists_darwin_5_14_0_ci.py b/sources/pyside2/tests/registry/exists_darwin_5_14_0_ci.py
index 98ec8fcbc..82295c216 100644
--- a/sources/pyside2/tests/registry/exists_darwin_5_14_0_ci.py
+++ b/sources/pyside2/tests/registry/exists_darwin_5_14_0_ci.py
@@ -1,3 +1,4 @@
+recreate
#############################################################################
##
## Copyright (C) 2018 The Qt Company Ltd.
diff --git a/sources/pyside2/tests/registry/exists_red_hat_enterprise_linux_workstation7_6_5_14_0_ci.py b/sources/pyside2/tests/registry/exists_red_hat_enterprise_linux_workstation7_6_5_14_0_ci.py
index e19f8a27c..1a7266b36 100644
--- a/sources/pyside2/tests/registry/exists_red_hat_enterprise_linux_workstation7_6_5_14_0_ci.py
+++ b/sources/pyside2/tests/registry/exists_red_hat_enterprise_linux_workstation7_6_5_14_0_ci.py
@@ -1,3 +1,4 @@
+recreate
#############################################################################
##
## Copyright (C) 2018 The Qt Company Ltd.
diff --git a/sources/pyside2/tests/registry/exists_win32_5_14_0_ci.py b/sources/pyside2/tests/registry/exists_win32_5_14_0_ci.py
index 575236710..7b360284d 100644
--- a/sources/pyside2/tests/registry/exists_win32_5_14_0_ci.py
+++ b/sources/pyside2/tests/registry/exists_win32_5_14_0_ci.py
@@ -1,3 +1,4 @@
+recreate
#############################################################################
##
## Copyright (C) 2018 The Qt Company Ltd.
diff --git a/sources/pyside2/tests/registry/exists_x86_64_suse_linux_5_14_0_ci.py b/sources/pyside2/tests/registry/exists_x86_64_suse_linux_5_14_0_ci.py
index 2bacf6ae7..5fbe713e7 100644
--- a/sources/pyside2/tests/registry/exists_x86_64_suse_linux_5_14_0_ci.py
+++ b/sources/pyside2/tests/registry/exists_x86_64_suse_linux_5_14_0_ci.py
@@ -1,3 +1,4 @@
+recreate
#############################################################################
##
## Copyright (C) 2018 The Qt Company Ltd.
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py
index a0367883a..6564786b9 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py
@@ -152,10 +152,12 @@ if sys.version_info >= (3,):
import inspect
inspect.formatannotation = formatannotation
else:
- if "typing" not in sys.modules:
+ tp_name = "typing"
+ if tp_name not in sys.modules:
orig_typing = False
from shibokensupport import typing27 as typing
- sys.modules["typing"] = typing
+ sys.modules[tp_name] = typing
+ typing.__name__ = tp_name
else:
import typing
import inspect
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
index 0767e8fd4..0571b11bd 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
@@ -73,45 +73,6 @@ NoneType = type(None)
_S = TypeVar("_S")
-# Building our own Char type, which is much nicer than
-# Char = typing.Union[str, int] # how do I model the limitation to 1 char?
-
-class _CharMeta(type):
- def __repr__(self):
- return '%s.%s' % (self.__module__, self.__name__)
-
-
-class Char(with_metaclass(_CharMeta)):
- """
- From http://doc.qt.io/qt-5/qchar.html :
-
- In Qt, Unicode characters are 16-bit entities without any markup or
- structure. This class represents such an entity. It is lightweight,
- so it can be used everywhere. Most compilers treat it like an
- unsigned short.
-
- Here, we provide a simple implementation just to avoid long aliases.
- """
- __module__ = "typing"
-
- def __init__(self, code):
- if isinstance(code, int):
- self.code = code & 0xffff
- else:
- self.code = ord(code)
-
- def __add__(self, other):
- return chr(self.code) + other
-
- def __radd__(self, other):
- return other + chr(self.code)
-
- def __repr__(self):
- return "typing.Char({})".format(self.code)
-
-typing.Char = Char
-
-
MultiMap = typing.DefaultDict[str, typing.List[str]]
# ulong_max is only 32 bit on windows.
@@ -266,7 +227,7 @@ namespace = globals() # our module's __dict__
type_map.update({
"...": ellipsis,
"bool": bool,
- "char": Char,
+ "char": int,
"char*": str,
"char*const": str,
"double": float,
@@ -278,7 +239,7 @@ type_map.update({
"PyObject": object,
"PySequence": typing.Iterable, # important for numpy
"PyTypeObject": type,
- "QChar": Char,
+ "QChar": str,
"QHash": typing.Dict,
"qint16": int,
"qint32": int,
@@ -305,7 +266,7 @@ type_map.update({
"QVector": typing.List,
"real": float,
"short": int,
- "signed char": Char,
+ "signed char": int,
"signed long": int,
"std.list": typing.List,
"std.map": typing.Dict,
@@ -314,12 +275,12 @@ type_map.update({
"str": str,
"true": True,
"Tuple": typing.Tuple,
- "uchar": Char,
+ "uchar": int,
"uchar*": str,
"uint": int,
"ulong": int,
"ULONG_MAX": ulong_max,
- "unsigned char": Char, # 5.9
+ "unsigned char": int, # 5.9
"unsigned char*": str,
"unsigned int": int,
"unsigned long int": int, # 5.6, RHEL 6.6
@@ -405,7 +366,7 @@ def init_minimal():
def init_sample():
import datetime
type_map.update({
- "char": Char,
+ "char": int,
"char**": typing.List[str],
"Complex": complex,
"double": float,
@@ -418,7 +379,7 @@ def init_sample():
"PStr": str,
"PyDate": datetime.date,
"sample.bool": bool,
- "sample.char": Char,
+ "sample.char": int,
"sample.double": float,
"sample.int": int,
"sample.ObjectType": object,
@@ -427,7 +388,7 @@ def init_sample():
"sample.Photon.TemplateBase[Photon.IdentityType]": sample.Photon.ValueIdentity,
"sample.Point": Point,
"sample.PStr": str,
- "sample.unsigned char": Char,
+ "sample.unsigned char": int,
"std.size_t": int,
"std.string": str,
"ZeroIn": 0,