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

Auto-formatting inside f-strings #179

Closed
amirstm opened this issue Oct 15, 2023 · 4 comments
Closed

Auto-formatting inside f-strings #179

amirstm opened this issue Oct 15, 2023 · 4 comments
Assignees
Labels
info-needed Issue requires more information from poster triage-needed

Comments

@amirstm
Copy link

amirstm commented Oct 15, 2023

Hey.
The latest version of the extension has a problem that edits inside python f-strings. For instance:
Line of code before formatting:
connector = f"socks5://{user}:{password}:{url}:{port}"
Line after saving with the formatter enabled:
connector = f"socks5: //{user}: {password}: {url}: {port}"

@karthiknadig
Copy link
Member

@amirstm I am not able to repro this locally. Can you run this from the command line and see if this is actually coming from autopep8?
image

from the logs it looks like it is processing it as expected:

2023-10-16 08:28:44.746 [info] [Trace - 8:28:44 AM] Sending notification '$/setTrace'.
2023-10-16 08:28:44.746 [info] Params: {
    "value": "verbose"
}


2023-10-16 08:28:54.762 [info] [Trace - 8:28:54 AM] Sending request 'textDocument/formatting - (1)'.
2023-10-16 08:28:54.762 [info] Params: {
    "textDocument": {
        "uri": "file:///c%3A/GIT/formatters/vscode-autopep8/bundled/tool/something.py"
    },
    "options": {
        "tabSize": 4,
        "insertSpaces": true
    }
}


2023-10-16 08:28:54.779 [info] [Trace - 8:28:54 AM] Received notification 'window/logMessage'.
2023-10-16 08:28:54.780 [info] Params: {
    "type": 4,
    "message": "c:\\GIT\\formatters\\vscode-autopep8\\.venv\\Scripts\\python.exe -m autopep8 -"
}


2023-10-16 08:28:54.780 [info] c:\GIT\formatters\vscode-autopep8\.venv\Scripts\python.exe -m autopep8 -
2023-10-16 08:28:54.781 [info] [Trace - 8:28:54 AM] Received notification 'window/logMessage'.
2023-10-16 08:28:54.781 [info] Params: {
    "type": 4,
    "message": "CWD Server: c:\\GIT\\formatters\\vscode-autopep8"
}


2023-10-16 08:28:54.781 [info] CWD Server: c:\GIT\formatters\vscode-autopep8
2023-10-16 08:28:55.930 [info] [Trace - 8:28:55 AM] Received notification 'window/logMessage'.
2023-10-16 08:28:55.930 [info] Params: {
    "type": 4,
    "message": "file:///c%3A/GIT/formatters/vscode-autopep8/bundled/tool/something.py :\r\n****************************************************************************************************\r\nconnector = f\"socks5://{user}:{password}:{url}:{port}\"\r\n****************************************************************************************************\r\n"
}


2023-10-16 08:28:55.930 [info] file:///c%3A/GIT/formatters/vscode-autopep8/bundled/tool/something.py :
****************************************************************************************************
connector = f"socks5://{user}:{password}:{url}:{port}"
****************************************************************************************************

image

You can get detailed logs by adding the following to your user settings:
image

@karthiknadig karthiknadig self-assigned this Oct 16, 2023
@karthiknadig karthiknadig added the info-needed Issue requires more information from poster label Oct 16, 2023
@amirstm
Copy link
Author

amirstm commented Oct 16, 2023

@karthiknadig Thank you for your response. I ran the following command from the command line and it returned the same output.
image
the logs look like this:

2023-10-16 20:21:30.112 [info] [Trace - 8:21:30 PM] Sending request 'textDocument/formatting - (1)'.
2023-10-16 20:21:30.112 [info] Params: {
    "textDocument": {
        "uri": "file:///home/amirs/test/test.py"
    },
    "options": {
        "tabSize": 4,
        "insertSpaces": true
    }
}


2023-10-16 20:21:30.116 [info] [Trace - 8:21:30 PM] Received notification 'window/logMessage'.
2023-10-16 20:21:30.116 [info] Params: {
    "type": 4,
    "message": "/bin/python -m autopep8 -"
}


2023-10-16 20:21:30.116 [info] /bin/python -m autopep8 -
2023-10-16 20:21:30.116 [info] [Trace - 8:21:30 PM] Received notification 'window/logMessage'.
2023-10-16 20:21:30.116 [info] Params: {
    "type": 4,
    "message": "CWD Server: /home/amirs/test"
}


2023-10-16 20:21:30.116 [info] CWD Server: /home/amirs/test
2023-10-16 20:21:30.159 [info] [Trace - 8:21:30 PM] Received notification 'window/logMessage'.
2023-10-16 20:21:30.159 [info] Params: {
    "type": 4,
    "message": "file:///home/amirs/test/test.py :\r\n****************************************************************************************************\r\nconnector = f\"socks5: //{user}: {password}: {url}: {port}\"\n\r\n****************************************************************************************************\r\n"
}


2023-10-16 20:21:30.159 [info] file:///home/amirs/test/test.py :
****************************************************************************************************
connector = f"socks5: //{user}: {password}: {url}: {port}"

****************************************************************************************************

2023-10-16 20:21:30.160 [info] [Trace - 8:21:30 PM] Received response 'textDocument/formatting - (1)' in 48ms.
2023-10-16 20:21:30.160 [info] Result: [
    {
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 1,
                "character": 0
            }
        },
        "newText": "connector = f\"socks5: //{user}: {password}: {url}: {port}\"\n"
    }
]


2023-10-16 20:21:30.206 [info] [Trace - 8:21:30 PM] Sending notification 'textDocument/didChange'.
2023-10-16 20:21:30.206 [info] Params: {
    "textDocument": {
        "uri": "file:///home/amirs/test/test.py",
        "version": 8
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 47
                },
                "end": {
                    "line": 0,
                    "character": 47
                }
            },
            "rangeLength": 0,
            "text": " "
        },
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 41
                },
                "end": {
                    "line": 0,
                    "character": 41
                }
            },
            "rangeLength": 0,
            "text": " "
        },
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 30
                },
                "end": {
                    "line": 0,
                    "character": 30
                }
            },
            "rangeLength": 0,
            "text": " "
        },
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 21
                },
                "end": {
                    "line": 0,
                    "character": 21
                }
            },
            "rangeLength": 0,
            "text": " "
        }
    ]
}

I should point out that I am using python3.12, and when I tried the same with python3.11 the issue didn't exist.

@karthiknadig
Copy link
Member

@amirstm This is a bug on autopep8 itself. So, please file this on https://github.com/hhatto/autopep8/issues

@karthiknadig
Copy link
Member

Closing this against the upstream issue hhatto/autopep8#712

@karthiknadig karthiknadig closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster triage-needed
Projects
None yet
Development

No branches or pull requests

2 participants