Skip to content

Visual indent changed for certain continued strings #761

Open
@avancil

Description

@avancil

Certain strings, wrapped with a continuation character, are getting changed with autopep8, even though pycodestyle has no issue with them, and they are PEP8 compliant.

In the code below, autopep8 wants to realign my_str. Notably:

  • This issue was NOT seen with autopep8 2.3.1 running in Python 3.10.14. It DOES show up with autopep8 2.3.1 and Python 3.12.4.
  • This issue does not show up if the f-string is not used.
  • This issue does not show up if the string is at the module level (not indented).

Python Code

def my_fn():
    """Do the thing."""
    foo = "foo"
    my_str = f"lorem ipsum lorem ipsum lorem ipsum {foo}" \
             "lorem ipsum lorem ipsum lorem ipsum"

    print(my_str)

Command Line

$ pyenv local 3.12.4
$ autopep8 --diff temp.py 
--- original/temp.py
+++ fixed/temp.py
@@ -5,6 +5,6 @@
 
 foo = "foo"
 my_str = f"lorem ipsum lorem ipsum lorem ipsum {foo}" \
-         "lorem ipsum lorem ipsum lorem ipsum"
+    "lorem ipsum lorem ipsum lorem ipsum"
 
 print(my_str)
$ pycodestyle temp.py
$ pip list | grep autopep8
autopep8                    2.3.1
$ pyenv local 3.10.14
$ autopep8 --diff temp.py 
$
$ pip list | grep autopep8
autopep8                    2.3.1

Your Environment

  • Python version: 3.12.4
  • autopep8 version: 2.3.1
  • Platform: Linux (Ubuntu 24.04)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions