mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-17 22:07:42 +00:00
fix-20819
This commit is contained in:
parent
7064c38e53
commit
746feb8506
3 changed files with 78 additions and 2 deletions
|
@ -18,3 +18,20 @@ def print_third_word(word: Hello.Text) -> None:
|
|||
|
||||
def print_fourth_word(word: Goodbye) -> None:
|
||||
print(word)
|
||||
|
||||
|
||||
import typing_extensions
|
||||
import typing_extensions as TypingExt
|
||||
from typing_extensions import Text as TextAlias
|
||||
|
||||
|
||||
def print_fifth_word(word: typing_extensions.Text) -> None:
|
||||
print(word)
|
||||
|
||||
|
||||
def print_sixth_word(word: TypingExt.Text) -> None:
|
||||
print(word)
|
||||
|
||||
|
||||
def print_seventh_word(word: TextAlias) -> None:
|
||||
print(word)
|
||||
|
|
|
@ -47,14 +47,22 @@ impl Violation for TypingTextStrAlias {
|
|||
|
||||
/// UP019
|
||||
pub(crate) fn typing_text_str_alias(checker: &Checker, expr: &Expr) {
|
||||
if !checker.semantic().seen_module(Modules::TYPING) {
|
||||
if !checker
|
||||
.semantic()
|
||||
.seen_module(Modules::TYPING | Modules::TYPING_EXTENSIONS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if checker
|
||||
.semantic()
|
||||
.resolve_qualified_name(expr)
|
||||
.is_some_and(|qualified_name| matches!(qualified_name.segments(), ["typing", "Text"]))
|
||||
.is_some_and(|qualified_name| {
|
||||
matches!(
|
||||
qualified_name.segments(),
|
||||
["typing" | "typing_extensions", "Text"]
|
||||
)
|
||||
})
|
||||
{
|
||||
let mut diagnostic = checker.report_diagnostic(TypingTextStrAlias, expr.range());
|
||||
diagnostic.add_primary_tag(ruff_db::diagnostic::DiagnosticTag::Deprecated);
|
||||
|
|
|
@ -66,3 +66,54 @@ help: Replace with `str`
|
|||
- def print_fourth_word(word: Goodbye) -> None:
|
||||
19 + def print_fourth_word(word: str) -> None:
|
||||
20 | print(word)
|
||||
21 |
|
||||
22 |
|
||||
|
||||
UP019 [*] `typing.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`
|
||||
25 | from typing_extensions import Text as TextAlias
|
||||
26 |
|
||||
27 |
|
||||
- def print_fifth_word(word: typing_extensions.Text) -> None:
|
||||
28 + def print_fifth_word(word: str) -> None:
|
||||
29 | print(word)
|
||||
30 |
|
||||
31 |
|
||||
|
||||
UP019 [*] `typing.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`
|
||||
29 | print(word)
|
||||
30 |
|
||||
31 |
|
||||
- def print_sixth_word(word: TypingExt.Text) -> None:
|
||||
32 + def print_sixth_word(word: str) -> None:
|
||||
33 | print(word)
|
||||
34 |
|
||||
35 |
|
||||
|
||||
UP019 [*] `typing.Text` is deprecated, use `str`
|
||||
--> UP019.py:36:30
|
||||
|
|
||||
36 | def print_seventh_word(word: TextAlias) -> None:
|
||||
| ^^^^^^^^^
|
||||
37 | print(word)
|
||||
|
|
||||
help: Replace with `str`
|
||||
33 | print(word)
|
||||
34 |
|
||||
35 |
|
||||
- def print_seventh_word(word: TextAlias) -> None:
|
||||
36 + def print_seventh_word(word: str) -> None:
|
||||
37 | print(word)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue