aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/shibokenmodule
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2018-07-14 15:10:56 +0200
committerChristian Tismer <tismer@stackless.com>2018-12-22 12:26:10 +0000
commit73a9168ad56559bb3fba0d93866b05a7fde812de (patch)
treeb57018ee6702eac794867635d549a3b65509ca71 /sources/shiboken2/shibokenmodule
parentc013faebdfb248e1ce66fa41aa0a771aaf4e3d80 (diff)
Complete The Signature Introspection
The signature module has been quite far developed. In the course of making things fit for the TypeErrors with the signature module, now also all signatures from all shiboken modules are queried. Instead of writing an extra signature existence test for shiboken, it made more sense to extend the existing init_platform.py by the shiboken modules. In fact, by this query a corner case was exploited that worked on Python 2 but assertion-crashed on Python 3. The mapping.py modules were also completed to support all new PySide2 modules. Special care had to be taken because the "shiboken2" module exists both as directory and as binary module. The fix was tricky, and I will add a task that replaces such workarounds by a better design. Task-number: PYSIDE-510 Change-Id: Ibf8e322d1905976a0044a702ea178b7f98629fb4 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/shibokenmodule')
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py4
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/mapping.py72
2 files changed, 69 insertions, 7 deletions
diff --git a/sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py b/sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py
index 6b97470e..e890dcdc 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py
+++ b/sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py
@@ -113,8 +113,8 @@ CO_NOFREE = 0x0040
# We use '__builtin__' and '__name__' instead.
# It is further changed because we use a local copy of typing
def formatannotation(annotation, base_module=None):
- if getattr(annotation, '__module__', None) == 'support.signature.typing':
- return repr(annotation).replace('support.signature.typing', 'typing')
+ if getattr(annotation, '__module__', None) == 'support.signature.typing27':
+ return repr(annotation).replace('support.signature.typing27', 'typing')
if isinstance(annotation, type):
if annotation.__module__ in ('__builtin__', base_module):
return annotation.__name__
diff --git a/sources/shiboken2/shibokenmodule/support/signature/mapping.py b/sources/shiboken2/shibokenmodule/support/signature/mapping.py
index 3e76cd94..f638bc42 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/mapping.py
+++ b/sources/shiboken2/shibokenmodule/support/signature/mapping.py
@@ -88,6 +88,7 @@ WId = int
GL_TEXTURE_2D = 0x0DE1
GL_RGBA = 0x1908
+
class _NotCalled(str):
"""
Wrap some text with semantics
@@ -104,7 +105,7 @@ class _NotCalled(str):
real object is needed, the wrapper can simply be called.
"""
def __repr__(self):
- suppress = "support.signature.typing."
+ suppress = "support.signature.typing27."
text = self[len(suppress):] if self.startswith(suppress) else self
return "{}({})".format(type(self).__name__, text)
@@ -113,14 +114,20 @@ class _NotCalled(str):
text = self if self.endswith(")") else self + "()"
return eval(text, namespace)
+USE_PEP563 = sys.version_info[:2] >= (3, 7)
+
+
# Some types are abstract. They just show their name.
class Virtual(_NotCalled):
pass
# Other types I simply could not find.
class Missing(_NotCalled):
- def __repr__(self):
- return '{}("{}")'.format(type(self).__name__, self)
+ if not USE_PEP563:
+ # The string must be quoted, because the object does not exist.
+ def __repr__(self):
+ return '{}("{}")'.format(type(self).__name__, self)
+
class Invalid(_NotCalled):
pass
@@ -129,12 +136,20 @@ class Invalid(_NotCalled):
class Default(_NotCalled):
pass
+
class Instance(_NotCalled):
pass
class Reloader(object):
- _uninitialized = ["sample"]
+ """
+ Reloder class
+
+ This is a singleton class which provides the update function for the
+ shiboken and PySide classes.
+ """
+ ## Note: We needed to rename shiboken2 in order to avoid a name clash.
+ _uninitialized = "Shiboken minimal sample other smart".split()
_prefixes = [""]
def __init__(self):
@@ -142,6 +157,14 @@ class Reloader(object):
self.uninitialized = self._uninitialized
def update(self, g=None):
+ """
+ update is responsible to import all modules from shiboken and PySide
+ which are already in sys.modules.
+ The purpose is to follow all user imports without introducing new
+ ones.
+ This function is called by pyside_type_init to adapt imports
+ when the number of imported modules has changed.
+ """
if self.sys_module_count == len(sys.modules):
return
self.sys_module_count = len(sys.modules)
@@ -160,6 +183,14 @@ class Reloader(object):
self.uninitialized.remove(mod_name)
proc_name = "init_" + mod_name
if proc_name in g:
+ # Do the 'import {import_name}' first.
+ # 'top' is PySide2 when we do 'import PySide.QtCore'
+ # or Shiboken if we do 'import Shiboken'.
+ # Convince yourself that these two lines below have the same
+ # global effect as "import Shiboken" or "import PySide2.QtCore".
+ top = __import__(import_name)
+ g[top.__name__] = top
+ # Modules are in place, we can update the type_map.
g.update(g[proc_name]())
@@ -167,8 +198,23 @@ update_mapping = Reloader().update
type_map = {}
+def init_Shiboken():
+ type_map.update({
+ "shiboken2.bool": bool,
+ "size_t": int,
+ "PyType": type,
+ })
+ return locals()
+
+
+def init_minimal():
+ type_map.update({
+ "MinBool": bool,
+ })
+ return locals()
+
+
def init_sample():
- import sample
import datetime
type_map.update({
"sample.int": int,
@@ -207,4 +253,20 @@ def init_sample():
})
return locals()
+
+def init_other():
+ import numbers
+ type_map.update({
+ "other.Number": numbers.Number,
+ "other.ExtendsNoImplicitConversion": Missing("other.ExtendsNoImplicitConversion"),
+ })
+ return locals()
+
+
+def init_smart():
+ type_map.update({
+ "smart.SharedPtr": Missing("smart.SharedPtr"), # bad object "SharedPtr<Obj >"
+ })
+ return locals()
+
# end of file