diff options
author | Christian Tismer <tismer@stackless.com> | 2018-07-14 15:10:56 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2018-11-24 17:25:06 +0000 |
commit | b86d72b9eac320044fde5642e0323be3ef80d62c (patch) | |
tree | 55e308075718467e77376587fcef2dc7beb82710 /sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py | |
parent | 57e7c17b2b77740cf0be7620dd628584a369eb82 (diff) |
Create hinting stubs for Python IDEs
This implementation formats all signatures in a way
that is known as type hinting files (.pyi).
Usage
-----
The script is to be called by the same Python interpreter that
was used to build PySide. It works with Python 2 and 3.
On Python 3, it performs a self-test.
python3 sources/pyside2/PySide2/support/generate_pyi.py run
will generate .pyi files for all compiled PySide modules
and places them into site packages to the binaries.
An optional outpath can be specified.
It is planned to call this script automatically after install.
o Local constants are not included, yet.
Maybe they never will, unless requested.
o The keyword "from" appears 43 times in argument lists.
It is fixed in Python, only which does not matter.
o When using Python 3.7 or above, it respects Pep 563 and
avoids imports which are deferred to runtime.
Task-number: PYSIDE-735
Change-Id: I3bcd5d9284b853fe955376bf35c7897e3698da2b
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py')
-rw-r--r-- | sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py b/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py index 2ec14d62b..f79f3266a 100644 --- a/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py +++ b/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py @@ -39,6 +39,16 @@ from __future__ import print_function, absolute_import +""" +enum_sig.py + +Enumerate all signatures of a class. + +This module separates the enumeration process from the formatting. +It is not easy to adhere to this protocol, but in the end, it paid off +by producing a lot of clarity. +""" + import sys from signature_loader import get_signature, inspect @@ -51,6 +61,7 @@ class ExactEnumerator(object): An appropriate formatter should be supplied, if printable output is desired. """ + def __init__(self, formatter, result_type=dict): self.fmt = formatter self.result_type = result_type @@ -91,7 +102,8 @@ class ExactEnumerator(object): subclass_name = ".".join((class_name, thing_name)) subclasses.append((subclass_name, thing)) else: - ret.update(self.function(thing_name, thing)) + func_name = thing_name.split(".")[0] # remove ".overload" + ret.update(self.function(func_name, thing)) for subclass_name, subclass in subclasses: ret.update(self.klass(subclass_name, subclass)) return ret @@ -101,7 +113,7 @@ class ExactEnumerator(object): signature = getattr(func, '__signature__', None) if signature is not None: with self.fmt.function(func_name, signature) as key: - ret[key] = str(signature) + ret[key] = signature return ret @@ -133,3 +145,20 @@ class SimplifyingEnumerator(ExactEnumerator): 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. + + This class is used for generating complete listings of all signatures for + 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 + |