Skip to content

Commit

Permalink
Revert extensions change
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored and zanieb committed Nov 9, 2023
1 parent 545bd30 commit 0e0e738
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ PYI050.py:13:24: PYI050 Prefer `typing.Never` over `NoReturn` for argument annot
14 | ...
|

PYI050.py:18:10: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
17 | def foo_no_return_typing_extensions(
18 | arg: typing_extensions.NoReturn,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI050
19 | ):
20 | ...
|

PYI050.py:23:44: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
23 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ PYI050.pyi:6:24: PYI050 Prefer `typing.Never` over `NoReturn` for argument annot
8 | arg: typing_extensions.NoReturn,
|

PYI050.pyi:8:10: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
6 | def foo_no_return(arg: NoReturn): ... # Error: PYI050
7 | def foo_no_return_typing_extensions(
8 | arg: typing_extensions.NoReturn,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI050
9 | ): ... # Error: PYI050
10 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn): ... # Error: PYI050
|

PYI050.pyi:10:44: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
8 | arg: typing_extensions.NoReturn,
Expand Down
13 changes: 11 additions & 2 deletions crates/ruff_python_semantic/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use ruff_python_ast::call_path::{collect_call_path, from_unqualified_name, CallP
use ruff_python_ast::helpers::from_relative_import;
use ruff_python_ast::{self as ast, Expr, Operator, Stmt};
use ruff_python_stdlib::path::is_python_stub_file;
use ruff_python_stdlib::typing::is_typing_extension;
use ruff_text_size::{Ranged, TextRange, TextSize};

use crate::binding::{
Expand Down Expand Up @@ -174,8 +175,16 @@ impl<'a> SemanticModel<'a> {

/// Return `true` if the call path is a reference to `typing.${target}`.
pub fn match_typing_call_path(&self, call_path: &CallPath, target: &str) -> bool {
if let ["typing" | "_typeshed" | "typing_extensions", name] = call_path.as_slice() {
if *name == target {
if call_path.as_slice() == ["typing", target] {
return true;
}

if call_path.as_slice() == ["_typeshed", target] {
return true;
}

if is_typing_extension(target) {
if call_path.as_slice() == ["typing_extensions", target] {
return true;
}
}
Expand Down
60 changes: 60 additions & 0 deletions crates/ruff_python_stdlib/src/typing.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
/// Returns `true` if a name is a member of Python's `typing_extensions` module.
///
/// See: <https://pypi.org/project/typing-extensions/>
pub fn is_typing_extension(member: &str) -> bool {
matches!(
member,
"Annotated"
| "Any"
| "AsyncContextManager"
| "AsyncGenerator"
| "AsyncIterable"
| "AsyncIterator"
| "Awaitable"
| "ChainMap"
| "ClassVar"
| "Concatenate"
| "ContextManager"
| "Coroutine"
| "Counter"
| "DefaultDict"
| "Deque"
| "Final"
| "Literal"
| "LiteralString"
| "NamedTuple"
| "Never"
| "NewType"
| "NotRequired"
| "OrderedDict"
| "ParamSpec"
| "ParamSpecArgs"
| "ParamSpecKwargs"
| "Protocol"
| "Required"
| "Self"
| "TYPE_CHECKING"
| "Text"
| "Type"
| "TypeAlias"
| "TypeGuard"
| "TypeVar"
| "TypeVarTuple"
| "TypedDict"
| "Unpack"
| "assert_never"
| "assert_type"
| "clear_overloads"
| "final"
| "get_type_hints"
| "get_args"
| "get_origin"
| "get_overloads"
| "is_typeddict"
| "overload"
| "override"
| "reveal_type"
| "runtime_checkable"
)
}

/// Returns `true` if a call path is a generic from the Python standard library (e.g. `list`, which
/// can be used as `list[int]`).
///
Expand Down

0 comments on commit 0e0e738

Please sign in to comment.