Skip to content

Commit ab62b0b

Browse files
committed
minor adjustments
1 parent b62ff10 commit ab62b0b

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

crates/ty_python_semantic/src/semantic_index/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ impl<'db, 'ast> SemanticIndexBuilder<'db, 'ast> {
315315
// Records snapshots of the place states visible from the current eager scope.
316316
fn record_eager_snapshots(&mut self, popped_scope_id: FileScopeId) {
317317
let popped_scope = &self.scopes[popped_scope_id];
318+
let popped_scope_is_annotation_scope = popped_scope.kind().is_annotation();
318319

319320
// If the scope that we just popped off is an eager scope, we need to "lock" our view of
320321
// which bindings reach each of the uses in the scope. Loop through each enclosing scope,
@@ -330,6 +331,7 @@ impl<'db, 'ast> SemanticIndexBuilder<'db, 'ast> {
330331
// ```
331332
for enclosing_scope_info in self.scope_stack.iter().rev() {
332333
let enclosing_scope_id = enclosing_scope_info.file_scope_id;
334+
let is_immediately_enclosing_scope = popped_scope.parent() == Some(enclosing_scope_id);
333335
let enclosing_scope_kind = self.scopes[enclosing_scope_id].kind();
334336
let enclosing_place_table = &self.place_tables[enclosing_scope_id];
335337

@@ -352,14 +354,12 @@ impl<'db, 'ast> SemanticIndexBuilder<'db, 'ast> {
352354
nested_scope: popped_scope_id,
353355
nested_laziness: ScopeLaziness::Eager,
354356
};
355-
let is_immediately_enclosing_scope = popped_scope.kind().is_annotation()
356-
&& popped_scope.parent() == Some(enclosing_scope_id);
357357
let eager_snapshot = self.use_def_maps[enclosing_scope_id]
358358
.snapshot_enclosing_state(
359359
enclosing_place_id,
360360
enclosing_scope_kind,
361361
enclosing_place,
362-
is_immediately_enclosing_scope,
362+
popped_scope_is_annotation_scope && is_immediately_enclosing_scope,
363363
);
364364
self.enclosing_snapshots.insert(key, eager_snapshot);
365365
}

crates/ty_python_semantic/src/semantic_index/use_def.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,20 +1188,19 @@ impl<'db> UseDefMapBuilder<'db> {
11881188
enclosing_place: ScopedPlaceId,
11891189
enclosing_scope: ScopeKind,
11901190
enclosing_place_expr: PlaceExprRef,
1191-
is_immediately_enclosing_scope: bool,
1191+
is_parent_of_annotation_scope: bool,
11921192
) -> ScopedEnclosingSnapshotId {
11931193
let bindings = match enclosing_place {
11941194
ScopedPlaceId::Symbol(symbol) => self.symbol_states[symbol].bindings(),
11951195
ScopedPlaceId::Member(member) => self.member_states[member].bindings(),
11961196
};
11971197

11981198
let is_class_symbol = enclosing_scope.is_class() && enclosing_place.is_symbol();
1199-
// Names bound in class scopes are never visible to nested scopes (but attributes/subscripts are visible),
1200-
// so we never need to save eager scope bindings in a class scope.
1201-
// There is one exception to this rule: annotation scopes can see
1202-
// names defined in an immediately-enclosing class scope.
1203-
if (is_class_symbol && !is_immediately_enclosing_scope) || !enclosing_place_expr.is_bound()
1204-
{
1199+
// Names bound in class scopes are never visible to nested scopes (but
1200+
// attributes/subscripts are visible), so we never need to save eager scope bindings in a
1201+
// class scope. There is one exception to this rule: annotation scopes can see names
1202+
// defined in an immediately-enclosing class scope.
1203+
if (is_class_symbol && !is_parent_of_annotation_scope) || !enclosing_place_expr.is_bound() {
12051204
self.enclosing_snapshots.push(EnclosingSnapshot::Constraint(
12061205
bindings.unbound_narrowing_constraint(),
12071206
))

0 commit comments

Comments
 (0)