This rule raises an issue when the only argument of a call is an unparenthesized generator expression whose element is a starred expression, such as f(*x for x in groups) (Python 3.15+, PEP 798).

This syntax represents one generator argument. It can be mistaken for positional argument unpacking.

Why is this an issue?

Recent versions of the language allow an iterable-expansion expression as the element of a generator expression. In a call written with a leading expansion marker immediately before a generator expression, the call receives one generator that produces the flattened elements. It does not expand that generator into several positional arguments.

Without parentheses, this meaning is difficult to see. A reader may interpret the leading expansion marker as call-site argument unpacking, especially because expanding an iterable directly into a function call is a common pattern.

Add parentheses to show the intended operation. Parenthesize the generator expression to pass one flattened generator argument. Use an additional expansion marker outside those parentheses when the generator itself must be unpacked into positional arguments.

What is the potential impact?

Ambiguous call syntax can lead to incorrect reviews, maintenance mistakes, or changes that alter how arguments are passed. Explicit parentheses make the call’s argument-passing behavior easier to understand.

How to fix it

Review the intended argument-passing behavior. If the function should receive one flattened generator as its only argument, add parentheses around the generator.

Code examples

Noncompliant code example

result = f(*x for x in groups)  # Noncompliant

Compliant solution

result = f((*x for x in groups))

Noncompliant code example

result = f(*x for x in groups)  # Noncompliant

Compliant solution

result = f(*(*x for x in groups))  # unpacks the flattened elements into positional arguments

Resources

Documentation