From ce80e7c4aa5170fd518b70da64f05ab13e3065c2 Mon Sep 17 00:00:00 2001 From: jandorr Date: Mon, 6 Feb 2023 09:47:48 -0800 Subject: [PATCH 1/3] fix translate arguments --- Qt.py | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/Qt.py b/Qt.py index 4ed2bea0..90295437 100644 --- a/Qt.py +++ b/Qt.py @@ -831,23 +831,35 @@ def _translate(context, sourceText, *args): # The first argument is disambiguation[str] # The last argument is n[int] # The middle argument can be encoding[QtCore.QCoreApplication.Encoding] + try: + app = Qt.QtCore.QCoreApplication + except AttributeError: + raise NotImplementedError( + "Missing QCoreApplication implementation for {}".format( + Qt.__binding__ + ) + ) + + def get_arg(index): + try: + return args[index] + except IndexError: + pass + + n = -1 + encoding = None + if len(args) == 3: disambiguation, encoding, n = args - elif len(args) == 2: - disambiguation, n = args - encoding = None else: - raise TypeError( - "Expected 4 or 5 arguments, got {0}.".format(len(args) + 2)) + disambiguation = get_arg(0) + n_or_encoding = get_arg(1) + + if isinstance(n_or_encoding, int): + n = n_or_encoding + else: + encoding = n_or_encoding - if hasattr(Qt.QtCore, "QCoreApplication"): - app = getattr(Qt.QtCore, "QCoreApplication") - else: - raise NotImplementedError( - "Missing QCoreApplication implementation for {binding}".format( - binding=Qt.__binding__, - ) - ) if Qt.__binding__ in ("PySide2", "PyQt5"): sanitized_args = [context, sourceText, disambiguation, n] else: @@ -856,8 +868,9 @@ def _translate(context, sourceText, *args): sourceText, disambiguation, encoding or app.CodecForTr, - n + n, ] + return app.translate(*sanitized_args) From e987732052bbac11fd8461f3b4c690801a241883 Mon Sep 17 00:00:00 2001 From: jandorr Date: Mon, 6 Feb 2023 10:23:41 -0800 Subject: [PATCH 2/3] Revert "fix translate arguments" This reverts commit ce80e7c4aa5170fd518b70da64f05ab13e3065c2. --- Qt.py | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/Qt.py b/Qt.py index 90295437..4ed2bea0 100644 --- a/Qt.py +++ b/Qt.py @@ -831,35 +831,23 @@ def _translate(context, sourceText, *args): # The first argument is disambiguation[str] # The last argument is n[int] # The middle argument can be encoding[QtCore.QCoreApplication.Encoding] - try: - app = Qt.QtCore.QCoreApplication - except AttributeError: - raise NotImplementedError( - "Missing QCoreApplication implementation for {}".format( - Qt.__binding__ - ) - ) - - def get_arg(index): - try: - return args[index] - except IndexError: - pass - - n = -1 - encoding = None - if len(args) == 3: disambiguation, encoding, n = args + elif len(args) == 2: + disambiguation, n = args + encoding = None else: - disambiguation = get_arg(0) - n_or_encoding = get_arg(1) - - if isinstance(n_or_encoding, int): - n = n_or_encoding - else: - encoding = n_or_encoding + raise TypeError( + "Expected 4 or 5 arguments, got {0}.".format(len(args) + 2)) + if hasattr(Qt.QtCore, "QCoreApplication"): + app = getattr(Qt.QtCore, "QCoreApplication") + else: + raise NotImplementedError( + "Missing QCoreApplication implementation for {binding}".format( + binding=Qt.__binding__, + ) + ) if Qt.__binding__ in ("PySide2", "PyQt5"): sanitized_args = [context, sourceText, disambiguation, n] else: @@ -868,9 +856,8 @@ def get_arg(index): sourceText, disambiguation, encoding or app.CodecForTr, - n, + n ] - return app.translate(*sanitized_args) From 98745baec462b49b674e4015d2014a6d6ba40c0c Mon Sep 17 00:00:00 2001 From: Jan Dorr Date: Mon, 6 Feb 2023 10:28:24 -0800 Subject: [PATCH 3/3] fix translate arguments --- Qt.py | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/Qt.py b/Qt.py index 4ed2bea0..90295437 100644 --- a/Qt.py +++ b/Qt.py @@ -831,23 +831,35 @@ def _translate(context, sourceText, *args): # The first argument is disambiguation[str] # The last argument is n[int] # The middle argument can be encoding[QtCore.QCoreApplication.Encoding] + try: + app = Qt.QtCore.QCoreApplication + except AttributeError: + raise NotImplementedError( + "Missing QCoreApplication implementation for {}".format( + Qt.__binding__ + ) + ) + + def get_arg(index): + try: + return args[index] + except IndexError: + pass + + n = -1 + encoding = None + if len(args) == 3: disambiguation, encoding, n = args - elif len(args) == 2: - disambiguation, n = args - encoding = None else: - raise TypeError( - "Expected 4 or 5 arguments, got {0}.".format(len(args) + 2)) + disambiguation = get_arg(0) + n_or_encoding = get_arg(1) + + if isinstance(n_or_encoding, int): + n = n_or_encoding + else: + encoding = n_or_encoding - if hasattr(Qt.QtCore, "QCoreApplication"): - app = getattr(Qt.QtCore, "QCoreApplication") - else: - raise NotImplementedError( - "Missing QCoreApplication implementation for {binding}".format( - binding=Qt.__binding__, - ) - ) if Qt.__binding__ in ("PySide2", "PyQt5"): sanitized_args = [context, sourceText, disambiguation, n] else: @@ -856,8 +868,9 @@ def _translate(context, sourceText, *args): sourceText, disambiguation, encoding or app.CodecForTr, - n + n, ] + return app.translate(*sanitized_args)