Skip to content

Commit b0bec7e

Browse files
committed
[FIX] pylint_odoo: Fix parsing dictionary from manifest
The following code: - `# e.g. {"key": "" or ""}` It is parsed correctly the node code But `ast.literal_eval` shows the following traceback: ```txt Exception on node <Dict.dict l.3 at 0x10ef6aba0> Traceback (most recent call last): File "pylint/utils/ast_walker.py", line 91, in walk callback(astroid) ~~~~~~~~^^^^^^^^^ File "pylint_odoo/checkers/odoo_addons.py", line 1034, in visit_dict manifest_dict = ast.literal_eval(node.as_string()) File "3.13/lib/python3.13/ast.py", line 114, in literal_eval return _convert(node_or_string) File "3.13/lib/python3.13/ast.py", line 103, in _convert return dict(zip(map(_convert, node.keys), map(_convert, node.values))) File "3.13/lib/python3.13/ast.py", line 113, in _convert return _convert_signed_num(node) File "3.13/lib/python3.13/ast.py", line 87, in _convert_signed_num return _convert_num(node) File "3.13/lib/python3.13/ast.py", line 78, in _convert_num _raise_malformed_node(node) ~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "3.13/lib/python3.13/ast.py", line 75, in _raise_malformed_node raise ValueError(msg + f': {node!r}') ValueError: malformed node or string on line 1: <ast.BoolOp object at 0x1104df790> ````
1 parent fc39ad4 commit b0bec7e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/pylint_odoo/checkers/odoo_addons.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,12 @@ def visit_dict(self, node):
10291029
node.parent, nodes.Expr
10301030
):
10311031
return
1032-
manifest_dict = ast.literal_eval(node.as_string())
1032+
try:
1033+
manifest_dict = ast.literal_eval(node.as_string())
1034+
except ValueError:
1035+
# There is code that the node is formed but literal_eval raises error
1036+
# e.g. {"key": "" or ""}
1037+
return
10331038
manifest_keys_nodes = {
10341039
key_node.value: key_node for key_node, _value in node.items if isinstance(key_node, nodes.Const)
10351040
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Verify a dictionary parsed correctly as node but raising error as literal_eval
2+
{
3+
"key": "" or "",
4+
}

0 commit comments

Comments
 (0)