From bb5c5e71f95c537ca2d19299b157a0bbf59e5279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Mon, 17 Oct 2022 21:50:58 +0200 Subject: [PATCH] fix: Don't strip too many parentheses around a call node PR #107: https://github.com/mkdocstrings/griffe/pull/107 --- src/griffe/agents/nodes.py | 4 ++-- tests/test_nodes.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/griffe/agents/nodes.py b/src/griffe/agents/nodes.py index a6588199..422ecc6e 100644 --- a/src/griffe/agents/nodes.py +++ b/src/griffe/agents/nodes.py @@ -1094,8 +1094,8 @@ def _get_sub_value(node: NodeSub) -> str: def _get_subscript_value(node: NodeSubscript) -> str: subscript = _get_value(node.slice) - if isinstance(subscript, str): - subscript = subscript.strip("()") + if isinstance(subscript, str) and subscript.startswith("(") and subscript.endswith(")"): + subscript = subscript[1:-1] return f"{_get_value(node.value)}[{subscript}]" diff --git a/tests/test_nodes.py b/tests/test_nodes.py index d9b7a038..c2628c41 100644 --- a/tests/test_nodes.py +++ b/tests/test_nodes.py @@ -190,6 +190,7 @@ def test_default_value_from_nodes(default): "o[x,y]", "o[x:y]", "o[x:y,z]", + "o[x, y(z)]", ], ) def test_building_value_from_nodes(expression):