Treat all typing_extensions members as typing aliases (#9335)

## Summary

Historically, we encoded this list by extracting the `__all__`. I went
to update it, but... is there really any value in it? Seems easier to
just treat `typing_extensions` as an alias for `typing`.

Closes https://github.com/astral-sh/ruff/issues/9334.
This commit is contained in:
Charlie Marsh 2023-12-31 14:23:33 -04:00 committed by GitHub
parent 772e5d587d
commit 195f7c097a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 72 deletions

View file

@ -8,7 +8,6 @@ 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::{
@ -175,20 +174,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", member] if *member == 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);