Skip to content

Commit

Permalink
Merge pull request #754 from hhatto/fix-issue-753
Browse files Browse the repository at this point in the history
skip e501 fixed method for f-string line without aggressive option
  • Loading branch information
hhatto authored Jun 22, 2024
2 parents a906e0e + 7a66033 commit 24cea97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion 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 Expand Up @@ -4091,7 +4100,7 @@ def read_pyproject_toml(args, parser):
if config.get("tool", {}).get("autopep8") is None:
return None

config = config.get("tool").get("autopep8")
config = config.get("tool", {}).get("autopep8")

defaults = {}
option_list = {o.dest: o.type or type(o.default)
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 24cea97

Please sign in to comment.