Skip to content

Commit cbdb6a9

Browse files
committed
fix: Don't add parentheses around comprehension target (implicit) tuple
Issue-mkdocstrings-python-311: mkdocstrings/python#311
1 parent 3a6dc36 commit cbdb6a9

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/griffe/_internal/expressions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ def _build_compare(node: ast.Compare, parent: Module | Class, **kwargs: Any) ->
11641164

11651165
def _build_comprehension(node: ast.comprehension, parent: Module | Class, **kwargs: Any) -> Expr:
11661166
return ExprComprehension(
1167-
_build(node.target, parent, **kwargs),
1167+
_build(node.target, parent, compr_target=True, **kwargs),
11681168
_build(node.iter, parent, **kwargs),
11691169
[_build(condition, parent, **kwargs) for condition in node.ifs],
11701170
is_async=bool(node.is_async),
@@ -1325,7 +1325,7 @@ def _build_subscript(
13251325
*,
13261326
parse_strings: bool = False,
13271327
literal_strings: bool = False,
1328-
in_subscript: bool = False, # noqa: ARG001
1328+
subscript_slice: bool = False, # noqa: ARG001
13291329
**kwargs: Any,
13301330
) -> Expr:
13311331
left = _build(node.value, parent, **kwargs)
@@ -1340,22 +1340,23 @@ def _build_subscript(
13401340
parent,
13411341
parse_strings=True,
13421342
literal_strings=literal_strings,
1343-
in_subscript=True,
1343+
subscript_slice=True,
13441344
**kwargs,
13451345
)
13461346
else:
1347-
slice_expr = _build(node.slice, parent, in_subscript=True, **kwargs)
1347+
slice_expr = _build(node.slice, parent, subscript_slice=True, **kwargs)
13481348
return ExprSubscript(left, slice_expr)
13491349

13501350

13511351
def _build_tuple(
13521352
node: ast.Tuple,
13531353
parent: Module | Class,
13541354
*,
1355-
in_subscript: bool = False,
1355+
subscript_slice: bool = False,
1356+
compr_target: bool = False,
13561357
**kwargs: Any,
13571358
) -> Expr:
1358-
return ExprTuple([_build(el, parent, **kwargs) for el in node.elts], implicit=in_subscript)
1359+
return ExprTuple([_build(el, parent, **kwargs) for el in node.elts], implicit=subscript_slice or compr_target)
13591360

13601361

13611362
def _build_unaryop(node: ast.UnaryOp, parent: Module | Class, **kwargs: Any) -> Expr:

tests/test_expressions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def func[Z](arg1: T, arg2: Y): pass
233233
assert module["C.func"].parameters["arg2"].annotation.canonical_path == "Y"
234234

235235

236-
@pytest.mark.xfail(reason="Tuple in comprehension target is not yet implicit")
237236
def test_render_dict_comprehension() -> None:
238237
"""Assert dict comprehensions are rendered correctly."""
239238
with temporary_visited_module(

0 commit comments

Comments
 (0)