diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-02-28 16:38:14 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-02-28 22:13:34 +0100 |
commit | 088acf9aec615372b297aab701757318e94b1fb5 (patch) | |
tree | 58428829fbd8f9367d6b2feeb91a881d378a58ba | |
parent | 0479b02b6159c189440cfe8f1c6093c8336f50c9 (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.
Pick-to: 6.4 6.2
Task-number: PYSIDE-1106
Change-Id: I19cdcd4205369d0d5681151b1f1243d6a9a3f81e
Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
-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 35b025881..360cb157e 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(): |