hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.54k stars 291 forks source link

Splitting long f strings containing hash sign (#) into multiple lines breaks code syntax #753

Closed pkv2a closed 2 weeks ago

pkv2a commented 2 weeks ago

Python Code

foo.py:

def foo:
    logger.info(f"some string padding some string padding some string padd {somedict['key1']}, more padding more paddin #: {somedict['dictkey2']}")

Command Line and Configuration

Not using any config files.

Command Line

$ ~/.local/bin/autopep8 foo.py 
def foo:
    logger.info(f"some string padding some string padding some string padd {
                #: {somedict['dictkey2']}")
                somedict['key1']}, more padding more paddin

Notice the second-to-last line should actually be the last line. The resulting formatted code is not syntactically correct.

Your Environment

hhatto commented 2 weeks ago

Thanks for reporting 👍

fix and v2.3.1 has been released. https://pypi.org/project/autopep8/2.3.1/