mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
[pyupgrade
] Remove keep-runtime-typing
setting (#4427)
This commit is contained in:
parent
01b372a75c
commit
a69451ff46
10 changed files with 22 additions and 103 deletions
|
@ -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))
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
mod fixes;
|
||||
mod helpers;
|
||||
pub(crate) mod rules;
|
||||
pub mod settings;
|
||||
pub(crate) mod types;
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -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<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, CacheKey)]
|
||||
pub struct Settings {
|
||||
pub keep_runtime_typing: bool,
|
||||
}
|
||||
|
||||
impl From<Options> for Settings {
|
||||
fn from(options: Options) -> Self {
|
||||
Self {
|
||||
keep_runtime_typing: options.keep_runtime_typing.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Settings> for Options {
|
||||
fn from(settings: Settings) -> Self {
|
||||
Self {
|
||||
keep_runtime_typing: Some(settings.keep_runtime_typing),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<pycodestyle::settings::Options>,
|
||||
pub pydocstyle: Option<pydocstyle::settings::Options>,
|
||||
pub pylint: Option<pylint::settings::Options>,
|
||||
pub pyupgrade: Option<pyupgrade::settings::Options>,
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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<pylint::settings::Options>,
|
||||
#[option_group]
|
||||
/// Options for the `pyupgrade` plugin.
|
||||
pub pyupgrade: Option<pyupgrade::settings::Options>,
|
||||
// Tables are required to go last.
|
||||
#[option(
|
||||
default = "{}",
|
||||
|
|
|
@ -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<JsValue, JsValue> {
|
|||
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()),
|
||||
})?)
|
||||
}
|
||||
|
||||
|
|
24
ruff.schema.json
generated
24
ruff.schema.json
generated
|
@ -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": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue