Skip to content

runtime(python): Add f-string support - #14057

Closed
dkearns wants to merge 1 commit into
vim:masterfrom
dkearns:runtime-python-fstring-support
Closed

runtime(python): Add f-string support#14057
dkearns wants to merge 1 commit into
vim:masterfrom
dkearns:runtime-python-fstring-support

Conversation

@dkearns

@dkearns dkearns commented Feb 19, 2024

Copy link
Copy Markdown
Contributor

This is an another possible fix for #14033 building on @A4-Tacks work in #14048.

This is a work in progress.

@dkearns
dkearns force-pushed the runtime-python-fstring-support branch 5 times, most recently from 3401f52 to 4515592 Compare February 20, 2024 15:32
@dkearns

dkearns commented Feb 20, 2024

Copy link
Copy Markdown
Contributor Author

I ran some automated syntax testing of this PR against Python-3.12.2/Lib and it doesn't appear to break anything.

@Felixoid

Copy link
Copy Markdown

It looks broken on the following code:

import logging
import os
from typing import Any


def git_runner(*args: Any, **kwargs: Any) -> str:
    "nothing"
    return str(*args, **kwargs)


GIT_PREFIX = "git"


def commit_push_staged(pr_info: Any) -> None:
    "nothing"
    # It works ONLY for PRs, and only over ssh, so either
    # ROBOT_CLICKHOUSE_SSH_KEY should be set or ssh-agent should work
    assert pr_info.number
    if not pr_info.head_name == pr_info.base_name:
        # We can't push to forks, sorry folks
        return
    git_staged = git_runner("git diff --cached --name-only")
    if not git_staged:
        logging.info("No fixes are staged")
        return

    def push_fix() -> None:
        """
        Stash staged changes to commit them on the top of the PR's head.
        `pull_request` event runs on top of a temporary merge_commit, we need to avoid
        including it in the autofix
        """
        remote_url = pr_info.event["pull_request"]["base"]["repo"]["ssh_url"]
        head = pr_info.sha
        git_runner(f"{GIT_PREFIX} commit -m 'Automatic style fix'")
        fix_commit = git_runner("git rev-parse HEAD")
        logging.info(
            "Fetching PR's head, check it out and cherry-pick autofix: %s", head
        )
        git_runner(
            f"{GIT_PREFIX} fetch {remote_url} --no-recurse-submodules --depth=1 {head}"
        )
        git_runner(f"git reset --hard {head}")
        git_runner(f"{GIT_PREFIX} cherry-pick {fix_commit}")
        git_runner(f"{GIT_PREFIX} push {remote_url} HEAD:{pr_info.head_ref}")

    if os.getenv("ROBOT_CLICKHOUSE_SSH_KEY", ""):
        push_fix()
        return

    push_fix()

image

@dkearns

dkearns commented Sep 27, 2024

Copy link
Copy Markdown
Contributor Author

You need to run it as a replacement for the distributed file, not applied additionally in your ~/.vim/after/syntax/ directory. So, just place it in ~/.vim/syntax (unedited).

@dkearns
dkearns force-pushed the runtime-python-fstring-support branch 2 times, most recently from 6e64c27 to 21c6d8b Compare September 27, 2024 12:39
@Felixoid

Felixoid commented Sep 27, 2024

Copy link
Copy Markdown

Installed the latest version from 21c6d8b as curl -s https://raw.githubusercontent.com/vim/vim/21c6d8b5b6ef510c9c78b9dfb89a41146599505f/runtime/syntax/python.vim > ~/.vim/syntax/python.vim, and it looks good. Thanks!

image

@Felixoid

Copy link
Copy Markdown
VAR = (
    "placeholderplaceholderplaceholderplaceholderplaceholderplaceholderplaceholder"
    if not bool()
    else f"placeholder {bool()}"
)
if not VAR:
    logging.debug("placeholder")
    _ = VAR

Another broken code. The closing curly brace there {bool()} is "unrelated" to the opening one.

image

@dkearns

dkearns commented Sep 28, 2024

Copy link
Copy Markdown
Contributor Author

WFM. Assuming you removed ~/.vim/after/syntax/python.vim are there any other custom syntax commands being applied?

The parens after bool shouldn't be highlighted either.

@Felixoid

Felixoid commented Sep 28, 2024

Copy link
Copy Markdown

Yes, it looks to be broken together with https://github.com/luochen1990/rainbow

Is it something that I should bring to the plugin repo to address? As far as I get, the work here is not over yet.

@luochen1990

Copy link
Copy Markdown

Yes, it looks to be broken together with https://github.com/luochen1990/rainbow

Replied here: luochen1990/rainbow#198

@dkearns
dkearns force-pushed the runtime-python-fstring-support branch from 21c6d8b to 987337e Compare June 16, 2025 13:08
@dkearns
dkearns force-pushed the runtime-python-fstring-support branch 3 times, most recently from ef81525 to 99a220d Compare July 12, 2025 11:26
Fixes vim#14033.

Signed-off-by: Doug Kearns <dougkearns@gmail.com>
@jparise

jparise commented May 27, 2026

Copy link
Copy Markdown
Contributor

It looks like everything this covered is now supported in runtime/syntax/python.vim.

@chrisbra

Copy link
Copy Markdown
Member

thanks, closing then.

@chrisbra chrisbra closed this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants