diff options
author | Christian Tismer <tismer@stackless.com> | 2018-10-14 11:13:40 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2018-11-15 10:24:23 +0000 |
commit | 2533dab013455bf94da2d4766e54abaf4d735e1e (patch) | |
tree | 506f169c2f3a44fed3bfe623c1f626d40836a379 /sources/pyside2/PySide2/support/signature/layout.py | |
parent | 93b54f123771c5b7da9880e9a2f372562893707f (diff) |
Signature: Implement Nested Classes and Functions for Shiboken
This patch again contains a complete overhaul of the signature
module. The code was re-implemented to properly support nested
classes. Also, the code was reduced by AutoDecRef and by
adopting a concise C++ style.
Note.. We will add a shiboken signature test and complete
mapping.py after the split into three projects is done. The split
changes a lot and is needed right now!
Signatures were quite complete for PySide, but the support for Shiboken
was under-developed.
Since we are planning to generally enhance error messages by using
the Signature module, we should be able to rely on them to always
produce a signature. Therefore, a general overhaul was needed
to resolve all cornes cases for Python 2 and 3.
Nested classes are supported, as well as plain module functions.
The usage of the typing module might improve over time, but the
Signature implementation is now considered complete.
The loader will respect now the path settings which might not be
the package dir but the build dir. This is more consistens with COIN
testing.
Task-number: PYSIDE-795
Change-Id: I246449d4df895dadf2bcb4d997eaa13d78463d9b
Reviewed-by: Simo Fält <simo.falt@qt.io>
Diffstat (limited to 'sources/pyside2/PySide2/support/signature/layout.py')
-rw-r--r-- | sources/pyside2/PySide2/support/signature/layout.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/sources/pyside2/PySide2/support/signature/layout.py b/sources/pyside2/PySide2/support/signature/layout.py index ac7833f03..e18cb2172 100644 --- a/sources/pyside2/PySide2/support/signature/layout.py +++ b/sources/pyside2/PySide2/support/signature/layout.py @@ -58,6 +58,7 @@ used literally as strings like "signature", "existence", etc. from textwrap import dedent from .loader import inspect + class SimpleNamespace(object): # From types.rst, because the builtin is implemented in Python 3, only. def __init__(self, **kwargs): @@ -71,6 +72,7 @@ class SimpleNamespace(object): def __eq__(self, other): return self.__dict__ == other.__dict__ + class SignatureLayout(SimpleNamespace): """ Configure a signature. @@ -140,6 +142,7 @@ typeerror = SignatureLayout(definition=False, return_annotation=False, parameter_names=False) + def define_nameless_parameter(): """ Create Nameless Parameters @@ -168,8 +171,10 @@ def define_nameless_parameter(): body["__str__"] = __str__ return type(newname, bases, body) + NamelessParameter = define_nameless_parameter() + def make_signature_nameless(signature): """ Make a Signature Nameless @@ -178,7 +183,8 @@ def make_signature_nameless(signature): The signature looks different, but is totally intact. """ for key in signature.parameters.keys(): - Signature.parameters[key].__class__ = NamelessParameter + signature.parameters[key].__class__ = NamelessParameter + def create_signature(props, key): if not props: @@ -193,7 +199,7 @@ def create_signature(props, key): else: sig_kind, modifier = key, "signature" - layout = globals()[modifier] # lookup of the modifier, here + layout = globals()[modifier] # lookup of the modifier in this module if not isinstance(layout, SignatureLayout): raise SystemError("Modifiers must be names of a SignatureLayout " "instance") @@ -201,14 +207,16 @@ def create_signature(props, key): # this is the basic layout of a signature varnames = props["varnames"] if layout.definition: - if sig_kind == "method": + if sig_kind == "function": + pass + elif sig_kind == "method": varnames = ("self",) + varnames elif sig_kind == "staticmethod": pass elif sig_kind == "classmethod": varnames = ("klass",) + varnames else: - raise SystemError("Methods must be normal, staticmethod or " + raise SystemError("Methods must be function, method, staticmethod or " "classmethod") # calculate the modifications defaults = props["defaults"][:] |