Treat Python 3.7 as minimum supported version (#2159)
This commit is contained in:
@@ -1138,10 +1138,6 @@
|
||||
"PythonVersion": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"py33",
|
||||
"py34",
|
||||
"py35",
|
||||
"py36",
|
||||
"py37",
|
||||
"py38",
|
||||
"py39",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<AliasData>]) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<Self, Self::Err> {
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user