Skip to content

Commit

Permalink
Treat all typing_extensions members as typing aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 31, 2023
1 parent 772e5d5 commit 573ec10
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 71 deletions.
15 changes: 4 additions & 11 deletions crates/ruff_python_semantic/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,13 @@ 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 call_path.as_slice() == ["typing", target] {
if matches!(
call_path.as_slice(),
["typing" | "_typeshed" | "typing_extensions", 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;
}
}

if self.typing_modules.iter().any(|module| {
let mut module: CallPath = from_unqualified_name(module);
module.push(target);
Expand Down
60 changes: 0 additions & 60 deletions crates/ruff_python_stdlib/src/typing.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,3 @@
/// 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 573ec10

Please sign in to comment.