New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error trying to format line with parameter assignment and generator #2551
Comments
I confirm this syntax seems valid in 3.9 (it wasn't in Python 3.8.6) Though it looks like this syntax is not supported by the current CPython parser. By the way the documentation about the usage of parentheses in assignment expression is still a work in progress python/cpython#23291 To workaround the issue: wrap the assignment |
up for 2022-10-09 on black 22.10.0: from typing import TypeVar, AsyncIterable
A = TypeVar("A")
async def enumerate(fa: AsyncIterable[A]) -> AsyncIterable[tuple[int, A]]:
i = -1
async for a in fa:
yield i := i + 1, a Result:
The parens workaround in #1898 does work: async def enumerate(fa: AsyncIterable[A]) -> AsyncIterable[tuple[int, A]]:
i = -1
async for a in fa:
yield (i := i + 1), a |
@isidentical would you be interested in taking a look at this issue? |
Yep, will look into it! Thanks for CC'ing me. |
Describe the bug
Black throws an error trying to format files containing a parameter assignment with a generator. This is valid Python code.
To Reproduce
Code sample:
Expected behavior
Black formats the file without errors. It seems to handle parameter assignment elsewhere just fine:
Environment (please complete the following information):
Does this bug also happen on main?
Yes
Additional context
None
The text was updated successfully, but these errors were encountered: