aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-01-21 13:09:52 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-01-22 11:38:23 +0000
commitcc7504e0b9090f9d0782ef27a9a8ce74fc5df552 (patch)
tree2d902131c984324560ba9e8cbd429dd7a199dd8e
parentfadc307586f2f762bb9d0907d2f458b39c5b5770 (diff)
signature: Provide fixes and improvements, Part 1
The signature module is modified again to be more correct when using the mypy application. This part splits some changes which occurred when working on Shiboken.Enum inheritance. There will be a number of follow-ups: - signatures for all shiboken types - test cases for signatures - signature support for different __feature__ selections Change-Id: Ifb0d92bf7641f2909ab950e3458b3c3c68c20dad Task-number: PYSIDE-510 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 123e27090e0ec4f8d32f301700c9ff9d1b49ba2a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside6/PySide6/QtQml/pysideqmlregistertype.cpp6
-rw-r--r--sources/pyside6/PySide6/support/generate_pyi.py3
-rw-r--r--sources/pyside6/libpyside/pysideclassinfo.cpp2
-rw-r--r--sources/pyside6/libpyside/pysidemetafunction.cpp2
-rw-r--r--sources/pyside6/libpyside/pysidesignal.cpp10
-rw-r--r--sources/pyside6/libpyside/pysideslot.cpp2
-rw-r--r--sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py58
-rw-r--r--sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py2
8 files changed, 50 insertions, 35 deletions
diff --git a/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.cpp b/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.cpp
index 32be83334..29fd8be77 100644
--- a/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.cpp
+++ b/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.cpp
@@ -616,13 +616,13 @@ PyTypeObject *QtQml_VolatileBoolTypeF(void)
}
static const char *PropertyList_SignatureStrings[] = {
- "PySide6.QtQml.ListProperty(type:type,append:typing.Callable,"
+ "PySide6.QtQml.ListProperty(self,type:type,append:typing.Callable,"
"at:typing.Callable=None,clear:typing.Callable=None,count:typing.Callable=None)",
nullptr}; // Sentinel
static const char *VolatileBool_SignatureStrings[] = {
- "PySide6.QtQml.VolatileBool.get()->bool",
- "PySide6.QtQml.VolatileBool.set(a:object)",
+ "PySide6.QtQml.VolatileBool.get(self)->bool",
+ "PySide6.QtQml.VolatileBool.set(self,a:object)",
nullptr}; // Sentinel
void PySide::initQmlSupport(PyObject *module)
diff --git a/sources/pyside6/PySide6/support/generate_pyi.py b/sources/pyside6/PySide6/support/generate_pyi.py
index 627e8efc1..32f43d804 100644
--- a/sources/pyside6/PySide6/support/generate_pyi.py
+++ b/sources/pyside6/PySide6/support/generate_pyi.py
@@ -128,6 +128,7 @@ class Formatter(Writer):
self.optional_replacer = optional_replacer
# self.level is maintained by enum_sig.py
# self.after_enum() is a one-shot set by enum_sig.py .
+ # self.is_method() is true for non-plain functions.
@contextmanager
def module(self, mod_name):
@@ -184,7 +185,7 @@ class Formatter(Writer):
yield key
def _function(self, func_name, signature, spaces):
- if "self" not in tuple(signature.parameters.keys()):
+ if self.is_method() and "self" not in tuple(signature.parameters.keys()):
self.print(f'{spaces}@staticmethod')
signature = self.optional_replacer(signature)
self.print(f'{spaces}def {func_name}{signature}: ...')
diff --git a/sources/pyside6/libpyside/pysideclassinfo.cpp b/sources/pyside6/libpyside/pysideclassinfo.cpp
index 67334f2f4..2a9914a68 100644
--- a/sources/pyside6/libpyside/pysideclassinfo.cpp
+++ b/sources/pyside6/libpyside/pysideclassinfo.cpp
@@ -179,7 +179,7 @@ void classInfoFree(void *self)
namespace PySide { namespace ClassInfo {
static const char *ClassInfo_SignatureStrings[] = {
- "PySide6.QtCore.ClassInfo(**info:typing.Dict[str,str])",
+ "PySide6.QtCore.ClassInfo(self,**info:typing.Dict[str,str])",
nullptr}; // Sentinel
void init(PyObject *module)
diff --git a/sources/pyside6/libpyside/pysidemetafunction.cpp b/sources/pyside6/libpyside/pysidemetafunction.cpp
index 6d93e7629..939e52e12 100644
--- a/sources/pyside6/libpyside/pysidemetafunction.cpp
+++ b/sources/pyside6/libpyside/pysidemetafunction.cpp
@@ -102,7 +102,7 @@ PyObject *functionCall(PyObject *self, PyObject *args, PyObject * /* kw */)
namespace PySide { namespace MetaFunction {
static const char *MetaFunction_SignatureStrings[] = {
- "PySide6.QtCore.MetaFunction.__call__(*args:typing.Any)->typing.Any",
+ "PySide6.QtCore.MetaFunction.__call__(self,*args:typing.Any)->typing.Any",
nullptr}; // Sentinel
void init(PyObject *module)
diff --git a/sources/pyside6/libpyside/pysidesignal.cpp b/sources/pyside6/libpyside/pysidesignal.cpp
index d14f32525..8533c2a48 100644
--- a/sources/pyside6/libpyside/pysidesignal.cpp
+++ b/sources/pyside6/libpyside/pysidesignal.cpp
@@ -620,17 +620,17 @@ namespace PySide {
namespace Signal {
static const char *MetaSignal_SignatureStrings[] = {
- "PySide6.QtCore.MetaSignal.__instancecheck__(object:object)->bool",
+ "PySide6.QtCore.MetaSignal.__instancecheck__(self,object:object)->bool",
nullptr}; // Sentinel
static const char *Signal_SignatureStrings[] = {
- "PySide6.QtCore.Signal(*types:type,name:str=nullptr,arguments:str=nullptr)",
+ "PySide6.QtCore.Signal(self,*types:type,name:str=nullptr,arguments:str=nullptr)",
nullptr}; // Sentinel
static const char *SignalInstance_SignatureStrings[] = {
- "PySide6.QtCore.SignalInstance.connect(slot:object,type:type=nullptr)",
- "PySide6.QtCore.SignalInstance.disconnect(slot:object=nullptr)",
- "PySide6.QtCore.SignalInstance.emit(*args:typing.Any)",
+ "PySide6.QtCore.SignalInstance.connect(self,slot:object,type:type=nullptr)",
+ "PySide6.QtCore.SignalInstance.disconnect(self,slot:object=nullptr)",
+ "PySide6.QtCore.SignalInstance.emit(self,*args:typing.Any)",
nullptr}; // Sentinel
void init(PyObject *module)
diff --git a/sources/pyside6/libpyside/pysideslot.cpp b/sources/pyside6/libpyside/pysideslot.cpp
index 850fee544..81f93c555 100644
--- a/sources/pyside6/libpyside/pysideslot.cpp
+++ b/sources/pyside6/libpyside/pysideslot.cpp
@@ -183,7 +183,7 @@ namespace PySide {
namespace Slot {
static const char *Slot_SignatureStrings[] = {
- "PySide6.QtCore.Slot(*types:type,name:str=nullptr,result:str=nullptr)->typing.Callable[...,typing.Optional[str]]",
+ "PySide6.QtCore.Slot(self,*types:type,name:str=nullptr,result:str=nullptr)->typing.Callable[...,typing.Optional[str]]",
nullptr}; // Sentinel
void init(PyObject *module)
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
index 99052e50e..c90ad05f0 100644
--- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
+++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
@@ -49,7 +49,7 @@ by producing a lot of clarity.
import sys
from shibokensupport.signature import inspect
-from shibokensupport.signature import get_signature
+from shibokensupport.signature import get_signature as get_sig
class ExactEnumerator(object):
@@ -62,19 +62,30 @@ class ExactEnumerator(object):
"""
def __init__(self, formatter, result_type=dict):
- global EnumType
+ global EnumMeta
try:
# Lazy import
from PySide6.QtCore import Qt
- EnumType = type(Qt.Key)
+ EnumMeta = type(Qt.Key)
except ImportError:
- EnumType = None
+ EnumMeta = None
self.fmt = formatter
self.result_type = result_type
self.fmt.level = 0
self.fmt.after_enum = self.after_enum
self._after_enum = False
+ self.fmt.is_method = self.is_method
+
+ def is_method(self):
+ """
+ Is this function a method?
+ We check if it is not in a sub-structure
+ """
+ func = self.func
+ if hasattr(func, "__func__"):
+ func = func.__func__
+ return func.__name__ != func.__qualname__
def after_enum(self):
ret = self._after_enum
@@ -91,7 +102,7 @@ class ExactEnumerator(object):
self.fmt.class_name = None
for class_name, klass in members:
ret.update(self.klass(class_name, klass))
- if isinstance(klass, EnumType):
+ if isinstance(klass, EnumMeta):
raise SystemError("implement enum instances at module level")
for func_name, func in functions:
ret.update(self.function(func_name, func))
@@ -128,10 +139,11 @@ class ExactEnumerator(object):
signature = getattr(thing, "__signature__", None)
if signature is not None:
functions.append((func_name, thing))
- elif type(type(thing)) is EnumType:
- enums.append((thing_name, thing))
+ elif type(type(thing)) is EnumMeta:
+ # take the real enum name, not what is in the dict
+ enums.append((thing_name, type(thing).__qualname__, thing))
init_signature = getattr(klass, "__signature__", None)
- enums.sort(key=lambda tup: tup[1]) # sort by enum value
+ enums.sort(key=lambda tup: tup[1 : 3]) # sort by class then enum value
self.fmt.have_body = bool(subclasses or functions or enums or init_signature)
with self.fmt.klass(class_name, class_str):
@@ -139,8 +151,8 @@ class ExactEnumerator(object):
self.fmt.class_name = class_name
if hasattr(self.fmt, "enum"):
# this is an optional feature
- for enum_name, value in enums:
- with self.fmt.enum(class_name, enum_name, int(value)):
+ for enum_name, enum_class_name, value in enums:
+ with self.fmt.enum(enum_class_name, enum_name, int(value)):
pass
for subclass_name, subclass in subclasses:
if klass == subclass:
@@ -157,14 +169,18 @@ class ExactEnumerator(object):
self.fmt.level -= 1
return ret
+ @staticmethod
+ def get_signature(func):
+ return func.__signature__
+
def function(self, func_name, func):
- self.fmt.level += 1
+ self.func = func # for is_method()
ret = self.result_type()
- signature = func.__signature__
+ signature = self.get_signature(func)
if signature is not None:
- with self.fmt.function(func_name, signature, modifier) as key:
+ with self.fmt.function(func_name, signature) as key:
ret[key] = signature
- self.fmt.level -= 1
+ del self.func
return ret
@@ -190,13 +206,14 @@ class SimplifyingEnumerator(ExactEnumerator):
def function(self, func_name, func):
ret = self.result_type()
- signature = get_signature(func, 'existence')
+ signature = get_sig(func, 'existence')
sig = stringify(signature) if signature is not None else None
if sig is not None and func_name not in ("next", "__next__", "__div__"):
with self.fmt.function(func_name, sig) as key:
ret[key] = sig
return ret
+
class HintingEnumerator(ExactEnumerator):
"""
HintingEnumerator enumerates all signatures in a module slightly changed.
@@ -205,11 +222,6 @@ class HintingEnumerator(ExactEnumerator):
hinting stubs. Only default values are replaced by "...".
"""
- def function(self, func_name, func):
- ret = self.result_type()
- signature = get_signature(func, 'hintingstub')
- if signature is not None:
- with self.fmt.function(func_name, signature) as key:
- ret[key] = signature
- return ret
-
+ @staticmethod
+ def get_signature(func):
+ return get_sig(func, "hintingstub")
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
index 97991d4f9..e6ad8d3d0 100644
--- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
+++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
@@ -362,6 +362,8 @@ def init_Shiboken():
})
return locals()
+# side effect of different shiboken namings
+init_shiboken6 = init_shiboken6_shiboken6 = init_Shiboken
def init_minimal():
type_map.update({