diff --git a/crates/ruff_linter/src/preview.rs b/crates/ruff_linter/src/preview.rs index cd60591233..5199a61fc5 100644 --- a/crates/ruff_linter/src/preview.rs +++ b/crates/ruff_linter/src/preview.rs @@ -245,10 +245,6 @@ pub(crate) const fn is_b006_unsafe_fix_preserve_assignment_expr_enabled( settings.preview.is_enabled() } -pub(crate) const fn is_typing_extensions_str_alias_enabled(settings: &LinterSettings) -> bool { - settings.preview.is_enabled() -} - // https://github.com/astral-sh/ruff/pull/19045 pub(crate) const fn is_extended_i18n_function_matching_enabled(settings: &LinterSettings) -> bool { settings.preview.is_enabled() diff --git a/crates/ruff_linter/src/rules/pyupgrade/mod.rs b/crates/ruff_linter/src/rules/pyupgrade/mod.rs index cdc8f10864..fa3ff8ff49 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/mod.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/mod.rs @@ -234,7 +234,6 @@ mod tests { Ok(()) } - #[test_case(Rule::TypingTextStrAlias, Path::new("UP019.py"))] #[test_case(Rule::OSErrorAlias, Path::new("UP024_0.py"))] fn rules_preview(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!("{}__preview", path.to_string_lossy()); diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs index 4e69c888b6..175c760374 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs @@ -6,13 +6,10 @@ use ruff_python_semantic::Modules; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; -use crate::preview::is_typing_extensions_str_alias_enabled; use crate::{Edit, Fix, FixAvailability, Violation}; /// ## What it does -/// Checks for uses of `typing.Text`. -/// -/// In preview mode, also checks for `typing_extensions.Text`. +/// Checks for uses of `typing.Text` and `typing_extensions.Text`. /// /// ## Why is this bad? /// `typing.Text` is an alias for `str`, and only exists for Python 2 @@ -65,11 +62,7 @@ pub(crate) fn typing_text_str_alias(checker: &Checker, expr: &Expr) { let segments = qualified_name.segments(); let module = match segments { ["typing", "Text"] => TypingModule::Typing, - ["typing_extensions", "Text"] - if is_typing_extensions_str_alias_enabled(checker.settings()) => - { - TypingModule::TypingExtensions - } + ["typing_extensions", "Text"] => TypingModule::TypingExtensions, _ => return, }; diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP019.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP019.py.snap index 13310b6a7b..142f093d4e 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP019.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP019.py.snap @@ -60,3 +60,48 @@ help: Replace with `str` 19 + def print_fourth_word(word: str) -> None: 20 | print(word) | + +UP019 [*] `typing_extensions.Text` is deprecated, use `str` + --> UP019.py:28:28 + | +28 | def print_fifth_word(word: typing_extensions.Text) -> None: + | ^^^^^^^^^^^^^^^^^^^^^^ +29 | print(word) + | +help: Replace with `str` + | +27 | + - def print_fifth_word(word: typing_extensions.Text) -> None: +28 + def print_fifth_word(word: str) -> None: +29 | print(word) + | + +UP019 [*] `typing_extensions.Text` is deprecated, use `str` + --> UP019.py:32:28 + | +32 | def print_sixth_word(word: TypingExt.Text) -> None: + | ^^^^^^^^^^^^^^ +33 | print(word) + | +help: Replace with `str` + | +31 | + - def print_sixth_word(word: TypingExt.Text) -> None: +32 + def print_sixth_word(word: str) -> None: +33 | print(word) + | + +UP019 [*] `typing_extensions.Text` is deprecated, use `str` + --> UP019.py:36:30 + | +36 | def print_seventh_word(word: TextAlias) -> None: + | ^^^^^^^^^ +37 | print(word) + | +help: Replace with `str` + | +35 | + - def print_seventh_word(word: TextAlias) -> None: +36 + def print_seventh_word(word: str) -> None: +37 | print(word) + | diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP019.py__preview.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP019.py__preview.snap deleted file mode 100644 index 142f093d4e..0000000000 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP019.py__preview.snap +++ /dev/null @@ -1,107 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/pyupgrade/mod.rs ---- -UP019 [*] `typing.Text` is deprecated, use `str` - --> UP019.py:7:22 - | -7 | def print_word(word: Text) -> None: - | ^^^^ -8 | print(word) - | -help: Replace with `str` - | -6 | - - def print_word(word: Text) -> None: -7 + def print_word(word: str) -> None: -8 | print(word) - | - -UP019 [*] `typing.Text` is deprecated, use `str` - --> UP019.py:11:29 - | -11 | def print_second_word(word: typing.Text) -> None: - | ^^^^^^^^^^^ -12 | print(word) - | -help: Replace with `str` - | -10 | - - def print_second_word(word: typing.Text) -> None: -11 + def print_second_word(word: str) -> None: -12 | print(word) - | - -UP019 [*] `typing.Text` is deprecated, use `str` - --> UP019.py:15:28 - | -15 | def print_third_word(word: Hello.Text) -> None: - | ^^^^^^^^^^ -16 | print(word) - | -help: Replace with `str` - | -14 | - - def print_third_word(word: Hello.Text) -> None: -15 + def print_third_word(word: str) -> None: -16 | print(word) - | - -UP019 [*] `typing.Text` is deprecated, use `str` - --> UP019.py:19:29 - | -19 | def print_fourth_word(word: Goodbye) -> None: - | ^^^^^^^ -20 | print(word) - | -help: Replace with `str` - | -18 | - - def print_fourth_word(word: Goodbye) -> None: -19 + def print_fourth_word(word: str) -> None: -20 | print(word) - | - -UP019 [*] `typing_extensions.Text` is deprecated, use `str` - --> UP019.py:28:28 - | -28 | def print_fifth_word(word: typing_extensions.Text) -> None: - | ^^^^^^^^^^^^^^^^^^^^^^ -29 | print(word) - | -help: Replace with `str` - | -27 | - - def print_fifth_word(word: typing_extensions.Text) -> None: -28 + def print_fifth_word(word: str) -> None: -29 | print(word) - | - -UP019 [*] `typing_extensions.Text` is deprecated, use `str` - --> UP019.py:32:28 - | -32 | def print_sixth_word(word: TypingExt.Text) -> None: - | ^^^^^^^^^^^^^^ -33 | print(word) - | -help: Replace with `str` - | -31 | - - def print_sixth_word(word: TypingExt.Text) -> None: -32 + def print_sixth_word(word: str) -> None: -33 | print(word) - | - -UP019 [*] `typing_extensions.Text` is deprecated, use `str` - --> UP019.py:36:30 - | -36 | def print_seventh_word(word: TextAlias) -> None: - | ^^^^^^^^^ -37 | print(word) - | -help: Replace with `str` - | -35 | - - def print_seventh_word(word: TextAlias) -> None: -36 + def print_seventh_word(word: str) -> None: -37 | print(word) - |