Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip e501 fixed method for f-string line without aggressive option #754

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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