diff options
author | Christian Tismer <tismer@stackless.com> | 2019-08-22 18:57:11 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2019-08-29 15:44:07 +0200 |
commit | d4acbacd7a655e3ff9e17663a23ed0d822b84850 (patch) | |
tree | cfe5b2666c5e98c848b22ef7b493c775cff5aebc /sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py | |
parent | 4d63dfffb661115f58cca60c80c4649ba982e01b (diff) |
signature: Support typing.Optional[T] and refine a bit
The signature was missing "typing.Optional[T]" which has to be wrapped
around any argument with a default value of "None".
This is the only case where the repr of a type looks different than
it was written, because it renders as "typing.Union[T, NoneType]".
Solving that by redefining a few typing structures was way too
hard and too error prone. It was finally solved by a regex replacemet
that is run as a post process in generate_pyi.py .
The enumerations are now even more complete, since toplevel enums
are also included. This had the effect that enums with Python
keywords were revealed, and so the function "createEnumItem" had
to be modified.
The order of creation was also changed to avoid name clashes.
The overall structure was improved, and instead of parsing the
generated signatures to find out if something is a class method,
this is now very cleanly implemented as an inquiry to get_signature().
I tried to make sense of the flags structure that comes with many
enums. PyQt5 has a standard set of "__...__" methods without useful
signature information. I could mimick that as well, but that would
create a whole lot of pointless extra information. We should decide
later if it makes sense to include that. Right now the flags
structures show the class name, only.
This patch will be merged with the 5.14 branch. The additions of this
patch could fortunately be placed into areas which do almost not
overlap with the 5.14 signature additions.
Change-Id: Ie513e15917b04d746ab597fb7a9eb1fd766f7c73
Fixes: PYSIDE-1079
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.py | 17 |
1 files changed, 1 insertions, 16 deletions
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index 10d0f16ad..163aac851 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -55,6 +55,7 @@ import os from shibokensupport.signature import typing from shibokensupport.signature.typing import TypeVar, Generic +from shibokensupport.signature.lib.tool import with_metaclass class ellipsis(object): def __repr__(self): @@ -76,22 +77,6 @@ _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? -# Copied from the six module: -def with_metaclass(meta, *bases): - """Create a base class with a metaclass.""" - # This requires a bit of explanation: the basic idea is to make a dummy - # metaclass for one level of class instantiation that replaces itself with - # the actual metaclass. - class metaclass(type): - - def __new__(cls, name, this_bases, d): - return meta(name, bases, d) - - @classmethod - def __prepare__(cls, name, this_bases): - return meta.__prepare__(name, bases) - return type.__new__(metaclass, 'temporary_class', (), {}) - class _CharMeta(type): def __repr__(self): return '%s.%s' % (self.__module__, self.__name__) |