@@ -5,6 +5,7 @@ use ruff_db::files::File;
55use ruff_db:: parsed:: parsed_module;
66use ruff_index:: { IndexSlice , IndexVec } ;
77
8+ use ruff_python_ast:: PythonVersion ;
89use rustc_hash:: { FxBuildHasher , FxHashMap , FxHashSet } ;
910use salsa:: plumbing:: AsId ;
1011use salsa:: Update ;
@@ -45,7 +46,13 @@ type SymbolMap = hashbrown::HashMap<ScopedSymbolId, (), FxBuildHasher>;
4546pub ( crate ) fn semantic_index ( db : & dyn Db , file : File ) -> SemanticIndex < ' _ > {
4647 let _span = tracing:: trace_span!( "semantic_index" , file = %file. path( db) ) . entered ( ) ;
4748
48- let parsed = parsed_module ( db. upcast ( ) , file) ;
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 ( ) ) ;
4956
5057 SemanticIndexBuilder :: new ( db, file, parsed) . build ( )
5158}
@@ -409,7 +416,7 @@ mod tests {
409416 use ruff_db:: files:: { system_path_to_file, File } ;
410417 use ruff_db:: parsed:: parsed_module;
411418 use ruff_db:: system:: DbWithTestSystem ;
412- use ruff_python_ast as ast;
419+ use ruff_python_ast:: { self as ast, PythonVersion } ;
413420 use ruff_text_size:: { Ranged , TextRange } ;
414421
415422 use crate :: db:: tests:: TestDb ;
@@ -830,7 +837,7 @@ def f(a: str, /, b: str, c: int = 1, *args, d: int = 2, **kwargs):
830837
831838 let use_def = index. use_def_map ( comprehension_scope_id) ;
832839
833- let module = parsed_module ( & db, file) . syntax ( ) ;
840+ let module = parsed_module ( & db, file, PythonVersion :: default ( ) ) . syntax ( ) ;
834841 let element = module. body [ 0 ]
835842 . as_expr_stmt ( )
836843 . unwrap ( )
@@ -1079,7 +1086,7 @@ class C[T]:
10791086 #[ test]
10801087 fn reachability_trivial ( ) {
10811088 let TestCase { db, file } = test_case ( "x = 1; x" ) ;
1082- let parsed = parsed_module ( & db, file) ;
1089+ let parsed = parsed_module ( & db, file, PythonVersion :: default ( ) ) ;
10831090 let scope = global_scope ( & db, file) ;
10841091 let ast = parsed. syntax ( ) ;
10851092 let ast:: Stmt :: Expr ( ast:: StmtExpr {
@@ -1112,7 +1119,7 @@ class C[T]:
11121119 let TestCase { db, file } = test_case ( "x = 1;\n def test():\n y = 4" ) ;
11131120
11141121 let index = semantic_index ( & db, file) ;
1115- let parsed = parsed_module ( & db, file) ;
1122+ let parsed = parsed_module ( & db, file, PythonVersion :: default ( ) ) ;
11161123 let ast = parsed. syntax ( ) ;
11171124
11181125 let x_stmt = ast. body [ 0 ] . as_assign_stmt ( ) . unwrap ( ) ;
0 commit comments