[ty] Dont provide goto definition for definitions which are not reexported in builtins (#21127)

This commit is contained in:
Matthew Mckee 2025-10-29 18:39:36 +00:00 committed by GitHub
parent d38a5292d2
commit 7045898ffa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

@ -1592,6 +1592,23 @@ a = Test()
");
}
/// Regression test for <https://github.com/astral-sh/ty/issues/1451>.
/// We must ensure we respect re-import convention for stub files for
/// imports in builtins.pyi.
#[test]
fn goto_definition_unimported_symbol_imported_in_builtins() {
let test = CursorTest::builder()
.source(
"main.py",
"
Traceb<CURSOR>ackType
",
)
.build();
assert_snapshot!(test.goto_definition(), @"No goto target found");
}
impl CursorTest {
fn goto_definition(&self) -> String {
let Some(targets) = goto_definition(&self.db, self.cursor.file, self.cursor.offset)

View file

@ -615,6 +615,7 @@ pub fn definitions_for_name<'db>(
};
find_symbol_in_scope(db, builtins_scope, name_str)
.into_iter()
.filter(|def| def.is_reexported(db))
.flat_map(|def| {
resolve_definition(
db,