Skip to content

Avoid raising S310 on safe f-strings #12245

@dscorbett

Description

@dscorbett

Given this input file (s310_fstring.py):

from urllib.request import urlopen
foo = "foo"
urlopen(f"https://www.example.com/{foo}")

Ruff reports a violation of rule S310.

$ ruff check --select S310 --output-format concise s310_fstring.py
s310_fstring.py:3:1: S310 Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.
Found 1 error.

Even though the argument is an f-string, Ruff should be able to detect that it begins with a permitted scheme. Compare #8040.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedContributions especially welcomeruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions