Skip to content
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

Set default version to py38 #6444

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion crates/ruff/src/rules/flake8_bugbear/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod tests {

use crate::assert_messages;
use crate::registry::Rule;
use crate::settings::types::PythonVersion;
use crate::settings::Settings;
use crate::test::test_path;

Expand Down Expand Up @@ -49,7 +50,6 @@ mod tests {
#[test_case(Rule::UselessComparison, Path::new("B015.py"))]
#[test_case(Rule::UselessContextlibSuppress, Path::new("B022.py"))]
#[test_case(Rule::UselessExpression, Path::new("B018.py"))]
#[test_case(Rule::ZipWithoutExplicitStrict, Path::new("B905.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Expand All @@ -60,6 +60,18 @@ mod tests {
Ok(())
}

#[test]
fn zip_without_explicit_strict() -> Result<()> {
let snapshot = "B905.py";
let diagnostics = test_path(
Path::new("flake8_bugbear").join(snapshot).as_path(),
&Settings::for_rule(Rule::ZipWithoutExplicitStrict)
.with_target_version(PythonVersion::latest()),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
}

#[test]
fn extend_immutable_calls() -> Result<()> {
let snapshot = "extend_immutable_calls".to_string();
Expand Down
6 changes: 4 additions & 2 deletions crates/ruff/src/rules/flake8_use_pathlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod tests {
use crate::assert_messages;
use crate::registry::Rule;
use crate::settings;
use crate::settings::types::PythonVersion;
use crate::test::test_path;

#[test_case(Path::new("full_name.py"))]
Expand Down Expand Up @@ -48,7 +49,8 @@ mod tests {
Rule::OsPathSamefile,
Rule::OsPathSplitext,
Rule::BuiltinOpen,
]),
])
.with_target_version(PythonVersion::latest()),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand All @@ -67,7 +69,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_use_pathlib").join(path).as_path(),
&settings::Settings::for_rule(rule_code),
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zanieb - We should probably make this the default for Settings::for_rule, what do you think? (But we can hash out in separate PR, I'm just trying to get tests passing here.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that makes sense to me

)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand Down
25 changes: 10 additions & 15 deletions crates/ruff/src/rules/pylint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pylint").join(path).as_path(),
&Settings::for_rules(vec![rule_code]),
&Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand All @@ -140,10 +140,8 @@ mod tests {
fn repeated_isinstance_calls() -> Result<()> {
let diagnostics = test_path(
Path::new("pylint/repeated_isinstance_calls.py"),
&Settings {
target_version: PythonVersion::Py39,
..Settings::for_rules(vec![Rule::RepeatedIsinstanceCalls])
},
&Settings::for_rule(Rule::RepeatedIsinstanceCalls)
.with_target_version(PythonVersion::Py39),
)?;
assert_messages!(diagnostics);
Ok(())
Expand All @@ -153,10 +151,7 @@ mod tests {
fn continue_in_finally() -> Result<()> {
let diagnostics = test_path(
Path::new("pylint/continue_in_finally.py"),
&Settings {
target_version: PythonVersion::Py37,
..Settings::for_rules(vec![Rule::ContinueInFinally])
},
&Settings::for_rule(Rule::ContinueInFinally).with_target_version(PythonVersion::Py37),
)?;
assert_messages!(diagnostics);
Ok(())
Expand All @@ -171,7 +166,7 @@ mod tests {
allow_magic_value_types: vec![pylint::settings::ConstantType::Int],
..pylint::settings::Settings::default()
},
..Settings::for_rules(vec![Rule::MagicValueComparison])
..Settings::for_rule(Rule::MagicValueComparison)
},
)?;
assert_messages!(diagnostics);
Expand All @@ -187,7 +182,7 @@ mod tests {
max_args: 4,
..pylint::settings::Settings::default()
},
..Settings::for_rules(vec![Rule::TooManyArguments])
..Settings::for_rule(Rule::TooManyArguments)
},
)?;
assert_messages!(diagnostics);
Expand All @@ -200,7 +195,7 @@ mod tests {
Path::new("pylint/too_many_arguments_params.py"),
&Settings {
dummy_variable_rgx: Regex::new(r"skip_.*").unwrap(),
..Settings::for_rules(vec![Rule::TooManyArguments])
..Settings::for_rule(Rule::TooManyArguments)
},
)?;
assert_messages!(diagnostics);
Expand All @@ -216,7 +211,7 @@ mod tests {
max_branches: 1,
..pylint::settings::Settings::default()
},
..Settings::for_rules(vec![Rule::TooManyBranches])
..Settings::for_rule(Rule::TooManyBranches)
},
)?;
assert_messages!(diagnostics);
Expand All @@ -232,7 +227,7 @@ mod tests {
max_statements: 1,
..pylint::settings::Settings::default()
},
..Settings::for_rules(vec![Rule::TooManyStatements])
..Settings::for_rule(Rule::TooManyStatements)
},
)?;
assert_messages!(diagnostics);
Expand All @@ -248,7 +243,7 @@ mod tests {
max_returns: 1,
..pylint::settings::Settings::default()
},
..Settings::for_rules(vec![Rule::TooManyReturnStatements])
..Settings::for_rule(Rule::TooManyReturnStatements)
},
)?;
assert_messages!(diagnostics);
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/pyupgrade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod tests {
let snapshot = path.to_string_lossy().to_string();
let diagnostics = test_path(
Path::new("pyupgrade").join(path).as_path(),
&settings::Settings::for_rule(rule_code),
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,4 +974,19 @@ UP035.py:76:1: UP035 [*] Import from `collections.abc` instead: `Generator`
78 78 | # OK
79 79 | from a import b

UP035.py:88:1: UP035 [*] Import from `typing` instead: `dataclass_transform`
|
87 | # Ok: `typing_extensions` supports `frozen_default` (backported from 3.12).
88 | from typing_extensions import dataclass_transform
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035
|
= help: Import from `typing`

ℹ Suggested fix
85 85 | from typing_extensions import NamedTuple
86 86 |
87 87 | # Ok: `typing_extensions` supports `frozen_default` (backported from 3.12).
88 |-from typing_extensions import dataclass_transform
88 |+from typing import dataclass_transform


8 changes: 3 additions & 5 deletions crates/ruff/src/rules/ruff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("ruff").join(path).as_path(),
&settings::Settings::for_rule(rule_code),
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand All @@ -60,10 +60,8 @@ mod tests {
);
let diagnostics = test_path(
Path::new("ruff").join(path).as_path(),
&settings::Settings {
target_version: PythonVersion::Py39,
..settings::Settings::for_rule(Rule::ImplicitOptional)
},
&settings::Settings::for_rule(Rule::ImplicitOptional)
.with_target_version(PythonVersion::Py39),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/settings/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub const PREFIXES: &[RuleSelector] = &[
RuleSelector::Linter(Linter::Pyflakes),
];

pub const TARGET_VERSION: PythonVersion = PythonVersion::Py310;
pub const TARGET_VERSION: PythonVersion = PythonVersion::Py38;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the relevant change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'd missed this somehow 😅


pub const TASK_TAGS: &[&str] = &["TODO", "FIXME", "XXX"];

Expand Down
7 changes: 7 additions & 0 deletions crates/ruff/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ impl Settings {
..Self::default()
}
}

/// Return the [`Settings`] after updating the target [`PythonVersion`].
#[must_use]
pub fn with_target_version(mut self, target_version: PythonVersion) -> Self {
self.target_version = target_version;
self
}
}

impl From<&Configuration> for RuleTable {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/settings/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ pub struct Options {
/// contained an `__init__.py` file.
pub namespace_packages: Option<Vec<String>>,
#[option(
default = r#""py310""#,
default = r#""py38""#,
value_type = r#""py37" | "py38" | "py39" | "py310" | "py311" | "py312""#,
example = r#"
# Always generate Python 3.7-compatible code.
Expand Down
4 changes: 4 additions & 0 deletions crates/ruff/src/settings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ impl From<PythonVersion> for Pep440Version {
}

impl PythonVersion {
pub const fn latest() -> Self {
Self::Py312
}

pub const fn as_tuple(&self) -> (u32, u32) {
match self {
Self::Py37 => (3, 7),
Expand Down