@@ -5,7 +5,6 @@ use ruff_db::files::File;
55use ruff_db:: parsed:: parsed_module;
66use ruff_index:: { IndexSlice , IndexVec } ;
77
8- use ruff_python_ast:: PythonVersion ;
98use rustc_hash:: { FxBuildHasher , FxHashMap , FxHashSet } ;
109use salsa:: plumbing:: AsId ;
1110use salsa:: Update ;
@@ -21,7 +20,7 @@ use crate::semantic_index::symbol::{
2120 FileScopeId , NodeWithScopeKey , NodeWithScopeRef , Scope , ScopeId , ScopedSymbolId , SymbolTable ,
2221} ;
2322use crate :: semantic_index:: use_def:: { EagerBindingsKey , ScopedEagerBindingsId , UseDefMap } ;
24- use crate :: Db ;
23+ use crate :: { Db , Program } ;
2524
2625pub mod ast_ids;
2726pub mod attribute_assignment;
@@ -46,13 +45,7 @@ type SymbolMap = hashbrown::HashMap<ScopedSymbolId, (), FxBuildHasher>;
4645pub ( crate ) fn semantic_index ( db : & dyn Db , file : File ) -> SemanticIndex < ' _ > {
4746 let _span = tracing:: trace_span!( "semantic_index" , file = %file. path( db) ) . entered ( ) ;
4847
49- // TODO(brent) need to pass the real PythonVersion here, but tests fail when I change it from
50- // PythonVersion::default()
51- //
52- // I've tried my hacky `python_version` helper function and also
53- // `Program::get(db).python_version(db)`, and many tests fail in both cases (18 with
54- // `python_version`, 48 with `Program::get`)
55- let parsed = parsed_module ( db. upcast ( ) , file, PythonVersion :: default ( ) ) ;
48+ let parsed = parsed_module ( db. upcast ( ) , file, Program :: get ( db) . python_version ( db) ) ;
5649
5750 SemanticIndexBuilder :: new ( db, file, parsed) . build ( )
5851}
@@ -415,11 +408,10 @@ impl FusedIterator for ChildrenIter<'_> {}
415408mod tests {
416409 use ruff_db:: files:: { system_path_to_file, File } ;
417410 use ruff_db:: parsed:: parsed_module;
418- use ruff_db:: system:: DbWithTestSystem ;
419411 use ruff_python_ast:: { self as ast, PythonVersion } ;
420412 use ruff_text_size:: { Ranged , TextRange } ;
421413
422- use crate :: db:: tests:: TestDb ;
414+ use crate :: db:: tests:: { TestDb , TestDbBuilder } ;
423415 use crate :: semantic_index:: ast_ids:: { HasScopedUseId , ScopedUseId } ;
424416 use crate :: semantic_index:: definition:: { Definition , DefinitionKind } ;
425417 use crate :: semantic_index:: symbol:: {
@@ -447,10 +439,14 @@ mod tests {
447439 }
448440
449441 fn test_case ( content : impl ToString ) -> TestCase {
450- let mut db = TestDb :: new ( ) ;
451- db. write_file ( "test.py" , content) . unwrap ( ) ;
442+ const FILENAME : & str = "test.py" ;
452443
453- let file = system_path_to_file ( & db, "test.py" ) . unwrap ( ) ;
444+ let db = TestDbBuilder :: new ( )
445+ . with_file ( FILENAME , & content. to_string ( ) )
446+ . build ( )
447+ . unwrap ( ) ;
448+
449+ let file = system_path_to_file ( & db, FILENAME ) . unwrap ( ) ;
454450
455451 TestCase { db, file }
456452 }
0 commit comments