forked from Rust-related/RustPython
Merge pull request #4548 from youknowone/hash-tuple
Prepare to implement hash for tuple
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use super::{PyInt, PyIntRef, PySlice, PyTupleRef, PyType, PyTypeRef};
|
||||
use crate::atomic_func;
|
||||
use crate::common::hash::PyHash;
|
||||
use super::{
|
||||
builtins_iter, tuple::tuple_hash, PyInt, PyIntRef, PySlice, PyTupleRef, PyType, PyTypeRef,
|
||||
};
|
||||
use crate::{
|
||||
builtins::builtins_iter,
|
||||
atomic_func,
|
||||
class::PyClassImpl,
|
||||
common::hash::PyHash,
|
||||
function::{FuncArgs, OptionalArg, PyComparisonValue},
|
||||
protocol::{PyIterReturn, PyMappingMethods, PySequenceMethods},
|
||||
types::{
|
||||
@@ -442,7 +443,7 @@ impl Hashable for PyRange {
|
||||
zelf.step().into(),
|
||||
]
|
||||
};
|
||||
crate::utils::hash_iter(elements.iter(), vm)
|
||||
tuple_hash(&elements, vm)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use super::{PositionIterInternal, PyGenericAlias, PyType, PyTypeRef};
|
||||
use crate::atomic_func;
|
||||
use crate::common::{hash::PyHash, lock::PyMutex};
|
||||
use crate::{
|
||||
atomic_func,
|
||||
class::PyClassImpl,
|
||||
convert::{ToPyObject, TransmuteFromObject},
|
||||
function::{OptionalArg, PyArithmeticValue, PyComparisonValue},
|
||||
@@ -372,7 +372,7 @@ impl AsSequence for PyTuple {
|
||||
impl Hashable for PyTuple {
|
||||
#[inline]
|
||||
fn hash(zelf: &crate::Py<Self>, vm: &VirtualMachine) -> PyResult<PyHash> {
|
||||
crate::utils::hash_iter(zelf.elements.iter(), vm)
|
||||
tuple_hash(zelf.as_slice(), vm)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,3 +523,9 @@ impl<T: TransmuteFromObject> ToPyObject for PyTupleTyped<T> {
|
||||
self.tuple.into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn tuple_hash(elements: &[PyObjectRef], vm: &VirtualMachine) -> PyResult<PyHash> {
|
||||
// TODO: See #3460 for the correct implementation.
|
||||
// https://github.com/RustPython/RustPython/pull/3460
|
||||
crate::utils::hash_iter(elements.iter(), vm)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user