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

Function generic_function

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

Source from the content-addressed store, hash-verified

1702
1703 #[test]
1704 fn generic_function() {
1705 let TestCase { db, file } = test_case(
1706 "
1707def func[T]():
1708 x = 1
1709",
1710 );
1711
1712 let module = parsed_module(&db, program_file(&db, file).python_file(&db)).load(&db);
1713 let index = semantic_index(&db, program_file(&db, file));
1714 let global_table = index.place_table(FileScopeId::global());
1715
1716 assert_eq!(names(global_table), vec!["func"]);
1717
1718 let [(ann_scope_id, ann_scope)] = index
1719 .child_scopes(FileScopeId::global())
1720 .collect::<Vec<_>>()[..]
1721 else {
1722 panic!("expected one child scope");
1723 };
1724
1725 assert_eq!(ann_scope.kind(), ScopeKind::TypeParams);
1726 assert_eq!(
1727 ann_scope_id
1728 .to_scope_id(&db, program_file(&db, file))
1729 .name(&db, &module),
1730 "func"
1731 );
1732 let ann_table = index.place_table(ann_scope_id);
1733 assert_eq!(names(ann_table), vec!["T"]);
1734
1735 let [(func_scope_id, func_scope)] =
1736 index.child_scopes(ann_scope_id).collect::<Vec<_>>()[..]
1737 else {
1738 panic!("expected one child scope");
1739 };
1740 assert_eq!(func_scope.kind(), ScopeKind::Function);
1741 assert_eq!(
1742 func_scope_id
1743 .to_scope_id(&db, program_file(&db, file))
1744 .name(&db, &module),
1745 "func"
1746 );
1747 let func_table = index.place_table(func_scope_id);
1748 assert_eq!(names(func_table), vec!["x"]);
1749 }
1750
1751 #[test]
1752 fn generic_class() {

Callers

nothing calls this directly

Calls 8

test_caseFunction · 0.85
parsed_moduleFunction · 0.85
semantic_indexFunction · 0.85
place_tableMethod · 0.80
child_scopesMethod · 0.80
program_fileFunction · 0.70
loadMethod · 0.45
python_fileMethod · 0.45

Tested by

no test coverage detected