Skip to content

--line-ranges formats entire file when ranges are at EOF #4264

@jvacek

Description

@jvacek

Line ranges seem to format an entire file when the range goes to the end of the file

microsoft/vscode-black-formatter#472

  • Take a file that is unformatted
  • Set the line ranges to any portion as long as the last line is EOF
  • The entire file is formatted

For example, take this code:

** Ensure empty last line **

abc = 'def'
ghi= 'jkl'
mno='pqr'
stu='vwx'

And run it with these arguments:

black --line-ranges 4-5 file.py

The resulting error is:

> cannot format file.py: INTERNAL ERROR: ...

Expected behavior

Only stu='vwx' being formatted, and not lines 1-3

Environment

  • Black's version: 24.2.0
  • OS and Python version: MacOS 14.3.1, Python 3.10.3

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions