aboutsummaryrefslogtreecommitdiffstats
path: root/tools/snippets_translate
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-10-02 14:42:21 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-10-02 16:12:57 +0200
commit604591ee13e39c4d9953fb56322ca85bdaf01e74 (patch)
treed172b6507319aa73822bcc2971efda7d2f228641 /tools/snippets_translate
parentc512b506b565578770c671b11afb78427ca8d012 (diff)
snippets_translate: Fix flake8-warnings
Change-Id: I91f211639846bb119d696244060f3013c52e59ed Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'tools/snippets_translate')
-rw-r--r--tools/snippets_translate/converter.py11
-rw-r--r--tools/snippets_translate/override.py10
-rw-r--r--tools/snippets_translate/tests/test_converter.py15
3 files changed, 18 insertions, 18 deletions
diff --git a/tools/snippets_translate/converter.py b/tools/snippets_translate/converter.py
index 7179a94a0..e5880a09b 100644
--- a/tools/snippets_translate/converter.py
+++ b/tools/snippets_translate/converter.py
@@ -56,12 +56,12 @@ switch_branch = 0
def snippet_translate(x):
global switch_var, switch_branch
- ## Cases which are not C++
- ## TODO: Maybe expand this with lines that doesn't need to be translated
+ # # Cases which are not C++
+ # # TODO: Maybe expand this with lines that doesn't need to be translated
if x.strip().startswith("content-type: text/html"):
return x
- ## General Rules
+ # # General Rules
# Remove ';' at the end of the lines
has_semicolon = x.endswith(";")
@@ -180,7 +180,7 @@ def snippet_translate(x):
if "nullptr" in x:
x = x.replace("nullptr", "None")
- ## Special Cases Rules
+ # # Special Cases Rules
xs = x.strip()
# Special case for 'main'
if xs.startswith("int main("):
@@ -298,8 +298,7 @@ def snippet_translate(x):
# with only alpha numeric content
if VAR4_PATTERN.search(xs) and not xs.endswith(")"):
v = x.rstrip()
- if (not v.endswith(" True") and not v.endswith(" False")
- and not v.endswith(" None")):
+ if (not v.endswith(" True") and not v.endswith(" False") and not v.endswith(" None")):
x = f"{v}()"
return dstrip(x)
diff --git a/tools/snippets_translate/override.py b/tools/snippets_translate/override.py
index c8f3d85d8..eab3f178e 100644
--- a/tools/snippets_translate/override.py
+++ b/tools/snippets_translate/override.py
@@ -80,33 +80,33 @@ def python_example_snippet_mapping():
/ "stringlistmodel.py")
for i in range(10):
snippet_id = str(i)
- result[(qt_path, snippet_id)] = pyside_path, snippet_id
+ result[(qt_path, snippet_id)] = pyside_path, snippet_id
qt_path = "qtbase/src/widgets/doc/snippets/qlistview-dnd/model.cpp"
pyside_path = (TUTORIAL_EXAMPLES_PATH / "modelviewprogramming"
/ "qlistview-dnd.py")
for i in range(11):
snippet_id = str(i)
- result[(qt_path, snippet_id)] = pyside_path, snippet_id
+ result[(qt_path, snippet_id)] = pyside_path, snippet_id
qt_path = "qtconnectivity/examples/bluetooth/heartrate_game/devicefinder.cpp"
pyside_path = EXAMPLES_PATH / "bluetooth" / "heartrate_game" / "devicefinder.py"
for i in range(5):
snippet_id = f"devicediscovery-{i}"
- result[(qt_path, snippet_id)] = pyside_path, snippet_id
+ result[(qt_path, snippet_id)] = pyside_path, snippet_id
qt_path = "qtconnectivity/examples/bluetooth/heartrate_game/devicehandler.cpp"
pyside_path = EXAMPLES_PATH / "bluetooth" / "heartrate_game" / "devicehandler.py"
for snippet_id in ["Connect-Signals-1", "Connect-Signals-2",
"Filter HeartRate service 2", "Find HRM characteristic",
"Reading value"]:
- result[(qt_path, snippet_id)] = pyside_path, snippet_id
+ result[(qt_path, snippet_id)] = pyside_path, snippet_id
qt_path = "qtconnectivity/examples/bluetooth/heartrate_server/main.cpp"
pyside_path = EXAMPLES_PATH / "bluetooth" / "heartrate_server" / "heartrate_server.py"
for snippet_id in ["Advertising Data", "Start Advertising", "Service Data",
"Provide Heartbeat"]:
- result[(qt_path, snippet_id)] = pyside_path, snippet_id
+ result[(qt_path, snippet_id)] = pyside_path, snippet_id
_python_example_snippet_mapping = result
diff --git a/tools/snippets_translate/tests/test_converter.py b/tools/snippets_translate/tests/test_converter.py
index efbedc7e9..70026b8d2 100644
--- a/tools/snippets_translate/tests/test_converter.py
+++ b/tools/snippets_translate/tests/test_converter.py
@@ -6,7 +6,7 @@ from converter import snippet_translate as st
def multi_st(lines):
- result = [st(l) for l in lines.split("\n")]
+ result = [st(line) for line in lines.split("\n")]
return "\n".join(result)
@@ -102,7 +102,7 @@ def test_cast():
== "elapsed = (elapsed + QTimer(sender()).interval()) % 1000"
)
assert (
- st("a = qobject_cast<type*>(data) * 9 + static_cast<int>(42)")
+ st("a = qobject_cast<type*>(data) * 9 + static_cast<int>(42)") # noqa: E126
== "a = type(data) * 9 + int(42)"
)
@@ -121,15 +121,15 @@ def test_double_colon():
def test_connects():
assert (
st("connect(button, &QPushButton::clicked, this, &MyClass::slotClicked);")
- == "button.clicked.connect(self.slotClicked)"
+ == "button.clicked.connect(self.slotClicked)"
)
assert (
st("connect(m_ui->button, &QPushButton::clicked, this, &MyClass::slotClicked);")
- == "m_ui.button.clicked.connect(self.slotClicked)"
+ == "m_ui.button.clicked.connect(self.slotClicked)"
)
assert (
st("connect(button.get(), &QPushButton::clicked, this, &MyClass::slotClicked);")
- == "button.clicked.connect(self.slotClicked)"
+ == "button.clicked.connect(self.slotClicked)"
)
@@ -204,7 +204,7 @@ def test_for():
assert st("for (int i = 0; i <= 10; i++)") == "for i in range(0, 11):"
assert st("for (int i = 10; i >= 0; i--)") == "for i in range(-1, 10, -1):"
- ## if contains "begin()" and "end()", do a 'for it in var'
+ # # if contains "begin()" and "end()", do a 'for it in var'
assert (
st(
"for (QHash<int, QString>::const_iterator it = hash.cbegin(),"
@@ -433,7 +433,8 @@ def test_special_cases():
# assert st("QDebug operator<<(QDebug dbg, const Message &message)") == "def __str__(self):"
# TODO: Maybe play with the format?
- # assert st('m_o.append(tr("version: %1.%2").arg(a).arg(b))') == 'm_o.append(tr("version: {1}.{2}".format(a, b)'
+ # assert st('m_o.append(tr("version: %1.%2").arg(a).arg(b))')
+ # == 'm_o.append(tr("version: {1}.{2}".format(a, b)'
def test_lambdas():