Skip to content

Ruff 0.10 #16600

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

Merged
merged 43 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7514e08
Bump alpine default tag to 3.21 (#16456)
samypr100 Mar 10, 2025
5177ed4
[formatter] Stabilize fix for single-with-item formatting with traili…
MichaReiser Mar 10, 2025
0252fad
Server: Remove log notification for `printDebugInformation` command (…
dhruvmanila Mar 11, 2025
dbde8d8
[`flake8-bandit`] Move `unsafe-markup-use` from `RUF035` to `S704` (#…
Daverball Mar 11, 2025
8d9fadf
[`flake8-builtins`] Remove `builtins-` prefix from option names (#16092)
InSyncWithFoo Mar 11, 2025
0a8c9c5
[`flake8-comprehensions`] Stabilize `unnecessary-dict-comprehension-f…
ntBre Mar 11, 2025
1ff7614
[`FastAPI`] Stabilize `fast-api-unused-path-parameter` (`FAST003`) (#…
ntBre Mar 11, 2025
7073d86
[`pylint`] Stabilize `shallow-copy-environ` (`PLW1507`) (#16627)
ntBre Mar 11, 2025
4fb1d6b
[`pylint`] Stabilize `len-test` (`PLC1802`) (#16626)
ntBre Mar 11, 2025
934a65b
[ruff-0.10] [`flake8-pyi`] Stabilize preview-mode behaviours for `cus…
AlexWaygood Mar 11, 2025
94ee8c7
[`flake8-simplify`] Stabilize `split-static-string` (`SIM905`) (#16631)
ntBre Mar 11, 2025
9c819ab
[`pyupgrade`] Stabilize `non-pep646-unpack` (`UP044`) (#16632)
ntBre Mar 11, 2025
a13d56a
[`flake8-builtins`] Default to non-strict checking (`A005`) (#16125)
ntBre Mar 11, 2025
ee33971
Make noqa parsing consistent and more robust (#16483)
dylwil3 Mar 11, 2025
fba56a7
Add missing unit tests for `# noqa:`-like cases (#16659)
InSyncWithFoo Mar 12, 2025
3944556
[`flake8-type-checking`] Stabilize `unquoted-type-alias` (`TC007`) (#…
ntBre Mar 12, 2025
e4b298a
[`flake8-use-pathlib`] Stabilize `os-listdir` (`PTH208`) (#16642)
ntBre Mar 12, 2025
7e2810b
[`ruff`] Stabilize `invalid-assert-message-literal-argument` (`RUF040…
ntBre Mar 12, 2025
30c8320
[`ruff`] Stabilize `unnecessary-cast-to-int` (`RUF046`) (#16649)
ntBre Mar 12, 2025
e02e174
[`ruff`] Stabilize `map-int-version-parsing` (`RUF048`) (#16653)
ntBre Mar 12, 2025
958a873
[`flake8-logging`] Stabilize `root-logger-call` (`LOG015`) (#16654)
ntBre Mar 12, 2025
53fd1ed
[`flake8-bugbear`] Stabilize `batched-without-explicit-strict` (`B911…
ntBre Mar 12, 2025
df9cf0e
[`ruff`] Stabilize `if-key-in-dict-del` (`RUF051`) (#16658)
ntBre Mar 12, 2025
ba2dfb8
Add missing unit tests for `# noqa: A`-like cases (#16677)
InSyncWithFoo Mar 12, 2025
765ce10
[`flake8-use-pathlib`] Stabilize `invalid-pathlib-with-suffix` (`PTH2…
ntBre Mar 12, 2025
b70743b
[`ruff`] Stabilize `unnecessary-nested-literal` (`RUF041`) (#16648)
ntBre Mar 12, 2025
4afb5da
Use inline snapshots in `# noqa` unit tests (#16687)
InSyncWithFoo Mar 12, 2025
1b789e3
[`flake8-datetimez`] Stabilize `datetime-min-max` (`DTZ901`) (#16635)
ntBre Mar 12, 2025
1037bec
[`flake8-bandit`] Stabilize `unsafe-markup-use` (`S704`) (#16643)
ntBre Mar 12, 2025
35f76a9
[`flake8-type-checking`] Stabilize `runtime-cast-value` (`TC006`) (#1…
ntBre Mar 12, 2025
93406e4
[`pyupgrade`]: Deprecate `non-pep604-isinstance` (`UP038`) (#16681)
MichaReiser Mar 13, 2025
1881550
[`flake8-pytest-style`] Allow for loops with empty bodies (`PT012`, `…
MichaReiser Mar 13, 2025
47b4b7c
[`pylint`] Detect invalid default value type for `os.environ.get` (`P…
MichaReiser Mar 13, 2025
12ce8bc
Stabilize FURB169 preview behavior (#16666)
MichaReiser Mar 13, 2025
bb17271
[`pep8-naming`]: Ignore methods decorated with `@typing.override` (`i…
MichaReiser Mar 13, 2025
629f42d
Consider all `TYPE_CHECKING` symbols for type-checking blocks (#16669)
MichaReiser Mar 13, 2025
fc54409
[`pyupgrade`]: Improve diagnostic range for `redundant-open-mode` (`U…
MichaReiser Mar 13, 2025
1d9d028
[`flake8-simplify`] Avoid double negation in fixes (`SIM103`) (#16684)
MichaReiser Mar 13, 2025
36085d8
[`flake8-bandit`] Deprecate `suspicious-xmle-tree-usage` (`S320`) (#1…
MichaReiser Mar 13, 2025
6bf595e
[`flake8-pyi`] Stabilize fix for `unused-private-type-var` (`PYI018`)…
MichaReiser Mar 13, 2025
2f46a46
[`pylint`/`pep8-naming`] Check `__new__` argument name in `bad-static…
MichaReiser Mar 13, 2025
cf04d9c
[`pylint`] Improve `repeated-equality-comparison` fix to use a `set` …
MichaReiser Mar 13, 2025
851427a
[`pylint`] Better inference for `str.strip` (`PLE310`) (#16671)
MichaReiser Mar 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
# Mapping of base image followed by a comma followed by one or more base tags (comma separated)
# Note, org.opencontainers.image.version label will use the first base tag (use the most specific tag first)
image-mapping:
- alpine:3.20,alpine3.20,alpine
- alpine:3.21,alpine3.21,alpine
- debian:bookworm-slim,bookworm-slim,debian-slim
- buildpack-deps:bookworm,bookworm,debian
steps:
Expand Down
16 changes: 6 additions & 10 deletions crates/ruff/tests/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2470,7 +2470,7 @@ fn create_a005_module_structure(tempdir: &TempDir) -> Result<()> {
Ok(())
}

/// Test A005 with `builtins-strict-checking = true`
/// Test A005 with `strict-checking = true`
#[test]
fn a005_module_shadowing_strict() -> Result<()> {
let tempdir = TempDir::new()?;
Expand All @@ -2482,7 +2482,7 @@ fn a005_module_shadowing_strict() -> Result<()> {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.arg("--config")
.arg(r#"lint.flake8-builtins.builtins-strict-checking = true"#)
.arg(r#"lint.flake8-builtins.strict-checking = true"#)
.args(["--select", "A005"])
.current_dir(tempdir.path()),
@r"
Expand All @@ -2504,7 +2504,7 @@ fn a005_module_shadowing_strict() -> Result<()> {
Ok(())
}

/// Test A005 with `builtins-strict-checking = false`
/// Test A005 with `strict-checking = false`
#[test]
fn a005_module_shadowing_non_strict() -> Result<()> {
let tempdir = TempDir::new()?;
Expand All @@ -2516,7 +2516,7 @@ fn a005_module_shadowing_non_strict() -> Result<()> {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.arg("--config")
.arg(r#"lint.flake8-builtins.builtins-strict-checking = false"#)
.arg(r#"lint.flake8-builtins.strict-checking = false"#)
.args(["--select", "A005"])
.current_dir(tempdir.path()),
@r"
Expand All @@ -2535,7 +2535,7 @@ fn a005_module_shadowing_non_strict() -> Result<()> {
Ok(())
}

/// Test A005 with `builtins-strict-checking` unset
/// Test A005 with `strict-checking` unset
/// TODO(brent) This should currently match the strict version, but after the next minor
/// release it will match the non-strict version directly above
#[test]
Expand All @@ -2556,11 +2556,7 @@ fn a005_module_shadowing_strict_default() -> Result<()> {
----- stdout -----
abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module
collections/__init__.py:1:1: A005 Module `collections` shadows a Python standard-library module
collections/abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module
foobar/abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module
foobar/collections/__init__.py:1:1: A005 Module `collections` shadows a Python standard-library module
foobar/collections/abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module
Found 6 errors.
Found 2 errors.

----- stderr -----
");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,12 @@ linter.flake8_bandit.hardcoded_tmp_directory = [
/dev/shm,
]
linter.flake8_bandit.check_typed_exception = false
linter.flake8_bandit.extend_markup_names = []
linter.flake8_bandit.allowed_markup_calls = []
linter.flake8_bugbear.extend_immutable_calls = []
linter.flake8_builtins.builtins_allowed_modules = []
linter.flake8_builtins.builtins_ignorelist = []
linter.flake8_builtins.builtins_strict_checking = true
linter.flake8_builtins.allowed_modules = []
linter.flake8_builtins.ignorelist = []
linter.flake8_builtins.strict_checking = false
linter.flake8_comprehensions.allow_dict_calls_with_keyword_arguments = false
linter.flake8_copyright.notice_rgx = (?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*
linter.flake8_copyright.author = none
Expand Down Expand Up @@ -369,8 +371,6 @@ linter.pylint.max_public_methods = 20
linter.pylint.max_locals = 15
linter.pyupgrade.keep_runtime_typing = false
linter.ruff.parenthesize_tuple_in_subscript = false
linter.ruff.extend_markup_names = []
linter.ruff.allowed_markup_calls = []

# Formatter Settings
formatter.exclude = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
from markupsafe import Markup, escape

content = "<script>alert('Hello, world!')</script>"
Markup(f"unsafe {content}") # RUF035
flask.Markup("unsafe {}".format(content)) # RUF035
Markup(f"unsafe {content}") # S704
flask.Markup("unsafe {}".format(content)) # S704
Markup("safe {}").format(content)
flask.Markup(b"safe {}", encoding='utf-8').format(content)
escape(content)
Markup(content) # RUF035
flask.Markup("unsafe %s" % content) # RUF035
Markup(content) # S704
flask.Markup("unsafe %s" % content) # S704
Markup(object="safe")
Markup(object="unsafe {}".format(content)) # Not currently detected

# NOTE: We may be able to get rid of these false positives with red-knot
# if it includes comprehensive constant expression detection/evaluation.
Markup("*" * 8) # RUF035 (false positive)
flask.Markup("hello {}".format("world")) # RUF035 (false positive)
Markup("*" * 8) # S704 (false positive)
flask.Markup("hello {}".format("world")) # S704 (false positive)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from webhelpers.html import literal

content = "<script>alert('Hello, world!')</script>"
Markup(f"unsafe {content}") # RUF035
literal(f"unsafe {content}") # RUF035
Markup(f"unsafe {content}") # S704
literal(f"unsafe {content}") # S704
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# additional markup names to be skipped if we don't import either
# markupsafe or flask first.
content = "<script>alert('Hello, world!')</script>"
literal(f"unsafe {content}") # RUF035
literal(f"unsafe {content}") # S704
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

# indirect assignments are currently not supported
cleaned = clean(content)
Markup(cleaned) # RUF035
Markup(cleaned) # S704
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
pass # TC005


if False:
pass # TC005

if 0:
pass # TC005


def example():
if TYPE_CHECKING:
pass # TC005
Expand All @@ -32,13 +25,6 @@ class Test:
x: List


if False:
x: List

if 0:
x: List


from typing_extensions import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff_linter/resources/test/fixtures/ruff/noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ def f():


def f():
# Only `E741` should be ignored by the `noqa`.
# Neither of these are ignored and warning is
# logged to user
I = 1 # noqa: E741.F841
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/checkers/ast/analyze/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
flake8_2020::rules::name_or_attribute(checker, expr);
}
if checker.enabled(Rule::DatetimeMinMax) {
flake8_datetimez::rules::datetime_max_min(checker, expr);
flake8_datetimez::rules::datetime_min_max(checker, expr);
}
if checker.enabled(Rule::BannedApi) {
flake8_tidy_imports::rules::banned_attribute_access(checker, expr);
Expand Down Expand Up @@ -1129,7 +1129,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
refurb::rules::int_on_sliced_str(checker, call);
}
if checker.enabled(Rule::UnsafeMarkupUse) {
ruff::rules::unsafe_markup_call(checker, call);
flake8_bandit::rules::unsafe_markup_call(checker, call);
}
if checker.enabled(Rule::MapIntVersionParsing) {
ruff::rules::map_int_version_parsing(checker, call);
Expand Down
15 changes: 9 additions & 6 deletions crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,7 @@ impl<'a> Checker<'a> {
notebook_index: Option<&'a NotebookIndex>,
target_version: PythonVersion,
) -> Checker<'a> {
let mut semantic = SemanticModel::new(&settings.typing_modules, path, module);
if settings.preview.is_enabled() {
// Set the feature flag to test `TYPE_CHECKING` semantic changes
semantic.flags |= SemanticModelFlags::NEW_TYPE_CHECKING_BLOCK_DETECTION;
}
let semantic = SemanticModel::new(&settings.typing_modules, path, module);
Self {
parsed,
parsed_type_annotation: None,
Expand Down Expand Up @@ -293,7 +289,14 @@ impl<'a> Checker<'a> {
if !self.noqa.is_enabled() {
return false;
}
noqa::rule_is_ignored(code, offset, self.noqa_line_for, self.locator)

noqa::rule_is_ignored(
code,
offset,
self.noqa_line_for,
self.comment_ranges(),
self.locator,
)
}

/// Create a [`Generator`] to generate source code based on the current AST state.
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff_linter/src/checkers/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ pub(crate) fn check_noqa(
let exemption = FileExemption::from(&file_noqa_directives);

// Extract all `noqa` directives.
let mut noqa_directives = NoqaDirectives::from_commented_ranges(comment_ranges, path, locator);
let mut noqa_directives =
NoqaDirectives::from_commented_ranges(comment_ranges, &settings.external, path, locator);

// Indices of diagnostics that were ignored by a `noqa` directive.
let mut ignored_diagnostics = vec![];
Expand Down
Loading
Loading