Skip to content

Commit

Permalink
Added feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sumezulike committed Mar 14, 2024
1 parent 5f29c7c commit a1ba877
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 35 deletions.
4 changes: 3 additions & 1 deletion src/black/ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def sanitized_lines(
if not src_contents:
return []
good_lines = []
src_line_count = len(src_contents.splitlines())
src_line_count = src_contents.count("\n")
if not src_contents.endswith("\n"):
src_line_count += 1
for start, end in lines:
if start > src_line_count:
continue
Expand Down
34 changes: 0 additions & 34 deletions tests/data/cases/line_ranges_outside_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,3 @@ def foo1(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parame
def foo2(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
def foo3(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass
def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass

# Adding some unformated code covering a wide range of syntaxes.

if True:
# Incorrectly indented prefix comments.
pass

import typing
from typing import (
Any ,
)
class MyClass( object): # Trailing comment with extra leading space.
#NOTE: The following indentation is incorrect:
@decor( 1 * 3 )
def my_func( arg):
pass

try: # Trailing comment with extra leading space.
for i in range(10): # Trailing comment with extra leading space.
while condition:
if something:
then_something( )
elif something_else:
then_something_else( )
except ValueError as e:
unformatted( )
finally:
unformatted( )

async def test_async_unformatted( ): # Trailing comment with extra leading space.
async for i in some_iter( unformatted ): # Trailing comment with extra leading space.
await asyncio.sleep( 1 )
async with some_context( unformatted ):
print( "unformatted" )
7 changes: 7 additions & 0 deletions tests/test_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,10 @@ def test_sanitize(
4. pass
"""
assert sanitized == sanitized_lines(lines, source)

source_no_trailing_nl = """\
1. import re
2. def func(arg1,
3. arg2, arg3):
4. pass"""
assert sanitized == sanitized_lines(lines, source_no_trailing_nl)

0 comments on commit a1ba877

Please sign in to comment.