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 on a specific file #4018

Closed
zerothi opened this issue Nov 3, 2023 · 2 comments · Fixed by #4019
Closed

Internal error on a specific file #4018

zerothi opened this issue Nov 3, 2023 · 2 comments · Fixed by #4019
Labels
T: bug Something isn't working

Comments

@zerothi
Copy link

zerothi commented Nov 3, 2023

Describe the bug
black reports an internal error when formatting a specific file.

error: cannot format /home/nicpa/codes/sisl/src/sisl_toolbox/siesta/minimizer/_metric_siesta.py: INTERNAL ERROR: Black produced code that is not equivalent to the source.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /tmp/blk__3mh1ucd.log

To Reproduce

  1. Download this file
  2. Run black on the file. (I have done pip install -U black as of today!)

My pyproject.toml configuration file has this:

[tool.black]
line-length = 88
target-version = ["py38", "py39", "py310", "py311", "py312"]

The resulting error is:

error: cannot format /home/nicpa/codes/sisl/src/sisl_toolbox/siesta/minimizer/_metric_siesta.py: INTERNAL ERROR: Black produced code that is not equivalent to the source.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /tmp/blk__3mh1ucd.log

Here is the attached diff-log file:

--- src
+++ dst
@@ -2307,16 +2307,10 @@
                   body=
                     Expr(
                       value=
                         JoinedStr(
                           values=
-                            Constant(
-                              kind=
-                                None,  # NoneType
-                              value=
-                                '',  # str
-                            )  # /Constant
                             FormattedValue(
                               conversion=
                                 -1,  # int
                               format_spec=
                                 None,  # NoneType
@@ -3263,16 +3257,10 @@
                   body=
                     Expr(
                       value=
                         JoinedStr(
                           values=
-                            Constant(
-                              kind=
-                                None,  # NoneType
-                              value=
-                                '',  # str
-                            )  # /Constant
                             FormattedValue(
                               conversion=
                                 -1,  # int
                               format_spec=
                                 None,  # NoneType
@@ -4273,16 +4261,10 @@
                   body=
                     Expr(
                       value=
                         JoinedStr(
                           values=
-                            Constant(
-                              kind=
-                                None,  # NoneType
-                              value=
-                                '',  # str
-                            )  # /Constant
                             FormattedValue(
                               conversion=
                                 -1,  # int
                               format_spec=
                                 None,  # NoneType

Expected behavior

Environment

  • Black's version:

    black --version
    black, 23.10.1 (compiled: yes)
    Python (CPython) 3.11.6

  • OS and Python version: Linux/debian, Python 3.11.6

@zerothi zerothi added the T: bug Something isn't working label Nov 3, 2023
@hauntsaninja
Copy link
Collaborator

Thanks for the report! Minimised repro:

def foo(energy_str):
    f""" {'.'.join(energy_str)} metric """

@zerothi
Copy link
Author

zerothi commented Nov 3, 2023

Thanks for the report! Minimised repro:

def foo(energy_str):
    f""" {'.'.join(energy_str)} metric """

thanks for hunting this down, that was beyond my expertise! :)

hauntsaninja added a commit to hauntsaninja/black that referenced this issue Nov 3, 2023
Python does not consider f-strings to be docstrings, so we probably
shouldn't be formatting them as such

Fixes psf#4018

Despite its name, I think docstring_preview.py might be testing stable
style, which this unfortunately does change
JelleZijlstra pushed a commit that referenced this issue Nov 7, 2023
Python does not consider f-strings to be docstrings, so we probably
shouldn't be formatting them as such

Fixes #4018

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
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

Successfully merging a pull request may close this issue.

2 participants