Skip to content
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

Preview crashes on await (yield) #3532

Closed
jakkdl opened this issue Jan 30, 2023 · 3 comments · Fixed by #3533
Closed

Preview crashes on await (yield) #3532

jakkdl opened this issue Jan 30, 2023 · 3 comments · Fixed by #3533
Assignees
Labels
C: crash Black is crashing C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. T: bug Something isn't working

Comments

@jakkdl
Copy link
Contributor

jakkdl commented Jan 30, 2023

Describe the bug
black --preview crashes on seeing await (yield)
This is certainly not good code or anything, but is code we have in one of our test files in flake8-trio. Non-preview black has no issues with it.

To Reproduce

For example, take this code:

async def foo():
    await (yield)

And run it with these arguments:

$ black --preview myfile.py 

The resulting error is:

error: cannot format myfile.py: blib2to3.pytree.Node object expected; got blib2to3.pytree.Leaf

Oh no! 💥 💔 💥
1 file failed to reformat.

Expected behavior

Not crashing

Environment

$ black --version
black, 22.12.0 (compiled: yes)
Python (CPython) 3.11.0
$ python --version
Python 3.11.0
$ uname -sro
Linux 6.1.1-arch1-1 GNU/Linux
@jakkdl jakkdl added the T: bug Something isn't working label Jan 30, 2023
@felix-hilden felix-hilden added C: crash Black is crashing C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. labels Jan 30, 2023
@JelleZijlstra
Copy link
Collaborator

Thanks! We'll fix this before the stable release.

@ichard26 ichard26 self-assigned this Jan 30, 2023
@JelleZijlstra
Copy link
Collaborator

Note this only repros with mypyc enabled. This is the stack trace (from black -v):

Traceback (most recent call last):
  File "src/black/__init__.py", line 770, in reformat_one
  File "src/black/__init__.py", line 810, in format_file_in_place
  File "src/black/__init__.py", line 926, in format_file_contents
  File "src/black/__init__.py", line 1073, in format_str
  File "src/black/__init__.py", line 1100, in _format_str_once
  File "src/black/nodes.py", line 169, in visit
  File "src/black/linegen.py", line 139, in visit_default
  File "src/black/nodes.py", line 175, in visit_default
  File "src/black/nodes.py", line 167, in visit
  File "src/black/linegen.py", line 265, in visit_async_stmt
  File "src/black/nodes.py", line 167, in visit
  File "src/black/linegen.py", line 222, in visit_suite
  File "src/black/linegen.py", line 139, in visit_default
  File "src/black/nodes.py", line 175, in visit_default
  File "src/black/nodes.py", line 167, in visit
  File "src/black/linegen.py", line 248, in visit_simple_stmt
  File "src/black/linegen.py", line 139, in visit_default
  File "src/black/nodes.py", line 175, in visit_default
  File "src/black/nodes.py", line 167, in visit
  File "src/black/linegen.py", line 294, in visit_power
  File "src/black/linegen.py", line 1075, in remove_await_parens
TypeError: blib2to3.pytree.Node object expected; got blib2to3.pytree.Leaf

I think I found the cause; it's a bad cast. I'll propose a fix.

JelleZijlstra added a commit to JelleZijlstra/black that referenced this issue Jan 31, 2023
@jakkdl
Copy link
Contributor Author

jakkdl commented Jan 31, 2023

Nice and quick, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: crash Black is crashing C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants