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 when formatting bracketed return annotations #2381

Closed
AntObr opened this issue Jul 19, 2021 · 2 comments · Fixed by #2384
Closed

Internal Error when formatting bracketed return annotations #2381

AntObr opened this issue Jul 19, 2021 · 2 comments · Fixed by #2384
Labels
C: crash Black is crashing C: invalid code Black destroyed a valid Python file T: bug Something isn't working

Comments

@AntObr
Copy link

AntObr commented Jul 19, 2021

Describe the bug

When formatting a *.py file with bracketed returns annotations the error below is returned:

error: cannot format test.py: INTERNAL ERROR: Black produced code that is not equivalent to the source on pass 1.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /var/folders/9m/cps802s92k77tpy3z1w56hxr0000gn/T/blk_fu7q8w3k.log

To Reproduce

For example:
test.py

returning_a_deeply_nested_import_of_a_type = str

def some_method_with_a_really_long_name() -> (
    returning_a_deeply_nested_import_of_a_type
):
    pass

run black -l 79 on the above file

Expected behavior

The file is formatted and the bracketed form is maintained.

Environment (please complete the following information):

  • Version: main
  • OS and Python version: macOS v11.4/Python 3.9.4

Does this bug also happen on main?

@felix-hilden
Copy link
Collaborator

Hi, thanks for the report! Just for easy inspection, I've reproduced this on the playground.

@felix-hilden felix-hilden added T: bug Something isn't working C: crash Black is crashing C: invalid code Black destroyed a valid Python file labels Jul 19, 2021
@ichard26
Copy link
Collaborator

Yeah thanks for the report, that trailing comma Black tries to add actually changes the type annotation's type to a tuple ... good thing the AST equivalence check caught that :)

This should be fixed by this PR: #2384.

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: invalid code Black destroyed a valid Python file T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants