psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
37.6k stars 2.38k forks source link

Advice (UFMT) command-failed Failed due to ASTSafetyError #4364

Closed hippocookie closed 2 weeks ago

hippocookie commented 2 weeks ago

Describe the bug

Running UFMT lint on PyTorch main branch code, and has following error message.

$ lintrunner -a --take UFMT test/quantization/*/ Warning: Could not find a lintrunner config at: '.lintrunner.private.toml'. Continuing without using configuration file. WARNING: The init commands have changed since you last ran lintrunner. You may need to run lintrunner init.

Lint for test/quantization/fx/test_quantize_fx.py:

Advice (UFMT) command-failed Failed due to ASTSafetyError: 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_d666mo2u.log

/tmp/blk_d666mo2u.log

  1 --- src
  2 +++ dst
  3 @@ -187103,11 +187103,11 @@
  4                      value=
  5                      Constant(
  6                          kind=
  7                          None,  # NoneType
  8                          value=
  9 -                        ' Test for function conv and functional conv + relu\n            ',  # str
 10 +                        'Test for function conv and functional conv + relu',  # str
 11                      )  # /Constant
 12                  )  # /Expr
 13                  Assign(
 14                      targets=
 15                      Name(

To Reproduce

Download source code from PyTorch github repo

git clone https://github.com/pytorch/pytorch.git

Remove below escape config in file .lintrunner.toml, in exclude_patterns of ufmt linter config section

'test/quantization/fx/test_quantize_fx.py',

Run lint command

lintrunner -a --take UFMT test/quantization/*/

Expected behavior

Environment

Get versions info from conda

Additional context

JelleZijlstra commented 2 weeks ago

I believe we fixed this recently, could you try with the latest release?

If not, could you isolate the failure to a single file you can attach here?

zsol commented 2 weeks ago

I bumped into this as well. Minimal repro is:

for i in _:
    """ foo"""

But it's been fixed in 24.4.0