Skip to content

str.format(): issue with parsing parentheses #3356

@SkeneZr

Description

@SkeneZr

I think there's a bug in the str.format() function, following the please update from version 16.19.0 to version 17.14.0, there's a regression on my use of the str.format() function:

In older version, I did something like this:

    cmd = """
    cat > $OUT << EOF
{{
  "name": "{name}",
  "version": "{version}",
}}
EOF
  """.format(
        name = API_NAME,
        version = API_VERSION,
    ),

I got this:

{
  "name": "api_name",
  "version": "X.1.0",
}

but after updating, I got:

{{
  "name": "{name}",
  "version": "X.1.0",
}}

I tried several modifications to find a solution, with something like this:

    cmd = """
    cat > $OUT << EOF
{
  "name": "{name}",
  "version": "{version}",
}
EOF
  """.format(
        name = NAME,
        version = VERSION,
    ),

with this result:

{
  "name": "{name}",
  "version": "X.1.0",
}

If I change order like this:

    cmd = """
    cat > $OUT << EOF
{
  "version": "{version}",
  "name": "{name}",
}
EOF
  """.format(
        name = NAME,
        version = VERSION,
    ),

result:

{
  "version": "{version}",
  "name": "api_name",
}

finally, I had a brace:

    cmd = """
    cat > $OUT << EOF
{
  "name": "}{name}",
  "version": "{version}",
}
EOF
  """.format(
        name = NAME,
        version = VERSION,
    ),

result:

{
  "name": "}api_name",
  "version": "X.1.0",
}

So maybe I miss understood something about str.format() and skipping brace, or this function don't skip any opened brace and wait a closed brace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugstarterGood starter issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions