From 38de46ae3c53caebd2ec45dad64f21ba576943e9 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 25 Jan 2023 12:36:50 -0500 Subject: [PATCH] Treat Python 3.7 as minimum supported version (#2159) --- ruff.schema.json | 4 ---- ruff_cli/src/main.rs | 2 +- src/checkers/ast.rs | 4 +++- .../rules/unnecessary_future_import.rs | 9 ++------- src/settings/types.rs | 17 ++++++++--------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/ruff.schema.json b/ruff.schema.json index f991eca97d..6a469583a8 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -1138,10 +1138,6 @@ "PythonVersion": { "type": "string", "enum": [ - "py33", - "py34", - "py35", - "py36", "py37", "py38", "py39", diff --git a/ruff_cli/src/main.rs b/ruff_cli/src/main.rs index b32bf86dab..8d11d0b633 100644 --- a/ruff_cli/src/main.rs +++ b/ruff_cli/src/main.rs @@ -201,7 +201,7 @@ quoting the executed command, along with the relevant file contents and `pyproje if cache { // `--no-cache` doesn't respect code changes, and so is often confusing during // development. - warn_user_once!("debug build without --no-cache."); + warn_user_once!("Detected debug build without --no-cache."); } let printer = Printer::new(&format, &log_level, &autofix, &violations); diff --git a/src/checkers/ast.rs b/src/checkers/ast.rs index ae69abe53d..05c9aba168 100644 --- a/src/checkers/ast.rs +++ b/src/checkers/ast.rs @@ -1044,7 +1044,9 @@ where } } - if self.settings.rules.enabled(&Rule::UnnecessaryFutureImport) { + if self.settings.rules.enabled(&Rule::UnnecessaryFutureImport) + && self.settings.target_version >= PythonVersion::Py37 + { if let Some("__future__") = module.as_deref() { pyupgrade::rules::unnecessary_future_import(self, stmt, names); } diff --git a/src/rules/pyupgrade/rules/unnecessary_future_import.rs b/src/rules/pyupgrade/rules/unnecessary_future_import.rs index 68d9fd4bb3..8507875ab4 100644 --- a/src/rules/pyupgrade/rules/unnecessary_future_import.rs +++ b/src/rules/pyupgrade/rules/unnecessary_future_import.rs @@ -6,7 +6,6 @@ use rustpython_parser::ast::Stmt; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::Diagnostic; -use crate::settings::types::PythonVersion; use crate::{autofix, violations}; const PY33_PLUS_REMOVE_FUTURES: &[&str] = &[ @@ -34,17 +33,13 @@ const PY37_PLUS_REMOVE_FUTURES: &[&str] = &[ /// UP010 pub fn unnecessary_future_import(checker: &mut Checker, stmt: &Stmt, names: &[Located]) { - let target_version = checker.settings.target_version; - let mut unused_imports: Vec<&Alias> = vec![]; for alias in names { if alias.node.asname.is_some() { continue; } - if (target_version >= PythonVersion::Py33 - && PY33_PLUS_REMOVE_FUTURES.contains(&alias.node.name.as_str())) - || (target_version >= PythonVersion::Py37 - && PY37_PLUS_REMOVE_FUTURES.contains(&alias.node.name.as_str())) + if PY33_PLUS_REMOVE_FUTURES.contains(&alias.node.name.as_str()) + || PY37_PLUS_REMOVE_FUTURES.contains(&alias.node.name.as_str()) { unused_imports.push(alias); } diff --git a/src/settings/types.rs b/src/settings/types.rs index 3041515c38..42db6ccbaf 100644 --- a/src/settings/types.rs +++ b/src/settings/types.rs @@ -11,19 +11,15 @@ use schemars::JsonSchema; use serde::{de, Deserialize, Deserializer, Serialize}; use super::hashable::HashableHashSet; -use crate::fs; use crate::registry::Rule; use crate::rule_selector::RuleSelector; +use crate::{fs, warn_user_once}; #[derive( Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, Hash, JsonSchema, )] #[serde(rename_all = "lowercase")] pub enum PythonVersion { - Py33, - Py34, - Py35, - Py36, Py37, Py38, Py39, @@ -36,10 +32,13 @@ impl FromStr for PythonVersion { fn from_str(string: &str) -> Result { match string { - "py33" => Ok(PythonVersion::Py33), - "py34" => Ok(PythonVersion::Py34), - "py35" => Ok(PythonVersion::Py35), - "py36" => Ok(PythonVersion::Py36), + "py33" | "py34" | "py35" | "py36" => { + warn_user_once!( + "Specified a version below the minimum supported Python version. Defaulting \ + to Python 3.7." + ); + Ok(PythonVersion::Py37) + } "py37" => Ok(PythonVersion::Py37), "py38" => Ok(PythonVersion::Py38), "py39" => Ok(PythonVersion::Py39),