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

black internal error on line-broken == #4220

Closed
Jacobfaib opened this issue Feb 9, 2024 · 0 comments · Fixed by #4248
Closed

black internal error on line-broken == #4220

Jacobfaib opened this issue Feb 9, 2024 · 0 comments · Fixed by #4248
Labels
C: crash Black is crashing F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: bug Something isn't working

Comments

@Jacobfaib
Copy link

Jacobfaib commented Feb 9, 2024

Describe the bug

black crashes when encountering a type: ignore comment on a line-broken ==, where the == is on the first line.

To Reproduce

For example, take this code:

z = (
    x == # type: ignore[foo]
    y # type: ignore[foo]
  ) # <-- to trigger black

And run it with these arguments:

$ black file.py

The resulting error is:

error: cannot format -: 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: /var/folders/0m/7yv6pgt57vzdqfbzcr8lztkh0000gp/T/blk_zliifnke.log

And the diff:

--- src
+++ dst
@@ -110,8 +110,6 @@
         )  # /Compare
     )  # /If
   type_ignores=
     TypeIgnore(
     )  # /TypeIgnore
-    TypeIgnore(
-    )  # /TypeIgnore
 )  # /Module
\ No newline at end of file

Note: if you move the == to the second line:

z = (
    x # type: ignore[foo]
    == y # type: ignore[foo]
  ) # <-- to trigger black

then no problem.

Environment

  • Black's version:
$ black --version
black, 24.1.1 (compiled: yes)
Python (CPython) 3.11.7
  • OS and Python version:
$ python3 --version
Python 3.11.7
$ uname -v
Darwin Kernel Version 22.6.0: Sun Dec 17 22:13:25 PST 2023; root:xnu-8796.141.3.703.2~2/RELEASE_ARM64_T6020
@Jacobfaib Jacobfaib added the T: bug Something isn't working label Feb 9, 2024
@JelleZijlstra JelleZijlstra added C: crash Black is crashing F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. labels Feb 9, 2024
cobaltt7 added a commit to cobaltt7/black that referenced this issue Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: crash Black is crashing 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.

2 participants