mirror of https://github.com/astral-sh/ruff
[ty] Remove `all_` prefix from some routines on UseDefMap
These routines don't return *all* symbols/members, but rather, only *for* a particular scope. We do specifically want to add some routines that return *all* symbols/members, and this naming scheme made that confusing. It was also inconsistent with other routines like `all_end_of_scope_symbol_declarations` which *do* return *all* symbols.
This commit is contained in:
parent
c51727708a
commit
c1c45a6a13
|
|
@ -783,7 +783,7 @@ pub(crate) fn place_by_id<'db>(
|
||||||
|
|
||||||
let declarations = match considered_definitions {
|
let declarations = match considered_definitions {
|
||||||
ConsideredDefinitions::EndOfScope => use_def.end_of_scope_declarations(place_id),
|
ConsideredDefinitions::EndOfScope => use_def.end_of_scope_declarations(place_id),
|
||||||
ConsideredDefinitions::AllReachable => use_def.all_reachable_declarations(place_id),
|
ConsideredDefinitions::AllReachable => use_def.reachable_declarations(place_id),
|
||||||
};
|
};
|
||||||
|
|
||||||
let declared = place_from_declarations_impl(db, declarations, requires_explicit_reexport)
|
let declared = place_from_declarations_impl(db, declarations, requires_explicit_reexport)
|
||||||
|
|
@ -791,7 +791,7 @@ pub(crate) fn place_by_id<'db>(
|
||||||
|
|
||||||
let all_considered_bindings = || match considered_definitions {
|
let all_considered_bindings = || match considered_definitions {
|
||||||
ConsideredDefinitions::EndOfScope => use_def.end_of_scope_bindings(place_id),
|
ConsideredDefinitions::EndOfScope => use_def.end_of_scope_bindings(place_id),
|
||||||
ConsideredDefinitions::AllReachable => use_def.all_reachable_bindings(place_id),
|
ConsideredDefinitions::AllReachable => use_def.reachable_bindings(place_id),
|
||||||
};
|
};
|
||||||
|
|
||||||
// If a symbol is undeclared, but qualified with `typing.Final`, we use the right-hand side
|
// If a symbol is undeclared, but qualified with `typing.Final`, we use the right-hand side
|
||||||
|
|
|
||||||
|
|
@ -113,10 +113,7 @@ pub(crate) fn attribute_assignments<'db, 's>(
|
||||||
let place_table = index.place_table(function_scope_id);
|
let place_table = index.place_table(function_scope_id);
|
||||||
let member = place_table.member_id_by_instance_attribute_name(name)?;
|
let member = place_table.member_id_by_instance_attribute_name(name)?;
|
||||||
let use_def = &index.use_def_maps[function_scope_id];
|
let use_def = &index.use_def_maps[function_scope_id];
|
||||||
Some((
|
Some((use_def.reachable_member_bindings(member), function_scope_id))
|
||||||
use_def.all_reachable_member_bindings(member),
|
|
||||||
function_scope_id,
|
|
||||||
))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,7 +135,7 @@ pub(crate) fn attribute_declarations<'db, 's>(
|
||||||
let member = place_table.member_id_by_instance_attribute_name(name)?;
|
let member = place_table.member_id_by_instance_attribute_name(name)?;
|
||||||
let use_def = &index.use_def_maps[function_scope_id];
|
let use_def = &index.use_def_maps[function_scope_id];
|
||||||
Some((
|
Some((
|
||||||
use_def.all_reachable_member_declarations(member),
|
use_def.reachable_member_declarations(member),
|
||||||
function_scope_id,
|
function_scope_id,
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -453,17 +453,17 @@ impl<'db> UseDefMap<'db> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn all_reachable_bindings(
|
pub(crate) fn reachable_bindings(
|
||||||
&self,
|
&self,
|
||||||
place: ScopedPlaceId,
|
place: ScopedPlaceId,
|
||||||
) -> BindingWithConstraintsIterator<'_, 'db> {
|
) -> BindingWithConstraintsIterator<'_, 'db> {
|
||||||
match place {
|
match place {
|
||||||
ScopedPlaceId::Symbol(symbol) => self.all_reachable_symbol_bindings(symbol),
|
ScopedPlaceId::Symbol(symbol) => self.reachable_symbol_bindings(symbol),
|
||||||
ScopedPlaceId::Member(member) => self.all_reachable_member_bindings(member),
|
ScopedPlaceId::Member(member) => self.reachable_member_bindings(member),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn all_reachable_symbol_bindings(
|
pub(crate) fn reachable_symbol_bindings(
|
||||||
&self,
|
&self,
|
||||||
symbol: ScopedSymbolId,
|
symbol: ScopedSymbolId,
|
||||||
) -> BindingWithConstraintsIterator<'_, 'db> {
|
) -> BindingWithConstraintsIterator<'_, 'db> {
|
||||||
|
|
@ -471,7 +471,7 @@ impl<'db> UseDefMap<'db> {
|
||||||
self.bindings_iterator(bindings, BoundnessAnalysis::AssumeBound)
|
self.bindings_iterator(bindings, BoundnessAnalysis::AssumeBound)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn all_reachable_member_bindings(
|
pub(crate) fn reachable_member_bindings(
|
||||||
&self,
|
&self,
|
||||||
symbol: ScopedMemberId,
|
symbol: ScopedMemberId,
|
||||||
) -> BindingWithConstraintsIterator<'_, 'db> {
|
) -> BindingWithConstraintsIterator<'_, 'db> {
|
||||||
|
|
@ -547,7 +547,7 @@ impl<'db> UseDefMap<'db> {
|
||||||
self.declarations_iterator(declarations, BoundnessAnalysis::BasedOnUnboundVisibility)
|
self.declarations_iterator(declarations, BoundnessAnalysis::BasedOnUnboundVisibility)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn all_reachable_symbol_declarations(
|
pub(crate) fn reachable_symbol_declarations(
|
||||||
&self,
|
&self,
|
||||||
symbol: ScopedSymbolId,
|
symbol: ScopedSymbolId,
|
||||||
) -> DeclarationsIterator<'_, 'db> {
|
) -> DeclarationsIterator<'_, 'db> {
|
||||||
|
|
@ -555,7 +555,7 @@ impl<'db> UseDefMap<'db> {
|
||||||
self.declarations_iterator(declarations, BoundnessAnalysis::AssumeBound)
|
self.declarations_iterator(declarations, BoundnessAnalysis::AssumeBound)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn all_reachable_member_declarations(
|
pub(crate) fn reachable_member_declarations(
|
||||||
&self,
|
&self,
|
||||||
member: ScopedMemberId,
|
member: ScopedMemberId,
|
||||||
) -> DeclarationsIterator<'_, 'db> {
|
) -> DeclarationsIterator<'_, 'db> {
|
||||||
|
|
@ -563,13 +563,13 @@ impl<'db> UseDefMap<'db> {
|
||||||
self.declarations_iterator(declarations, BoundnessAnalysis::AssumeBound)
|
self.declarations_iterator(declarations, BoundnessAnalysis::AssumeBound)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn all_reachable_declarations(
|
pub(crate) fn reachable_declarations(
|
||||||
&self,
|
&self,
|
||||||
place: ScopedPlaceId,
|
place: ScopedPlaceId,
|
||||||
) -> DeclarationsIterator<'_, 'db> {
|
) -> DeclarationsIterator<'_, 'db> {
|
||||||
match place {
|
match place {
|
||||||
ScopedPlaceId::Symbol(symbol) => self.all_reachable_symbol_declarations(symbol),
|
ScopedPlaceId::Symbol(symbol) => self.reachable_symbol_declarations(symbol),
|
||||||
ScopedPlaceId::Member(member) => self.all_reachable_member_declarations(member),
|
ScopedPlaceId::Member(member) => self.reachable_member_declarations(member),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3457,7 +3457,7 @@ impl<'db> ClassLiteral<'db> {
|
||||||
.symbol_id(&method_def.node(&module).name)
|
.symbol_id(&method_def.node(&module).name)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
class_map
|
class_map
|
||||||
.all_reachable_symbol_bindings(method_place)
|
.reachable_symbol_bindings(method_place)
|
||||||
.find_map(|bind| {
|
.find_map(|bind| {
|
||||||
(bind.binding.is_defined_and(|def| def == method))
|
(bind.binding.is_defined_and(|def| def == method))
|
||||||
.then(|| class_map.binding_reachability(db, &bind))
|
.then(|| class_map.binding_reachability(db, &bind))
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ pub(crate) fn enum_metadata<'db>(
|
||||||
let mut auto_counter = 0;
|
let mut auto_counter = 0;
|
||||||
|
|
||||||
let ignored_names: Option<Vec<&str>> = if let Some(ignore) = table.symbol_id("_ignore_") {
|
let ignored_names: Option<Vec<&str>> = if let Some(ignore) = table.symbol_id("_ignore_") {
|
||||||
let ignore_bindings = use_def_map.all_reachable_symbol_bindings(ignore);
|
let ignore_bindings = use_def_map.reachable_symbol_bindings(ignore);
|
||||||
let ignore_place = place_from_bindings(db, ignore_bindings).place;
|
let ignore_place = place_from_bindings(db, ignore_bindings).place;
|
||||||
|
|
||||||
match ignore_place {
|
match ignore_place {
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,9 @@ pub fn definitions_for_name<'db>(
|
||||||
if let Some(global_symbol_id) = global_place_table.symbol_id(name_str) {
|
if let Some(global_symbol_id) = global_place_table.symbol_id(name_str) {
|
||||||
let global_use_def_map = crate::semantic_index::use_def_map(db, global_scope_id);
|
let global_use_def_map = crate::semantic_index::use_def_map(db, global_scope_id);
|
||||||
let global_bindings =
|
let global_bindings =
|
||||||
global_use_def_map.all_reachable_symbol_bindings(global_symbol_id);
|
global_use_def_map.reachable_symbol_bindings(global_symbol_id);
|
||||||
let global_declarations =
|
let global_declarations =
|
||||||
global_use_def_map.all_reachable_symbol_declarations(global_symbol_id);
|
global_use_def_map.reachable_symbol_declarations(global_symbol_id);
|
||||||
|
|
||||||
for binding in global_bindings {
|
for binding in global_bindings {
|
||||||
if let Some(def) = binding.binding.definition() {
|
if let Some(def) = binding.binding.definition() {
|
||||||
|
|
@ -114,8 +114,8 @@ pub fn definitions_for_name<'db>(
|
||||||
let use_def_map = index.use_def_map(scope_id);
|
let use_def_map = index.use_def_map(scope_id);
|
||||||
|
|
||||||
// Get all definitions (both bindings and declarations) for this place
|
// Get all definitions (both bindings and declarations) for this place
|
||||||
let bindings = use_def_map.all_reachable_symbol_bindings(symbol_id);
|
let bindings = use_def_map.reachable_symbol_bindings(symbol_id);
|
||||||
let declarations = use_def_map.all_reachable_symbol_declarations(symbol_id);
|
let declarations = use_def_map.reachable_symbol_declarations(symbol_id);
|
||||||
|
|
||||||
for binding in bindings {
|
for binding in bindings {
|
||||||
if let Some(def) = binding.binding.definition() {
|
if let Some(def) = binding.binding.definition() {
|
||||||
|
|
@ -294,7 +294,7 @@ pub fn definitions_for_attribute<'db>(
|
||||||
let use_def = use_def_map(db, class_scope);
|
let use_def = use_def_map(db, class_scope);
|
||||||
|
|
||||||
// Check declarations first
|
// Check declarations first
|
||||||
for decl in use_def.all_reachable_symbol_declarations(place_id) {
|
for decl in use_def.reachable_symbol_declarations(place_id) {
|
||||||
if let Some(def) = decl.declaration.definition() {
|
if let Some(def) = decl.declaration.definition() {
|
||||||
resolved.extend(resolve_definition(
|
resolved.extend(resolve_definition(
|
||||||
db,
|
db,
|
||||||
|
|
@ -307,7 +307,7 @@ pub fn definitions_for_attribute<'db>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no declarations found, check bindings
|
// If no declarations found, check bindings
|
||||||
for binding in use_def.all_reachable_symbol_bindings(place_id) {
|
for binding in use_def.reachable_symbol_bindings(place_id) {
|
||||||
if let Some(def) = binding.binding.definition() {
|
if let Some(def) = binding.binding.definition() {
|
||||||
resolved.extend(resolve_definition(
|
resolved.extend(resolve_definition(
|
||||||
db,
|
db,
|
||||||
|
|
@ -332,7 +332,7 @@ pub fn definitions_for_attribute<'db>(
|
||||||
let use_def = index.use_def_map(function_scope_id);
|
let use_def = index.use_def_map(function_scope_id);
|
||||||
|
|
||||||
// Check declarations first
|
// Check declarations first
|
||||||
for decl in use_def.all_reachable_member_declarations(place_id) {
|
for decl in use_def.reachable_member_declarations(place_id) {
|
||||||
if let Some(def) = decl.declaration.definition() {
|
if let Some(def) = decl.declaration.definition() {
|
||||||
resolved.extend(resolve_definition(
|
resolved.extend(resolve_definition(
|
||||||
db,
|
db,
|
||||||
|
|
@ -345,7 +345,7 @@ pub fn definitions_for_attribute<'db>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no declarations found, check bindings
|
// If no declarations found, check bindings
|
||||||
for binding in use_def.all_reachable_member_bindings(place_id) {
|
for binding in use_def.reachable_member_bindings(place_id) {
|
||||||
if let Some(def) = binding.binding.definition() {
|
if let Some(def) = binding.binding.definition() {
|
||||||
resolved.extend(resolve_definition(
|
resolved.extend(resolve_definition(
|
||||||
db,
|
db,
|
||||||
|
|
@ -1096,8 +1096,8 @@ mod resolve_definition {
|
||||||
let mut definitions = IndexSet::new();
|
let mut definitions = IndexSet::new();
|
||||||
|
|
||||||
// Get all definitions (both bindings and declarations) for this place
|
// Get all definitions (both bindings and declarations) for this place
|
||||||
let bindings = use_def_map.all_reachable_symbol_bindings(symbol_id);
|
let bindings = use_def_map.reachable_symbol_bindings(symbol_id);
|
||||||
let declarations = use_def_map.all_reachable_symbol_declarations(symbol_id);
|
let declarations = use_def_map.reachable_symbol_declarations(symbol_id);
|
||||||
|
|
||||||
for binding in bindings {
|
for binding in bindings {
|
||||||
if let Some(def) = binding.binding.definition() {
|
if let Some(def) = binding.binding.definition() {
|
||||||
|
|
|
||||||
|
|
@ -8894,7 +8894,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
||||||
// If we're inferring types of deferred expressions, look them up from end-of-scope.
|
// If we're inferring types of deferred expressions, look them up from end-of-scope.
|
||||||
if self.is_deferred() {
|
if self.is_deferred() {
|
||||||
let place = if let Some(place_id) = place_table.place_id(expr) {
|
let place = if let Some(place_id) = place_table.place_id(expr) {
|
||||||
place_from_bindings(db, use_def.all_reachable_bindings(place_id)).place
|
place_from_bindings(db, use_def.reachable_bindings(place_id)).place
|
||||||
} else {
|
} else {
|
||||||
assert!(
|
assert!(
|
||||||
self.deferred_state.in_string_annotation(),
|
self.deferred_state.in_string_annotation(),
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ fn check_class_declaration<'db>(
|
||||||
&& PROHIBITED_NAMEDTUPLE_ATTRS.contains(&member.name.as_str())
|
&& PROHIBITED_NAMEDTUPLE_ATTRS.contains(&member.name.as_str())
|
||||||
&& let Some(symbol_id) = place_table(db, class_scope).symbol_id(&member.name)
|
&& let Some(symbol_id) = place_table(db, class_scope).symbol_id(&member.name)
|
||||||
&& let Some(bad_definition) = use_def_map(db, class_scope)
|
&& let Some(bad_definition) = use_def_map(db, class_scope)
|
||||||
.all_reachable_bindings(ScopedPlaceId::Symbol(symbol_id))
|
.reachable_bindings(ScopedPlaceId::Symbol(symbol_id))
|
||||||
.filter_map(|binding| binding.binding.definition())
|
.filter_map(|binding| binding.binding.definition())
|
||||||
.find(|def| !matches!(def.kind(db), DefinitionKind::AnnotatedAssignment(_)))
|
.find(|def| !matches!(def.kind(db), DefinitionKind::AnnotatedAssignment(_)))
|
||||||
&& let Some(builder) = context.report_lint(
|
&& let Some(builder) = context.report_lint(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue