mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:34:57 +00:00
Fix tests on 32-bit architectures (#19652)
Summary -- Fixes #19640. I'm not sure these are the exact fixes we really want, but I reproduced the issue in a 32-bit Docker container and tracked down the causes, so I figured I'd open a PR. As I commented on the issue, the `goto_references` test depends on the iteration order of the files in an `FxHashSet` in `Indexed`. In this case, we can just sort the output in test code. Similarly, the tuple case depended on the order of overloads inserted in an `FxHashMap`. `FxIndexMap` seemed like a convenient drop-in replacement, but I don't know if that will have other detrimental effects. I did have to change the assertion for the tuple test, but I think it should now be stable across architectures. Test Plan -- Running the tests in the aforementioned Docker container
This commit is contained in:
parent
d2d4b115e3
commit
a71513bae1
3 changed files with 9 additions and 7 deletions
|
@ -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 {
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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<K, V> = ordermap::map::OrderMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||
|
||||
|
@ -628,8 +628,8 @@ impl<'db> ClassType<'db> {
|
|||
.map(|spec| {
|
||||
let tuple = spec.tuple(db);
|
||||
|
||||
let mut element_type_to_indices: FxHashMap<Type<'db>, Vec<i64>> =
|
||||
FxHashMap::default();
|
||||
let mut element_type_to_indices: FxIndexMap<Type<'db>, Vec<i64>> =
|
||||
FxIndexMap::default();
|
||||
|
||||
match tuple {
|
||||
// E.g. for `tuple[int, str]`, we will generate the following overloads:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue