aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
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/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
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/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py')
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py55
1 files changed, 8 insertions, 47 deletions
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,