astral-sh/ruff

Avoid raising S310 if user explicitly checks for URL scheme

Open

#7.918 geöffnet am 11. Okt. 2023

Auf GitHub ansehen
 (13 Kommentare) (11 Reaktionen) (0 zugewiesene Personen)Rust (2.088 Forks)batch import
help wantedrule

Repository-Metriken

Stars
 (47.527 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 3T 8h) (573 gemergte PRs in 30 T)

Beschreibung

  • A minimal code snippet that reproduces the bug.
import urllib.request


def foo(url: str) -> None:
    if not url.startswith(("https://", "http://")):
        raise ValueError
    req = urllib.request.Request(
        url,
        headers=headers,
        data=data,
        method=method,
    )
    resp = urllib.request.urlopen(req)

Also it would be great if ruff could recognize asserts (like assert url.startswith(("https://", "http://")))

  • The command you invoked (e.g., ruff /path/to/file.py --fix), ideally including the --isolated flag.

ruff --isolated --select S t.py

  • The current Ruff settings (any relevant sections from your pyproject.toml).

No pyproject.toml

  • The current Ruff version (ruff --version).

ruff 0.0.292

Contributor Guide