Skip to content

Commit 4c6b6d1

Browse files
committed
make scope always the last parameter
1 parent ba63be4 commit 4c6b6d1

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

crates/red_knot_python_semantic/src/symbol.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ pub(crate) type LookupResult<'db> = Result<TypeAndQualifiers<'db>, LookupError<'
165165
/// `scope`.
166166
pub(crate) fn symbol<'db>(
167167
db: &'db dyn Db,
168-
scope: ScopeId<'db>,
169168
name: &str,
169+
scope: ScopeId<'db>,
170170
) -> SymbolAndQualifiers<'db> {
171171
symbol_impl(db, scope, name, RequiresExplicitReExport::No)
172172
}
@@ -175,8 +175,8 @@ pub(crate) fn symbol<'db>(
175175
/// `scope`.
176176
pub(crate) fn class_symbol<'db>(
177177
db: &'db dyn Db,
178-
scope: ScopeId<'db>,
179178
name: &str,
179+
scope: ScopeId<'db>,
180180
) -> SymbolAndQualifiers<'db> {
181181
symbol_table(db, scope)
182182
.symbol_id_by_name(name)
@@ -356,8 +356,8 @@ fn core_module_scope(db: &dyn Db, core_module: KnownModule) -> Option<ScopeId<'_
356356
/// The type will be a union if there are multiple bindings with different types.
357357
pub(super) fn symbol_from_bindings<'db>(
358358
db: &'db dyn Db,
359-
scope: ScopeId<'db>,
360359
bindings_with_constraints: BindingWithConstraintsIterator<'_, 'db>,
360+
scope: ScopeId<'db>,
361361
) -> Symbol<'db> {
362362
symbol_from_bindings_impl(
363363
db,

crates/red_knot_python_semantic/src/types/class.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ impl<'db> Class<'db> {
401401
/// directly. Use [`Class::class_member`] if you require a method that will
402402
/// traverse through the MRO until it finds the member.
403403
pub(super) fn own_class_member(self, db: &'db dyn Db, name: &str) -> SymbolAndQualifiers<'db> {
404-
let body_scope = self.body_scope(db);
405-
class_symbol(db, body_scope, name)
404+
class_symbol(db, name, self.body_scope(db))
406405
}
407406

408407
/// Returns the `name` attribute of an instance of this class.
@@ -469,8 +468,8 @@ impl<'db> Class<'db> {
469468
/// "implicitly" defined in a method of the class that corresponds to `class_body_scope`.
470469
fn implicit_instance_attribute(
471470
db: &'db dyn Db,
472-
class_body_scope: ScopeId<'db>,
473471
name: &str,
472+
class_body_scope: ScopeId<'db>,
474473
) -> Option<Type<'db>> {
475474
// If we do not see any declarations of an attribute, neither in the class body nor in
476475
// any method, we build a union of `Unknown` with the inferred types of all bindings of
@@ -571,14 +570,14 @@ impl<'db> Class<'db> {
571570
// The attribute is declared in the class body.
572571

573572
let bindings = use_def.public_bindings(symbol_id);
574-
let inferred = symbol_from_bindings(db, body_scope, bindings);
573+
let inferred = symbol_from_bindings(db, bindings, body_scope);
575574
let has_binding = !inferred.is_unbound();
576575

577576
if has_binding {
578577
// The attribute is declared and bound in the class body.
579578

580579
if let Some(implicit_ty) =
581-
Self::implicit_instance_attribute(db, body_scope, name)
580+
Self::implicit_instance_attribute(db, name, body_scope)
582581
{
583582
if declaredness == Boundness::Bound {
584583
// If a symbol is definitely declared, and we see
@@ -612,7 +611,7 @@ impl<'db> Class<'db> {
612611
declared.with_qualifiers(qualifiers)
613612
} else {
614613
if let Some(implicit_ty) =
615-
Self::implicit_instance_attribute(db, body_scope, name)
614+
Self::implicit_instance_attribute(db, name, body_scope)
616615
{
617616
Symbol::Type(
618617
UnionType::from_elements(db, [declared_ty, implicit_ty]),
@@ -633,7 +632,7 @@ impl<'db> Class<'db> {
633632
// The attribute is not *declared* in the class body. It could still be declared/bound
634633
// in a method.
635634

636-
Self::implicit_instance_attribute(db, body_scope, name)
635+
Self::implicit_instance_attribute(db, name, body_scope)
637636
.map_or(Symbol::Unbound, Symbol::bound)
638637
.into()
639638
}
@@ -646,7 +645,7 @@ impl<'db> Class<'db> {
646645
// This attribute is neither declared nor bound in the class body.
647646
// It could still be implicitly defined in a method.
648647

649-
Self::implicit_instance_attribute(db, body_scope, name)
648+
Self::implicit_instance_attribute(db, name, body_scope)
650649
.map_or(Symbol::Unbound, Symbol::bound)
651650
.into()
652651
}

crates/red_knot_python_semantic/src/types/infer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ impl<'db> TypeInferenceBuilder<'db> {
10581058
let use_def = self.index.use_def_map(declaration.file_scope(self.db()));
10591059
let prior_bindings = use_def.bindings_at_declaration(declaration);
10601060
// unbound_ty is Never because for this check we don't care about unbound
1061-
let inferred_ty = symbol_from_bindings(self.db(), self.scope(), prior_bindings)
1061+
let inferred_ty = symbol_from_bindings(self.db(), prior_bindings, self.scope())
10621062
.ignore_possibly_unbound()
10631063
.unwrap_or(Type::Never);
10641064
let ty = if inferred_ty.is_assignable_to(self.db(), ty.inner_type()) {
@@ -4181,7 +4181,7 @@ impl<'db> TypeInferenceBuilder<'db> {
41814181
// If we're inferring types of deferred expressions, always treat them as public symbols
41824182
let (local_scope_symbol, report_unresolved_usage) = if self.is_deferred() {
41834183
let symbol = if let Some(symbol_id) = symbol_table.symbol_id_by_name(symbol_name) {
4184-
symbol_from_bindings(db, self.scope(), use_def.public_bindings(symbol_id))
4184+
symbol_from_bindings(db, use_def.public_bindings(symbol_id), self.scope())
41854185
} else {
41864186
assert!(
41874187
self.deferred_state.in_string_annotation(),
@@ -4193,7 +4193,7 @@ impl<'db> TypeInferenceBuilder<'db> {
41934193
(symbol, true)
41944194
} else {
41954195
let use_id = name_node.scoped_use_id(db, scope);
4196-
let symbol = symbol_from_bindings(db, self.scope(), use_def.bindings_at_use(use_id));
4196+
let symbol = symbol_from_bindings(db, use_def.bindings_at_use(use_id), self.scope());
41974197
let report_unresolved_usage = use_def.is_symbol_use_reachable(db, use_id);
41984198
(symbol, report_unresolved_usage)
41994199
};
@@ -4258,7 +4258,7 @@ impl<'db> TypeInferenceBuilder<'db> {
42584258
file_scope_id,
42594259
) {
42604260
EagerBindingsResult::Found(bindings) => {
4261-
return symbol_from_bindings(db, self.scope(), bindings).into();
4261+
return symbol_from_bindings(db, bindings, self.scope()).into();
42624262
}
42634263
// There are no visible bindings here.
42644264
// Don't fall back to non-eager symbol resolution.
@@ -4280,7 +4280,7 @@ impl<'db> TypeInferenceBuilder<'db> {
42804280
// runtime, it is the scope that creates the cell for our closure.) If the name
42814281
// isn't bound in that scope, we should get an unbound name, not continue
42824282
// falling back to other scopes / globals / builtins.
4283-
return symbol(db, enclosing_scope_id, symbol_name);
4283+
return symbol(db, symbol_name, enclosing_scope_id);
42844284
}
42854285
}
42864286

@@ -4299,7 +4299,7 @@ impl<'db> TypeInferenceBuilder<'db> {
42994299
file_scope_id,
43004300
) {
43014301
EagerBindingsResult::Found(bindings) => {
4302-
return symbol_from_bindings(db, self.scope(), bindings).into();
4302+
return symbol_from_bindings(db, bindings, self.scope()).into();
43034303
}
43044304
// There are no visible bindings here.
43054305
EagerBindingsResult::NotFound => {
@@ -7455,7 +7455,7 @@ mod tests {
74557455
assert_eq!(scope.name(db), *expected_scope_name);
74567456
}
74577457

7458-
symbol(db, scope, symbol_name).symbol
7458+
symbol(db, symbol_name, scope).symbol
74597459
}
74607460

74617461
#[track_caller]

0 commit comments

Comments
 (0)