Skip to content

Commit

Permalink
skip e501 fixed method for f-string line without aggressive option
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Jun 22, 2024
1 parent 8b75604 commit 6454d39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -1943,11 +1943,20 @@ def _shorten_line(tokens, source, indentation, indent_word,
Multiple candidates will be yielded.
"""
in_string = False
for (token_type,
token_string,
start_offset,
end_offset) in token_offsets(tokens):

if IS_SUPPORT_TOKEN_FSTRING:
if token_type == tokenize.FSTRING_START:
in_string = True
elif token_type == tokenize.FSTRING_END:
in_string = False
if in_string:
continue

if (
token_type == tokenize.COMMENT and
not is_probably_part_of_multiline(previous_line) and
Expand Down
13 changes: 13 additions & 0 deletions test/test_autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -3941,6 +3941,19 @@ def test_e501_with_pep572_assignment_expressions(self):
with autopep8_context(line, options=['-aa']) as result:
self.assertEqual(line, result)

def test_e501_effected_with_fstring(self):
line = """\
def foo():
logger.info(f"some string padding some string padding some string padd {somedict['key1']}, more padding more paddin #: {somedict['dictkey2']}")
"""
fixed = """\
def foo():
logger.info(
f"some string padding some string padding some string padd {somedict['key1']}, more padding more paddin #: {somedict['dictkey2']}")
"""
with autopep8_context(line) as result:
self.assertEqual(fixed, result)

def test_e501_not_effected_with_fstring(self):
line = """\
connector = f"socks5://{user}:{password}:{url}:{port}"
Expand Down

0 comments on commit 6454d39

Please sign in to comment.