diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-02-28 16:38:14 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-28 22:07:09 +0000 |
commit | 985c281c2717a1595f3c1219a0c61a55be2a7ed6 (patch) | |
tree | a97cdf65d177972708df6709a5f747054cfba056 | |
parent | 4fbcfa43a2eeedd4b3ee5c8b25eb9532abcf1c9b (diff) |
snippets_translate: Do not append "()" when assigning special values
It used to generate things like "b = False()" for variable
assignments. Check the special values.
Task-number: PYSIDE-1106
Change-Id: I19cdcd4205369d0d5681151b1f1243d6a9a3f81e
Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit 088acf9aec615372b297aab701757318e94b1fb5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tools/snippets_translate/converter.py | 5 | ||||
-rw-r--r-- | tools/snippets_translate/tests/test_converter.py | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/tools/snippets_translate/converter.py b/tools/snippets_translate/converter.py index 93aab199f..c846d14ac 100644 --- a/tools/snippets_translate/converter.py +++ b/tools/snippets_translate/converter.py @@ -264,7 +264,10 @@ def snippet_translate(x): # so we need to add '()' at the end if it's just a word # with only alpha numeric content if VAR4_PATTERN.search(xs) and not xs.endswith(")"): - x = f"{x.rstrip()}()" + v = x.rstrip() + if (not v.endswith(" True") and not v.endswith(" False") + and not v.endswith(" None")): + x = f"{value}()" return dstrip(x) # For constructors, that we now the shape is: diff --git a/tools/snippets_translate/tests/test_converter.py b/tools/snippets_translate/tests/test_converter.py index 8c81f4635..335533af0 100644 --- a/tools/snippets_translate/tests/test_converter.py +++ b/tools/snippets_translate/tests/test_converter.py @@ -159,6 +159,8 @@ def test_variable_declaration(): assert st("QPointer<QLabel> label = new QLabel;") == "label = QLabel()" assert st("QMatrix4x4 matrix;") == "matrix = QMatrix4x4()" assert st("QList<QImage> collage =") == "collage =" + assert st("bool b = true;") == "b = True" + assert st("Q3DBars *m_graph = nullptr;") == "m_graph = None" def test_for(): |