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

Function function_scope

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

Source from the content-addressed store, hash-verified

1503
1504 #[test]
1505 fn function_scope() {
1506 let TestCase { db, file } = test_case(
1507 "
1508def func():
1509 x = 1
1510y = 2
1511",
1512 );
1513 let module = parsed_module(&db, program_file(&db, file).python_file(&db)).load(&db);
1514 let index = semantic_index(&db, program_file(&db, file));
1515 let global_table = index.place_table(FileScopeId::global());
1516
1517 assert_eq!(names(global_table), vec!["func", "y"]);
1518
1519 let [(function_scope_id, function_scope)] = index
1520 .child_scopes(FileScopeId::global())
1521 .collect::<Vec<_>>()[..]
1522 else {
1523 panic!("expected one child scope")
1524 };
1525 assert_eq!(function_scope.kind(), ScopeKind::Function);
1526 assert_eq!(
1527 function_scope_id
1528 .to_scope_id(&db, program_file(&db, file))
1529 .name(&db, &module),
1530 "func"
1531 );
1532
1533 let function_table = index.place_table(function_scope_id);
1534 assert_eq!(names(function_table), vec!["x"]);
1535
1536 let use_def = index.use_def_map(function_scope_id);
1537 let binding = use_def
1538 .first_public_binding(function_table.symbol_id("x").expect("symbol exists"))
1539 .unwrap();
1540 assert_matches!(binding.kind(&db), DefinitionKind::Assignment(_));
1541 }
1542
1543 #[test]
1544 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