@@ -203,14 +203,14 @@ pub(crate) fn symbol<'db>(
203
203
db : & ' db dyn Db ,
204
204
scope : ScopeId < ' db > ,
205
205
name : & str ,
206
- considered_bindings : ConsideredBindings ,
206
+ considered_definitions : ConsideredDefinitions ,
207
207
) -> PlaceAndQualifiers < ' db > {
208
208
symbol_impl (
209
209
db,
210
210
scope,
211
211
name,
212
212
RequiresExplicitReExport :: No ,
213
- considered_bindings ,
213
+ considered_definitions ,
214
214
)
215
215
}
216
216
@@ -220,14 +220,14 @@ pub(crate) fn place<'db>(
220
220
db : & ' db dyn Db ,
221
221
scope : ScopeId < ' db > ,
222
222
expr : & PlaceExpr ,
223
- considered_bindings : ConsideredBindings ,
223
+ considered_definitions : ConsideredDefinitions ,
224
224
) -> PlaceAndQualifiers < ' db > {
225
225
place_impl (
226
226
db,
227
227
scope,
228
228
expr,
229
229
RequiresExplicitReExport :: No ,
230
- considered_bindings ,
230
+ considered_definitions ,
231
231
)
232
232
}
233
233
@@ -246,7 +246,7 @@ pub(crate) fn class_symbol<'db>(
246
246
scope,
247
247
symbol,
248
248
RequiresExplicitReExport :: No ,
249
- ConsideredBindings :: LiveBindingsAtUse ,
249
+ ConsideredDefinitions :: AllLiveAtUse ,
250
250
) ;
251
251
252
252
if symbol_and_quals. is_class_var ( ) {
@@ -267,7 +267,7 @@ pub(crate) fn class_symbol<'db>(
267
267
db,
268
268
bindings,
269
269
RequiresExplicitReExport :: No ,
270
- ConsideredBindings :: LiveBindingsAtUse ,
270
+ ConsideredDefinitions :: AllLiveAtUse ,
271
271
) ;
272
272
273
273
// TODO: we should not need to calculate inferred type second time. This is a temporary
@@ -303,7 +303,7 @@ pub(crate) fn explicit_global_symbol<'db>(
303
303
global_scope ( db, file) ,
304
304
name,
305
305
RequiresExplicitReExport :: No ,
306
- ConsideredBindings :: AllReachable ,
306
+ ConsideredDefinitions :: AllReachable ,
307
307
)
308
308
}
309
309
@@ -362,7 +362,7 @@ pub(crate) fn imported_symbol<'db>(
362
362
global_scope ( db, file) ,
363
363
name,
364
364
requires_explicit_reexport,
365
- ConsideredBindings :: LiveBindingsAtUse ,
365
+ ConsideredDefinitions :: AllLiveAtUse ,
366
366
)
367
367
. or_fall_back_to ( db, || {
368
368
if name == "__getattr__" {
@@ -392,7 +392,7 @@ pub(crate) fn builtins_symbol<'db>(db: &'db dyn Db, symbol: &str) -> PlaceAndQua
392
392
global_scope ( db, file) ,
393
393
symbol,
394
394
RequiresExplicitReExport :: Yes ,
395
- ConsideredBindings :: LiveBindingsAtUse ,
395
+ ConsideredDefinitions :: AllLiveAtUse ,
396
396
)
397
397
. or_fall_back_to ( db, || {
398
398
// We're looking up in the builtins namespace and not the module, so we should
@@ -463,13 +463,13 @@ fn core_module_scope(db: &dyn Db, core_module: KnownModule) -> Option<ScopeId<'_
463
463
pub ( super ) fn place_from_bindings < ' db > (
464
464
db : & ' db dyn Db ,
465
465
bindings_with_constraints : BindingWithConstraintsIterator < ' _ , ' db > ,
466
- considered_bindings : ConsideredBindings , // TODO: remove this and always use `LiveBindingsAtUse` here?
466
+ considered_definitions : ConsideredDefinitions , // TODO: remove this and always use `LiveBindingsAtUse` here?
467
467
) -> Place < ' db > {
468
468
place_from_bindings_impl (
469
469
db,
470
470
bindings_with_constraints,
471
471
RequiresExplicitReExport :: No ,
472
- considered_bindings ,
472
+ considered_definitions ,
473
473
)
474
474
}
475
475
@@ -484,8 +484,14 @@ pub(super) fn place_from_bindings<'db>(
484
484
pub ( crate ) fn place_from_declarations < ' db > (
485
485
db : & ' db dyn Db ,
486
486
declarations : DeclarationsIterator < ' _ , ' db > ,
487
+ considered_definitions : ConsideredDefinitions ,
487
488
) -> PlaceFromDeclarationsResult < ' db > {
488
- place_from_declarations_impl ( db, declarations, RequiresExplicitReExport :: No )
489
+ place_from_declarations_impl (
490
+ db,
491
+ declarations,
492
+ RequiresExplicitReExport :: No ,
493
+ considered_definitions,
494
+ )
489
495
}
490
496
491
497
/// The result of looking up a declared type from declarations; see [`place_from_declarations`].
@@ -619,7 +625,7 @@ fn place_cycle_recover<'db>(
619
625
_scope : ScopeId < ' db > ,
620
626
_place_id : ScopedPlaceId ,
621
627
_requires_explicit_reexport : RequiresExplicitReExport ,
622
- _considered_bindings : ConsideredBindings ,
628
+ _considered_definitions : ConsideredDefinitions ,
623
629
) -> salsa:: CycleRecoveryAction < PlaceAndQualifiers < ' db > > {
624
630
salsa:: CycleRecoveryAction :: Iterate
625
631
}
@@ -629,7 +635,7 @@ fn place_cycle_initial<'db>(
629
635
_scope : ScopeId < ' db > ,
630
636
_place_id : ScopedPlaceId ,
631
637
_requires_explicit_reexport : RequiresExplicitReExport ,
632
- _considered_bindings : ConsideredBindings ,
638
+ _considered_definitions : ConsideredDefinitions ,
633
639
) -> PlaceAndQualifiers < ' db > {
634
640
Place :: bound ( Type :: Never ) . into ( )
635
641
}
@@ -640,19 +646,28 @@ fn place_by_id<'db>(
640
646
scope : ScopeId < ' db > ,
641
647
place_id : ScopedPlaceId ,
642
648
requires_explicit_reexport : RequiresExplicitReExport ,
643
- considered_bindings : ConsideredBindings ,
649
+ considered_definitions : ConsideredDefinitions ,
644
650
) -> PlaceAndQualifiers < ' db > {
645
651
let use_def = use_def_map ( db, scope) ;
646
652
647
653
// If the place is declared, the public type is based on declarations; otherwise, it's based
648
654
// on inference from bindings.
649
655
650
- let declarations = use_def. public_declarations ( place_id) ;
651
- let declared = place_from_declarations_impl ( db, declarations, requires_explicit_reexport) ;
656
+ let declarations = match considered_definitions {
657
+ ConsideredDefinitions :: AllLiveAtUse => use_def. end_of_scope_declarations ( place_id) ,
658
+ ConsideredDefinitions :: AllReachable => use_def. reachable_declarations ( place_id) ,
659
+ } ;
660
+
661
+ let declared = place_from_declarations_impl (
662
+ db,
663
+ declarations,
664
+ requires_explicit_reexport,
665
+ considered_definitions,
666
+ ) ;
652
667
653
- let all_considered_bindings = || match considered_bindings {
654
- ConsideredBindings :: LiveBindingsAtUse => use_def. end_of_scope_bindings ( place_id) ,
655
- ConsideredBindings :: AllReachable => use_def. potentially_reachable_bindings ( place_id) ,
668
+ let all_considered_bindings = || match considered_definitions {
669
+ ConsideredDefinitions :: AllLiveAtUse => use_def. end_of_scope_bindings ( place_id) ,
670
+ ConsideredDefinitions :: AllReachable => use_def. reachable_bindings ( place_id) ,
656
671
} ;
657
672
658
673
match declared {
@@ -673,7 +688,7 @@ fn place_by_id<'db>(
673
688
db,
674
689
bindings,
675
690
requires_explicit_reexport,
676
- considered_bindings ,
691
+ considered_definitions ,
677
692
) ;
678
693
679
694
let place = match inferred {
@@ -703,7 +718,7 @@ fn place_by_id<'db>(
703
718
db,
704
719
bindings,
705
720
requires_explicit_reexport,
706
- considered_bindings ,
721
+ considered_definitions ,
707
722
) ;
708
723
709
724
// `__slots__` is a symbol with special behavior in Python's runtime. It can be
@@ -763,7 +778,7 @@ fn symbol_impl<'db>(
763
778
scope : ScopeId < ' db > ,
764
779
name : & str ,
765
780
requires_explicit_reexport : RequiresExplicitReExport ,
766
- considered_bindings : ConsideredBindings ,
781
+ considered_definitions : ConsideredDefinitions ,
767
782
) -> PlaceAndQualifiers < ' db > {
768
783
let _span = tracing:: trace_span!( "symbol" , ?name) . entered ( ) ;
769
784
@@ -789,7 +804,7 @@ fn symbol_impl<'db>(
789
804
scope,
790
805
symbol,
791
806
requires_explicit_reexport,
792
- considered_bindings ,
807
+ considered_definitions ,
793
808
)
794
809
} )
795
810
. unwrap_or_default ( )
@@ -801,7 +816,7 @@ fn place_impl<'db>(
801
816
scope : ScopeId < ' db > ,
802
817
expr : & PlaceExpr ,
803
818
requires_explicit_reexport : RequiresExplicitReExport ,
804
- considered_bindings : ConsideredBindings ,
819
+ considered_definitions : ConsideredDefinitions ,
805
820
) -> PlaceAndQualifiers < ' db > {
806
821
let _span = tracing:: trace_span!( "place" , ?expr) . entered ( ) ;
807
822
@@ -813,7 +828,7 @@ fn place_impl<'db>(
813
828
scope,
814
829
place,
815
830
requires_explicit_reexport,
816
- considered_bindings ,
831
+ considered_definitions ,
817
832
)
818
833
} )
819
834
. unwrap_or_default ( )
@@ -828,7 +843,7 @@ fn place_from_bindings_impl<'db>(
828
843
db : & ' db dyn Db ,
829
844
bindings_with_constraints : BindingWithConstraintsIterator < ' _ , ' db > ,
830
845
requires_explicit_reexport : RequiresExplicitReExport ,
831
- considered_bindings : ConsideredBindings ,
846
+ considered_definitions : ConsideredDefinitions ,
832
847
) -> Place < ' db > {
833
848
let predicates = bindings_with_constraints. predicates ;
834
849
let reachability_constraints = bindings_with_constraints. reachability_constraints ;
@@ -943,12 +958,12 @@ fn place_from_bindings_impl<'db>(
943
958
) ;
944
959
945
960
if let Some ( first) = types. next ( ) {
946
- let boundness = match considered_bindings {
947
- ConsideredBindings :: AllReachable => {
961
+ let boundness = match considered_definitions {
962
+ ConsideredDefinitions :: AllReachable => {
948
963
// TODO: explain why we do this
949
964
Boundness :: Bound
950
965
}
951
- ConsideredBindings :: LiveBindingsAtUse => {
966
+ ConsideredDefinitions :: AllLiveAtUse => {
952
967
// If we have at least one binding, the implicit `unbound` binding should not be
953
968
// definitely visible.
954
969
match unbound_reachability ( ) {
@@ -987,6 +1002,7 @@ fn place_from_declarations_impl<'db>(
987
1002
db : & ' db dyn Db ,
988
1003
declarations : DeclarationsIterator < ' _ , ' db > ,
989
1004
requires_explicit_reexport : RequiresExplicitReExport ,
1005
+ considered_definitions : ConsideredDefinitions ,
990
1006
) -> PlaceFromDeclarationsResult < ' db > {
991
1007
let predicates = declarations. predicates ;
992
1008
let reachability_constraints = declarations. reachability_constraints ;
@@ -1050,14 +1066,17 @@ fn place_from_declarations_impl<'db>(
1050
1066
first
1051
1067
} ;
1052
1068
if conflicting. is_empty ( ) {
1053
- let boundness = match undeclared_reachability {
1054
- Truthiness :: AlwaysTrue => {
1055
- unreachable ! (
1056
- "If we have at least one declaration, the implicit `unbound` binding should not be definitely visible"
1057
- )
1058
- }
1059
- Truthiness :: AlwaysFalse => Boundness :: Bound ,
1060
- Truthiness :: Ambiguous => Boundness :: PossiblyUnbound ,
1069
+ let boundness = match considered_definitions {
1070
+ ConsideredDefinitions :: AllReachable => Boundness :: Bound ,
1071
+ ConsideredDefinitions :: AllLiveAtUse => match undeclared_reachability {
1072
+ Truthiness :: AlwaysTrue => {
1073
+ unreachable ! (
1074
+ "If we have at least one declaration, the implicit `unbound` binding should not be definitely visible"
1075
+ )
1076
+ }
1077
+ Truthiness :: AlwaysFalse => Boundness :: Bound ,
1078
+ Truthiness :: Ambiguous => Boundness :: PossiblyUnbound ,
1079
+ } ,
1061
1080
} ;
1062
1081
1063
1082
Ok (
@@ -1102,7 +1121,7 @@ mod implicit_globals {
1102
1121
use ruff_python_ast as ast;
1103
1122
1104
1123
use crate :: db:: Db ;
1105
- use crate :: place:: PlaceAndQualifiers ;
1124
+ use crate :: place:: { ConsideredDefinitions , PlaceAndQualifiers } ;
1106
1125
use crate :: semantic_index:: place:: PlaceExpr ;
1107
1126
use crate :: semantic_index:: { self , place_table, use_def_map} ;
1108
1127
use crate :: types:: { KnownClass , Type } ;
@@ -1130,7 +1149,8 @@ mod implicit_globals {
1130
1149
} ;
1131
1150
place_from_declarations (
1132
1151
db,
1133
- use_def_map ( db, module_type_scope) . public_declarations ( place_id) ,
1152
+ use_def_map ( db, module_type_scope) . end_of_scope_declarations ( place_id) ,
1153
+ ConsideredDefinitions :: AllLiveAtUse ,
1134
1154
)
1135
1155
}
1136
1156
@@ -1251,9 +1271,9 @@ impl RequiresExplicitReExport {
1251
1271
}
1252
1272
1253
1273
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , Update ) ]
1254
- pub ( crate ) enum ConsideredBindings {
1274
+ pub ( crate ) enum ConsideredDefinitions {
1255
1275
AllReachable ,
1256
- LiveBindingsAtUse ,
1276
+ AllLiveAtUse ,
1257
1277
}
1258
1278
1259
1279
/// Computes a possibly-widened type `Unknown | T_inferred` from the inferred type `T_inferred`
0 commit comments