mirror of
https://github.com/astral-sh/ruff.git
synced 2026-10-28 10:45:37 +08:00
[pyupgrade] Stabilize typing_extensions.Text detection (UP019) (#26943)
Preview feature: https://github.com/astral-sh/ruff/pull/20825 Rule documentation: https://docs.astral.sh/ruff/rules/typing-text-str-alias/
This commit is contained in:
1 parent
ac74da7a22
commit
f1e00e3062
5 files changed
+47
-121
No files matched your search
@@ -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()
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
+45
@@ -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)
|
||||
|
|
||||
-107
@@ -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)
|
||||
|
|
||||
Reference in new issue
Block a user