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: Black produced invalid code: f-string: expecting '}' #4151

Closed
max-wittig opened this issue Jan 12, 2024 · 7 comments
Closed
Labels
T: bug Something isn't working

Comments

@max-wittig
Copy link

Describe the bug

Internal crash

To Reproduce

Run the code down below

For example, take this code:

  File "src/black/__init__.py", line 1476, in assert_equivalent
  File "src/black/parsing.py", line 140, in parse_ast
email = "test@example.com"
query_params = UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
    filter=f"mail eq '{email}' or startswith(userPrincipalName, '{email.split("
    @ ")[0]}')",
    count=True,  # required
)

And run it with these arguments:

$ black .

The resulting error is:

[> cannot format file.py: INTERNAL ERROR: ...](error: cannot format whatever.py: INTERNAL ERROR: Black produced invalid code: f-string: expecting '}' (, line 3). Please report a bug on https://github.com/psf/black/issues. This invalid output might be helpful: /var/folders/lg/s80890fd1ts6s1w69c8lg03m0000gn/T/blk_jssqz16j.log)

Expected behavior

It should format correctly

Environment

  • Black's version: 23.12.1
  • OS and Python version: macOS 14.2.1, Python (CPython) 3.12.1
@max-wittig max-wittig added the T: bug Something isn't working label Jan 12, 2024
@hauntsaninja
Copy link
Collaborator

Duplicate of #3746

@hauntsaninja hauntsaninja marked this as a duplicate of #3746 Jan 12, 2024
@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jan 12, 2024
@max-wittig
Copy link
Author

@hauntsaninja Hi! This is not 3.12 code. This is normal f string formatting.

@JelleZijlstra
Copy link
Collaborator

Could you share what your input code was?

@max-wittig
Copy link
Author

max-wittig commented Jan 12, 2024

As listed above. Just put that into a file and try.

email = "test@example.com"
query_params = UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
    filter=f"mail eq '{email}' or startswith(userPrincipalName, '{email.split("
    @ ")[0]}')",
    count=True,  # required
)

@max-wittig
Copy link
Author

Ahh but maybe this can be closed. It's also detected as a SyntaxError now, but maybe the message is wrong?

    filter=f"mail eq '{email}' or startswith(userPrincipalName, '{email.split("@")[0]}')",
                                                                               ^
SyntaxError: f-string: unmatched '('

@JelleZijlstra
Copy link
Collaborator

That code is valid only in 3.12+, so Shantanu was correct in closing this.

@max-wittig
Copy link
Author

Okay sorry. I didn't know that I wrote 3.12 code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants