MCPcopy Create free account
hub / github.com/astral-sh/ruff / function_scope

Function function_scope

crates/ty_python_core/src/lib.rs:1305–1341  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1303
1304 #[test]
1305 fn function_scope() {
1306 let TestCase { db, file } = test_case(
1307 "
1308def func():
1309 x = 1
1310y = 2
1311",
1312 );
1313 let module = parsed_module(&db, program_file(&db, file).python_file(&db)).load(&db);
1314 let index = semantic_index(&db, program_file(&db, file));
1315 let global_table = index.place_table(FileScopeId::global());
1316
1317 assert_eq!(names(global_table), vec!["func", "y"]);
1318
1319 let [(function_scope_id, function_scope)] = index
1320 .child_scopes(FileScopeId::global())
1321 .collect::<Vec<_>>()[..]
1322 else {
1323 panic!("expected one child scope")
1324 };
1325 assert_eq!(function_scope.kind(), ScopeKind::Function);
1326 assert_eq!(
1327 function_scope_id
1328 .to_scope_id(&db, program_file(&db, file))
1329 .name(&db, &module),
1330 "func"
1331 );
1332
1333 let function_table = index.place_table(function_scope_id);
1334 assert_eq!(names(function_table), vec!["x"]);
1335
1336 let use_def = index.use_def_map(function_scope_id);
1337 let binding = use_def
1338 .first_public_binding(function_table.symbol_id("x").expect("symbol exists"))
1339 .unwrap();
1340 assert!(matches!(binding.kind(&db), DefinitionKind::Assignment(_)));
1341 }
1342
1343 #[test]
1344 fn function_parameter_symbols() {

Callers

nothing calls this directly

Calls 12

test_caseFunction · 0.85
parsed_moduleFunction · 0.85
semantic_indexFunction · 0.85
place_tableMethod · 0.80
child_scopesMethod · 0.80
use_def_mapMethod · 0.80
first_public_bindingMethod · 0.80
expectMethod · 0.80
program_fileFunction · 0.70
loadMethod · 0.45
python_fileMethod · 0.45
symbol_idMethod · 0.45

Tested by

no test coverage detected