diff --git a/crates/ty_ide/src/goto_references.rs b/crates/ty_ide/src/goto_references.rs index 1f6d5063f5..40d5ea8de9 100644 --- a/crates/ty_ide/src/goto_references.rs +++ b/crates/ty_ide/src/goto_references.rs @@ -38,7 +38,7 @@ mod tests { impl CursorTest { fn references(&self) -> String { - let Some(reference_results) = + let Some(mut reference_results) = goto_references(&self.db, self.cursor.file, self.cursor.offset, true) else { return "No references found".to_string(); @@ -48,6 +48,8 @@ mod tests { return "No references found".to_string(); } + reference_results.sort_by_key(ReferenceTarget::file); + self.render_diagnostics(reference_results.into_iter().enumerate().map( |(i, ref_item)| -> ReferenceResult { ReferenceResult { diff --git a/crates/ty_python_semantic/resources/mdtest/subscript/tuple.md b/crates/ty_python_semantic/resources/mdtest/subscript/tuple.md index a5be45f5cb..b85065fb06 100644 --- a/crates/ty_python_semantic/resources/mdtest/subscript/tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/subscript/tuple.md @@ -75,7 +75,7 @@ def f(h4: HeterogeneousSubclass4, i: int): class MixedSubclass(tuple[I0, *tuple[I1, ...], I2, I3, I2, I5]): ... -# revealed: Overload[(self, index: Literal[0], /) -> I0, (self, index: Literal[2, 3], /) -> I1 | I2 | I3, (self, index: Literal[-1], /) -> I5, (self, index: Literal[1], /) -> I1 | I2, (self, index: Literal[-3], /) -> I3, (self, index: Literal[-5], /) -> I1 | I0, (self, index: Literal[-4, -2], /) -> I2, (self, index: Literal[4], /) -> I1 | I2 | I3 | I5, (self, index: SupportsIndex, /) -> I0 | I1 | I2 | I3 | I5, (self, index: slice[Any, Any, Any], /) -> tuple[I0 | I1 | I2 | I3 | I5, ...]] +# revealed: Overload[(self, index: Literal[0], /) -> I0, (self, index: Literal[-5], /) -> I1 | I0, (self, index: Literal[-1], /) -> I5, (self, index: Literal[1], /) -> I1 | I2, (self, index: Literal[-4, -2], /) -> I2, (self, index: Literal[2, 3], /) -> I1 | I2 | I3, (self, index: Literal[-3], /) -> I3, (self, index: Literal[4], /) -> I1 | I2 | I3 | I5, (self, index: SupportsIndex, /) -> I0 | I1 | I2 | I3 | I5, (self, index: slice[Any, Any, Any], /) -> tuple[I0 | I1 | I2 | I3 | I5, ...]] reveal_type(MixedSubclass.__getitem__) def g(m: MixedSubclass, i: int): @@ -105,7 +105,7 @@ def g(m: MixedSubclass, i: int): class MixedSubclass2(tuple[I0, I1, *tuple[I2, ...], I3]): ... -# revealed: Overload[(self, index: Literal[-1], /) -> I3, (self, index: Literal[0], /) -> I0, (self, index: Literal[-2], /) -> I2 | I1, (self, index: Literal[2], /) -> I2 | I3, (self, index: Literal[1], /) -> I1, (self, index: Literal[-3], /) -> I2 | I1 | I0, (self, index: SupportsIndex, /) -> I0 | I1 | I2 | I3, (self, index: slice[Any, Any, Any], /) -> tuple[I0 | I1 | I2 | I3, ...]] +# revealed: Overload[(self, index: Literal[0], /) -> I0, (self, index: Literal[-2], /) -> I2 | I1, (self, index: Literal[1], /) -> I1, (self, index: Literal[-3], /) -> I2 | I1 | I0, (self, index: Literal[-1], /) -> I3, (self, index: Literal[2], /) -> I2 | I3, (self, index: SupportsIndex, /) -> I0 | I1 | I2 | I3, (self, index: slice[Any, Any, Any], /) -> tuple[I0 | I1 | I2 | I3, ...]] reveal_type(MixedSubclass2.__getitem__) def g(m: MixedSubclass2, i: int): diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 5e3bbc7029..65af4b9880 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -27,7 +27,7 @@ use crate::types::{ infer_definition_types, }; use crate::{ - Db, FxOrderSet, KnownModule, Program, + Db, FxIndexMap, FxOrderSet, KnownModule, Program, module_resolver::file_to_module, place::{ Boundness, LookupError, LookupResult, Place, PlaceAndQualifiers, class_symbol, @@ -53,7 +53,7 @@ use ruff_db::parsed::{ParsedModuleRef, parsed_module}; use ruff_python_ast::name::Name; use ruff_python_ast::{self as ast, PythonVersion}; use ruff_text_size::{Ranged, TextRange}; -use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; +use rustc_hash::{FxHashSet, FxHasher}; type FxOrderMap = ordermap::map::OrderMap>; @@ -628,8 +628,8 @@ impl<'db> ClassType<'db> { .map(|spec| { let tuple = spec.tuple(db); - let mut element_type_to_indices: FxHashMap, Vec> = - FxHashMap::default(); + let mut element_type_to_indices: FxIndexMap, Vec> = + FxIndexMap::default(); match tuple { // E.g. for `tuple[int, str]`, we will generate the following overloads: