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

INTERNAL ERROR: *.pyi file + function + comment + ellipsis #1020

Closed
di opened this issue Sep 14, 2019 · 4 comments · Fixed by #3745
Closed

INTERNAL ERROR: *.pyi file + function + comment + ellipsis #1020

di opened this issue Sep 14, 2019 · 4 comments · Fixed by #3745
Labels
C: invalid code Black destroyed a valid Python file F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: bug Something isn't working

Comments

@di
Copy link
Member

di commented Sep 14, 2019

Seems like a minimal example requires:

  • a .pyi file
  • a comment after the function declaration
  • an ellipsis in the function body

example.pyi:

def f():
    # hi
    ...
$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G95

$ python --version
Python 3.7.4

$ python -m black --version
black.py, version 19.3b0

$ cat example.pyi
def f():
    # hi
    ...

$ python -m black example.pyi
error: cannot format example.pyi: INTERNAL ERROR: Black produced invalid code: expected an indented block (<unknown>, line 3). Please report a bug on https://github.com/ambv/black/issues.  This invalid output might be helpful: /var/folders/m_/ffctv9r113lb285667lc7fh800k0_0/T/blk_2fvut1n6.log
All done! 💥 💔 💥
1 file failed to reformat.

$ cat /var/folders/m_/ffctv9r113lb285667lc7fh800k0_0/T/blk_iqek_luy.log
  File "/Users/dustiningram/.pyenv/versions/3.7.4/lib/python3.7/site-packages/black.py", line 3388, in assert_equivalent
    dst_ast = ast.parse(dst)
  File "/Users/dustiningram/.pyenv/versions/3.7.4/lib/python3.7/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
def foobar():  # hi

...

Does also happen on master: Yes

$ python -m black --version
black.py, version 19.3b0+82.gae5588c

$ python -m black example.pyi
error: cannot format example.pyi: INTERNAL ERROR: Black produced invalid code: invalid syntax (<unknown>, line 2). Please report a bug on https://github.com/psf/black/issues.  This invalid output might be helpful: /var/folders/m_/ffctv9r113lb285667lc7fh800k0_0/T/blk_yzbb8_6s.log
Oh no! 💥 💔 💥
1 file failed to reformat.
@di
Copy link
Member Author

di commented Sep 14, 2019

Also possibly related, black will remove the comment entirely if the file is formatted a certain way:

$ cat example.pyi
def f(
    ):  # hi
    ...

$ python -m black example.pyi
reformatted example.pyi
All done! ✨ 🍰 ✨
1 file reformatted.

$ cat example.pyi
def f(): ...

@zsol zsol added T: bug Something isn't working C: invalid code Black destroyed a valid Python file labels Sep 14, 2019
@zsol
Copy link
Collaborator

zsol commented Sep 14, 2019

Thanks for reporting, I can also repro this

@jdherg-brilliant
Copy link

Just ran into this as well. Note that black behaves appropriately when pass is used instead of ..., but that of course contravenes the preferred syntax in PEP 484.

@JelleZijlstra JelleZijlstra added the F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. label May 30, 2021
@JelleZijlstra
Copy link
Collaborator

Still crashes. The behavior where comments are sometimes removed is tracked separately in #1239.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: invalid code Black destroyed a valid Python file F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants