From a69451ff466d9e7e0148cd81e11f9487560f5f61 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 13 May 2023 23:12:52 -0400 Subject: [PATCH] [`pyupgrade`] Remove `keep-runtime-typing` setting (#4427) --- BREAKING_CHANGES.md | 9 ++++ crates/ruff/src/checkers/ast/mod.rs | 9 ++-- crates/ruff/src/rules/pyupgrade/mod.rs | 1 - crates/ruff/src/rules/pyupgrade/settings.rs | 51 --------------------- crates/ruff/src/settings/configuration.rs | 4 -- crates/ruff/src/settings/defaults.rs | 10 ++-- crates/ruff/src/settings/mod.rs | 3 -- crates/ruff/src/settings/options.rs | 12 ++--- crates/ruff_wasm/src/lib.rs | 2 - ruff.schema.json | 24 ---------- 10 files changed, 22 insertions(+), 103 deletions(-) delete mode 100644 crates/ruff/src/rules/pyupgrade/settings.rs diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 374552b789c19..c76d5b82a6c0b 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -1,5 +1,14 @@ # Breaking Changes +## 0.0.268 + +### The `keep-runtime-typing` setting has been removed ([#4427](https://github.com/charliermarsh/ruff/pull/4427)) + +Enabling the `keep-runtime-typing` option, located under the `pyupgrade` section, is equivalent +to ignoring the `UP006` and `UP007` rules via Ruff's standard `ignore` mechanism. As there's no +need for a dedicated setting to disable these rules, the `keep-runtime-typing` option has been +removed. + ## 0.0.267 ### `update-check` is no longer a valid configuration option ([#4313](https://github.com/charliermarsh/ruff/pull/4313)) diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index 53bab09e27cac..44c007f72f720 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -2269,8 +2269,7 @@ where { flake8_future_annotations::rules::missing_future_annotations(self, value); } - if !self.settings.pyupgrade.keep_runtime_typing - && self.settings.rules.enabled(Rule::NonPEP604Annotation) + if self.settings.rules.enabled(Rule::NonPEP604Annotation) && (self.settings.target_version >= PythonVersion::Py310 || (self.settings.target_version >= PythonVersion::Py37 && self.ctx.future_annotations() @@ -2347,8 +2346,7 @@ where self, expr, ); } - if !self.settings.pyupgrade.keep_runtime_typing - && self.settings.rules.enabled(Rule::NonPEP585Annotation) + if self.settings.rules.enabled(Rule::NonPEP585Annotation) && (self.settings.target_version >= PythonVersion::Py39 || (self.settings.target_version >= PythonVersion::Py37 && self.ctx.future_annotations() @@ -2410,8 +2408,7 @@ where { flake8_future_annotations::rules::missing_future_annotations(self, expr); } - if !self.settings.pyupgrade.keep_runtime_typing - && self.settings.rules.enabled(Rule::NonPEP585Annotation) + if self.settings.rules.enabled(Rule::NonPEP585Annotation) && (self.settings.target_version >= PythonVersion::Py39 || (self.settings.target_version >= PythonVersion::Py37 && self.ctx.future_annotations() diff --git a/crates/ruff/src/rules/pyupgrade/mod.rs b/crates/ruff/src/rules/pyupgrade/mod.rs index d4cfcec53e3ed..22c30c7e7bf6c 100644 --- a/crates/ruff/src/rules/pyupgrade/mod.rs +++ b/crates/ruff/src/rules/pyupgrade/mod.rs @@ -2,7 +2,6 @@ mod fixes; mod helpers; pub(crate) mod rules; -pub mod settings; pub(crate) mod types; #[cfg(test)] diff --git a/crates/ruff/src/rules/pyupgrade/settings.rs b/crates/ruff/src/rules/pyupgrade/settings.rs deleted file mode 100644 index 8fb75ac215305..0000000000000 --- a/crates/ruff/src/rules/pyupgrade/settings.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! Settings for the `pyupgrade` plugin. - -use ruff_macros::{CacheKey, ConfigurationOptions}; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Default, ConfigurationOptions)] -#[serde( - deny_unknown_fields, - rename_all = "kebab-case", - rename = "PyUpgradeOptions" -)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub struct Options { - #[option( - default = r#"false"#, - value_type = "bool", - example = r#" - # Preserve types, even if a file imports `from __future__ import annotations`. - keep-runtime-typing = true - "# - )] - /// Whether to avoid PEP 585 (`List[int]` -> `list[int]`) and PEP 604 - /// (`Optional[str]` -> `str | None`) rewrites even if a file imports - /// `from __future__ import annotations`. Note that this setting is only - /// applicable when the target Python version is below 3.9 and 3.10 - /// respectively, and enabling it is equivalent to disabling - /// `use-pep585-annotation` (`UP006`) and `use-pep604-annotation` - /// (`UP007`) entirely. - pub keep_runtime_typing: Option, -} - -#[derive(Debug, Default, CacheKey)] -pub struct Settings { - pub keep_runtime_typing: bool, -} - -impl From for Settings { - fn from(options: Options) -> Self { - Self { - keep_runtime_typing: options.keep_runtime_typing.unwrap_or_default(), - } - } -} - -impl From for Options { - fn from(settings: Settings) -> Self { - Self { - keep_runtime_typing: Some(settings.keep_runtime_typing), - } - } -} diff --git a/crates/ruff/src/settings/configuration.rs b/crates/ruff/src/settings/configuration.rs index 20d1d0fed2262..5e6318e5cb0a5 100644 --- a/crates/ruff/src/settings/configuration.rs +++ b/crates/ruff/src/settings/configuration.rs @@ -19,7 +19,6 @@ use crate::rules::{ flake8_errmsg, flake8_gettext, flake8_implicit_str_concat, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_self, flake8_tidy_imports, flake8_type_checking, flake8_unused_arguments, isort, mccabe, pep8_naming, pycodestyle, pydocstyle, pylint, - pyupgrade, }; use crate::settings::options::Options; use crate::settings::types::{ @@ -87,7 +86,6 @@ pub struct Configuration { pub pycodestyle: Option, pub pydocstyle: Option, pub pylint: Option, - pub pyupgrade: Option, } impl Configuration { @@ -222,7 +220,6 @@ impl Configuration { pycodestyle: options.pycodestyle, pydocstyle: options.pydocstyle, pylint: options.pylint, - pyupgrade: options.pyupgrade, }) } @@ -298,7 +295,6 @@ impl Configuration { pycodestyle: self.pycodestyle.or(config.pycodestyle), pydocstyle: self.pydocstyle.or(config.pydocstyle), pylint: self.pylint.or(config.pylint), - pyupgrade: self.pyupgrade.or(config.pyupgrade), } } } diff --git a/crates/ruff/src/settings/defaults.rs b/crates/ruff/src/settings/defaults.rs index 3cb374fb1c0e5..5d468784f407e 100644 --- a/crates/ruff/src/settings/defaults.rs +++ b/crates/ruff/src/settings/defaults.rs @@ -1,11 +1,10 @@ +use std::collections::HashSet; + use once_cell::sync::Lazy; use path_absolutize::path_dedot; use regex::Regex; use rustc_hash::FxHashSet; -use std::collections::HashSet; -use super::types::{FilePattern, PythonVersion}; -use super::Settings; use crate::codes::{self, RuleCodePrefix}; use crate::registry::Linter; use crate::rule_selector::{prefix_to_selector, RuleSelector}; @@ -14,10 +13,12 @@ use crate::rules::{ flake8_errmsg, flake8_gettext, flake8_implicit_str_concat, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_self, flake8_tidy_imports, flake8_type_checking, flake8_unused_arguments, isort, mccabe, pep8_naming, pycodestyle, pydocstyle, pylint, - pyupgrade, }; use crate::settings::types::FilePatternSet; +use super::types::{FilePattern, PythonVersion}; +use super::Settings; + pub const PREFIXES: &[RuleSelector] = &[ prefix_to_selector(RuleCodePrefix::Pycodestyle(codes::Pycodestyle::E)), RuleSelector::Linter(Linter::Pyflakes), @@ -105,7 +106,6 @@ impl Default for Settings { pycodestyle: pycodestyle::settings::Settings::default(), pydocstyle: pydocstyle::settings::Settings::default(), pylint: pylint::settings::Settings::default(), - pyupgrade: pyupgrade::settings::Settings::default(), } } } diff --git a/crates/ruff/src/settings/mod.rs b/crates/ruff/src/settings/mod.rs index d489794850add..791daf47901e7 100644 --- a/crates/ruff/src/settings/mod.rs +++ b/crates/ruff/src/settings/mod.rs @@ -20,7 +20,6 @@ use crate::rules::{ flake8_errmsg, flake8_gettext, flake8_implicit_str_concat, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_self, flake8_tidy_imports, flake8_type_checking, flake8_unused_arguments, isort, mccabe, pep8_naming, pycodestyle, pydocstyle, pylint, - pyupgrade, }; use crate::settings::configuration::Configuration; use crate::settings::types::{FilePatternSet, PerFileIgnore, PythonVersion, SerializationFormat}; @@ -126,7 +125,6 @@ pub struct Settings { pub pycodestyle: pycodestyle::settings::Settings, pub pydocstyle: pydocstyle::settings::Settings, pub pylint: pylint::settings::Settings, - pub pyupgrade: pyupgrade::settings::Settings, } impl Settings { @@ -226,7 +224,6 @@ impl Settings { pycodestyle: config.pycodestyle.map(Into::into).unwrap_or_default(), pydocstyle: config.pydocstyle.map(Into::into).unwrap_or_default(), pylint: config.pylint.map(Into::into).unwrap_or_default(), - pyupgrade: config.pyupgrade.map(Into::into).unwrap_or_default(), }) } diff --git a/crates/ruff/src/settings/options.rs b/crates/ruff/src/settings/options.rs index db86393bca177..52a202693aa3e 100644 --- a/crates/ruff/src/settings/options.rs +++ b/crates/ruff/src/settings/options.rs @@ -1,17 +1,18 @@ //! Options that the user can provide via pyproject.toml. +use rustc_hash::FxHashMap; +use serde::{Deserialize, Serialize}; + +use ruff_macros::ConfigurationOptions; + use crate::rule_selector::RuleSelector; use crate::rules::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_builtins, flake8_comprehensions, flake8_errmsg, flake8_gettext, flake8_implicit_str_concat, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_self, flake8_tidy_imports, flake8_type_checking, flake8_unused_arguments, isort, mccabe, pep8_naming, pycodestyle, pydocstyle, pylint, - pyupgrade, }; use crate::settings::types::{PythonVersion, SerializationFormat, Version}; -use ruff_macros::ConfigurationOptions; -use rustc_hash::FxHashMap; -use serde::{Deserialize, Serialize}; #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Default, ConfigurationOptions)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] @@ -508,9 +509,6 @@ pub struct Options { #[option_group] /// Options for the `pylint` plugin. pub pylint: Option, - #[option_group] - /// Options for the `pyupgrade` plugin. - pub pyupgrade: Option, // Tables are required to go last. #[option( default = "{}", diff --git a/crates/ruff_wasm/src/lib.rs b/crates/ruff_wasm/src/lib.rs index 6cd82624dc103..32c9a484a3989 100644 --- a/crates/ruff_wasm/src/lib.rs +++ b/crates/ruff_wasm/src/lib.rs @@ -12,7 +12,6 @@ use ruff::rules::{ flake8_errmsg, flake8_gettext, flake8_implicit_str_concat, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_self, flake8_tidy_imports, flake8_type_checking, flake8_unused_arguments, isort, mccabe, pep8_naming, pycodestyle, pydocstyle, pylint, - pyupgrade, }; use ruff::settings::configuration::Configuration; use ruff::settings::options::Options; @@ -155,7 +154,6 @@ pub fn defaultSettings() -> Result { pycodestyle: Some(pycodestyle::settings::Settings::default().into()), pydocstyle: Some(pydocstyle::settings::Settings::default().into()), pylint: Some(pylint::settings::Settings::default().into()), - pyupgrade: Some(pyupgrade::settings::Settings::default().into()), })?) } diff --git a/ruff.schema.json b/ruff.schema.json index c523f3913e7ed..adf5566311b56 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -428,17 +428,6 @@ } ] }, - "pyupgrade": { - "description": "Options for the `pyupgrade` plugin.", - "anyOf": [ - { - "$ref": "#/definitions/PyUpgradeOptions" - }, - { - "type": "null" - } - ] - }, "required-version": { "description": "Require a specific version of Ruff to be running (useful for unifying results across many environments, e.g., with a `pyproject.toml` file).", "anyOf": [ @@ -1335,19 +1324,6 @@ }, "additionalProperties": false }, - "PyUpgradeOptions": { - "type": "object", - "properties": { - "keep-runtime-typing": { - "description": "Whether to avoid PEP 585 (`List[int]` -> `list[int]`) and PEP 604 (`Optional[str]` -> `str | None`) rewrites even if a file imports `from __future__ import annotations`. Note that this setting is only applicable when the target Python version is below 3.9 and 3.10 respectively, and enabling it is equivalent to disabling `use-pep585-annotation` (`UP006`) and `use-pep604-annotation` (`UP007`) entirely.", - "type": [ - "boolean", - "null" - ] - } - }, - "additionalProperties": false - }, "Pycodestyle": { "type": "object", "properties": {