@@ -6,8 +6,8 @@ use ruff_python_ast::name::Name;
66use ruff_python_ast:: statement_visitor:: { StatementVisitor , walk_stmt} ;
77use ruff_python_ast:: { self as ast} ;
88
9- use crate :: semantic_index:: global_scope ;
10- use crate :: types:: { Truthiness , Type , infer_scope_expression_type } ;
9+ use crate :: semantic_index:: { SemanticIndex , semantic_index } ;
10+ use crate :: types:: { Truthiness , Type , TypeContext , infer_expression_types } ;
1111use crate :: { Db , ModuleName , resolve_module} ;
1212
1313#[ allow( clippy:: ref_option) ]
@@ -31,7 +31,8 @@ pub(crate) fn dunder_all_names(db: &dyn Db, file: File) -> Option<FxHashSet<Name
3131 let _span = tracing:: trace_span!( "dunder_all_names" , file=?file. path( db) ) . entered ( ) ;
3232
3333 let module = parsed_module ( db, file) . load ( db) ;
34- let mut collector = DunderAllNamesCollector :: new ( db, file) ;
34+ let index = semantic_index ( db, file) ;
35+ let mut collector = DunderAllNamesCollector :: new ( db, file, index) ;
3536 collector. visit_body ( module. suite ( ) ) ;
3637 collector. into_names ( )
3738}
@@ -41,6 +42,9 @@ struct DunderAllNamesCollector<'db> {
4142 db : & ' db dyn Db ,
4243 file : File ,
4344
45+ /// The semantic index for the module.
46+ index : & ' db SemanticIndex < ' db > ,
47+
4448 /// The origin of the `__all__` variable in the current module, [`None`] if it is not defined.
4549 origin : Option < DunderAllOrigin > ,
4650
@@ -53,10 +57,11 @@ struct DunderAllNamesCollector<'db> {
5357}
5458
5559impl < ' db > DunderAllNamesCollector < ' db > {
56- fn new ( db : & ' db dyn Db , file : File ) -> Self {
60+ fn new ( db : & ' db dyn Db , file : File , index : & ' db SemanticIndex < ' db > ) -> Self {
5761 Self {
5862 db,
5963 file,
64+ index,
6065 origin : None ,
6166 invalid : false ,
6267 names : FxHashSet :: default ( ) ,
@@ -177,7 +182,8 @@ impl<'db> DunderAllNamesCollector<'db> {
177182 ///
178183 /// This function panics if `expr` was not marked as a standalone expression during semantic indexing.
179184 fn standalone_expression_type ( & self , expr : & ast:: Expr ) -> Type < ' db > {
180- infer_scope_expression_type ( self . db , global_scope ( self . db , self . file ) , expr)
185+ infer_expression_types ( self . db , self . index . expression ( expr) , TypeContext :: default ( ) )
186+ . expression_type ( expr)
181187 }
182188
183189 /// Evaluate the given expression and return its truthiness.
0 commit comments