diff options
Diffstat (limited to 'sources/pyside2/PySide2/support/signature/lib/enum_sig.py')
-rw-r--r-- | sources/pyside2/PySide2/support/signature/lib/enum_sig.py | 129 |
1 files changed, 1 insertions, 128 deletions
diff --git a/sources/pyside2/PySide2/support/signature/lib/enum_sig.py b/sources/pyside2/PySide2/support/signature/lib/enum_sig.py index c043f04f8..1d19ad5e4 100644 --- a/sources/pyside2/PySide2/support/signature/lib/enum_sig.py +++ b/sources/pyside2/PySide2/support/signature/lib/enum_sig.py @@ -39,131 +39,4 @@ from __future__ import print_function, absolute_import -import sys -from PySide2.support.signature import inspect, get_signature - - -class ExactEnumerator(object): - """ - ExactEnumerator enumerates all signatures in a module as they are. - - This class is used for generating complete listings of all signatures. - 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 - - def module(self, mod_name): - __import__(mod_name) - with self.fmt.module(mod_name): - module = sys.modules[mod_name] - members = inspect.getmembers(module, inspect.isclass) - functions = inspect.getmembers(module, inspect.isroutine) - ret = self.result_type() - self.fmt.class_name = None - for func_name, func in functions: - ret.update(self.function(func_name, func)) - for class_name, klass in members: - ret.update(self.klass(class_name, klass)) - return ret - - def klass(self, class_name, klass): - bases_list = [] - for base in klass.__bases__: - name = base.__name__ - if name == "object": - pass - else: - modname = base.__module__ - name = modname + "." + base.__name__ - bases_list.append(name) - class_str = "{}({})".format(class_name, ", ".join(bases_list)) - with self.fmt.klass(class_name, class_str): - ret = self.function("__init__", klass) - # class_members = inspect.getmembers(klass) - # gives us also the inherited things. - class_members = sorted(list(klass.__dict__.items())) - subclasses = [] - for thing_name, thing in class_members: - if inspect.isclass(thing): - subclass_name = ".".join((class_name, thing_name)) - subclasses.append((subclass_name, thing)) - else: - ret.update(self.function(thing_name, thing)) - for subclass_name, subclass in subclasses: - ret.update(self.klass(subclass_name, subclass)) - return ret - - def function(self, func_name, func): - ret = self.result_type() - signature = getattr(func, '__signature__', None) - if signature is not None: - with self.fmt.function(func_name, signature) as key: - ret[key] = signature - return ret - - -def simplify(signature): - if isinstance(signature, list): - # remove duplicates which still sometimes occour: - ret = set(simplify(sig) for sig in signature) - return sorted(ret) if len(ret) > 1 else list(ret)[0] - ret = [] - for pv in signature.parameters.values(): - txt = str(pv) - if ":" not in txt: # 'self' or '*args' - continue - txt = txt[txt.index(":") + 1:] - if "=" in txt: - txt = txt[:txt.index("=")] - quote = txt[0] - if quote in ("'", '"') and txt[-1] == quote: - txt = txt[1:-1] - ret.append(txt.strip()) - return tuple(ret) - - -### disabled for now: -class SimplifyingEnumerator(ExactEnumerator): - """ - SimplifyingEnumerator enumerates all signatures in a module filtered. - - There are no default values, no variable - names and no self parameter. Only types are present after simplification. - The functions 'next' resp. '__next__' are removed - to make the output identical for Python 2 and 3. - An appropriate formatter should be supplied, if printable output - is desired. - """ - - def function(self, func_name, func): - ret = self.result_type() - signature = get_signature(func, 'existence') - if signature is not None and func_name not in ("next", "__next__"): - with self.fmt.function(func_name, signature) as key: - ret[key] = str(signature) - return ret - - -class SimplifyingEnumerator(ExactEnumerator): - """ - SimplifyingEnumerator enumerates all signatures in a module filtered. - - There are no default values, no variable - names and no self parameter. Only types are present after simplification. - The functions 'next' resp. '__next__' are removed - to make the output identical for Python 2 and 3. - An appropriate formatter should be supplied, if printable output - is desired. - """ - - def function(self, func_name, func): - ret = self.result_type() - signature = getattr(func, '__signature__', None) - sig = simplify(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 +from signature_loader.enum_sig import * |