aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qtpy2cpp_lib/visitor.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-05-27 13:26:54 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-06-01 16:17:41 +0200
commit9d2779a12f1c71db26b3ddc81c6006d7f7244772 (patch)
tree68d80434a5551dc67c81132d03f3bb2f9157b655 /tools/qtpy2cpp_lib/visitor.py
parentcbc7d2a21b63f58144da0d5a42048b7b9dee1eb0 (diff)
qtpy2cpp: Improve error handling
Format messages in a file:line: format. Fix an error causing an exception. Pick-to: 6.3 Task-number: PYSIDE-1945 Change-Id: I16a1fd6daa96521adfe53f23090f61fbbc581e84 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'tools/qtpy2cpp_lib/visitor.py')
-rw-r--r--tools/qtpy2cpp_lib/visitor.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/tools/qtpy2cpp_lib/visitor.py b/tools/qtpy2cpp_lib/visitor.py
index 57a483191..4f9962624 100644
--- a/tools/qtpy2cpp_lib/visitor.py
+++ b/tools/qtpy2cpp_lib/visitor.py
@@ -27,9 +27,10 @@ class ConvertVisitor(ast.NodeVisitor, CppFormatter):
debug = False
- def __init__(self, output_file):
+ def __init__(self, file_name, output_file):
ast.NodeVisitor.__init__(self)
CppFormatter.__init__(self, output_file)
+ self._file_name = file_name
self._class_scope = [] # List of class names
self._stack = [] # nodes
self._debug_indent = 0
@@ -51,9 +52,10 @@ class ConvertVisitor(ast.NodeVisitor, CppFormatter):
super().generic_visit(node)
except Exception as e:
line_no = node.lineno if hasattr(node, 'lineno') else -1
- message = 'Error "{}" at line {}'.format(str(e), line_no)
+ error_message = str(e)
+ message = f'{self._file_name}:{line_no}: Error "{error_message}"'
warnings.warn(message)
- self._output_file.write(f'\n// {message}\n')
+ self._output_file.write(f'\n// {error_message}\n')
del self._stack[-1]
if self.debug:
self._debug_leave(node)
@@ -65,13 +67,14 @@ class ConvertVisitor(ast.NodeVisitor, CppFormatter):
def visit_Assign(self, node):
self._output_file.write('\n')
self.INDENT()
+ line_no = node.lineno if hasattr(node, 'lineno') else -1
for target in node.targets:
if isinstance(target, ast.Tuple):
- warnings.warn('List assignment not handled (line {}).'.
- format(node.lineno))
+ w = f"{self._file_name}:{line_no}: List assignment not handled."
+ warnings.warn(w)
elif isinstance(target, ast.Subscript):
- warnings.warn('Subscript assignment not handled (line {}).'.
- format(node.lineno))
+ w = f"{self._file_name}:{line_no}: Subscript assignment not handled."
+ warnings.warn(w)
else:
self._output_file.write(format_reference(target))
self._output_file.write(' = ')