diff options
author | Simo Fält <simo.falt@qt.io> | 2023-02-01 15:24:01 +0200 |
---|---|---|
committer | Simo Fält <simo.falt@qt.io> | 2023-02-01 15:24:01 +0200 |
commit | 4ff8ac45ac541471d5ec967e529e24a6bee87eba (patch) | |
tree | 23149a480cb8dbf15d86e24b2f107a88881ebefb /sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py | |
parent | d526f801ced4687d5413907a93dedcd782ef72fa (diff) | |
parent | ac0db13c20529d09a715985b2a2d4579f415369c (diff) |
Merge tag 'v5.15.3-lts' into tqtc/lts-5.15-opensource
Qt For Python Release 5.15.3
Change-Id: Ia936efcdfa8196b02528905c12cc7764553d6ca8
Diffstat (limited to 'sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py')
-rw-r--r-- | sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py | 81 |
1 files changed, 37 insertions, 44 deletions
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py index 814926a59..2aad8a65c 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py @@ -1,11 +1,12 @@ ############################################################################# ## -## Copyright (C) 2020 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of Qt for Python. ## -## $QT_BEGIN_LICENSE:LGPL$ +## $QT_BEGIN_LICENSE:COMM$ +## ## Commercial License Usage ## Licensees holding valid commercial Qt licenses may use this file in ## accordance with the commercial license agreement provided with the @@ -14,25 +15,6 @@ ## and conditions see https://www.qt.io/terms-conditions. For further ## information use the contact form at https://www.qt.io/contact-us. ## -## GNU Lesser General Public License Usage -## Alternatively, this file may be used under the terms of the GNU Lesser -## General Public License version 3 as published by the Free Software -## Foundation and appearing in the file LICENSE.LGPL3 included in the -## packaging of this file. Please review the following information to -## ensure the GNU Lesser General Public License version 3 requirements -## will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 2.0 or (at your option) the GNU General -## Public license version 3 or any later version approved by the KDE Free -## Qt Foundation. The licenses are as published by the Free Software -## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -## included in the packaging of this file. Please review the following -## information to ensure the GNU General Public License requirements will -## be met: https://www.gnu.org/licenses/gpl-2.0.html and -## https://www.gnu.org/licenses/gpl-3.0.html. -## ## $QT_END_LICENSE$ ## ############################################################################# @@ -50,8 +32,9 @@ by producing a lot of clarity. """ import sys +import types from shibokensupport.signature import inspect -from shibokensupport.signature import get_signature +from shibokensupport.signature import get_signature as get_sig class ExactEnumerator(object): @@ -64,19 +47,28 @@ class ExactEnumerator(object): """ def __init__(self, formatter, result_type=dict): - global EnumType + global EnumMeta try: # Lazy import from PySide2.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 a simple function. + """ + tp = type(self.func) + return tp not in (types.BuiltinFunctionType, types.FunctionType) def after_enum(self): ret = self._after_enum @@ -93,7 +85,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)) @@ -129,10 +121,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): @@ -140,8 +133,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: @@ -159,14 +152,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 @@ -192,13 +189,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. @@ -207,11 +205,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") |