Skip to content

Commit b70f989

Browse files
committed
dict equality - objects always equal themselves.
1 parent bd5772d commit b70f989

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

tests/snippets/dict.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
assert not {'a': 4} == {'a': 2}
1212
assert {'a': 2} == {'a': 2}
1313

14+
nan = float('nan')
15+
assert {'a': nan} == {'a': nan}
16+
1417
a = {'g': 5}
1518
b = {'a': a, 'd': 9}
1619
c = dict(b)

vm/src/obj/objdict.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::fmt;
33

44
use crate::function::{KwArgs, OptionalArg};
55
use crate::pyobject::{
6-
IntoPyObject, ItemProtocol, PyAttributes, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
6+
IdProtocol, IntoPyObject, ItemProtocol, PyAttributes, PyContext, PyObjectRef, PyRef, PyResult,
7+
PyValue,
78
};
89
use crate::vm::{ReprGuard, VirtualMachine};
910

@@ -104,6 +105,9 @@ impl PyDictRef {
104105
for (k, v1) in self {
105106
match other.entries.borrow().get(vm, &k)? {
106107
Some(v2) => {
108+
if v1.is(&v2) {
109+
continue;
110+
}
107111
let value = objbool::boolval(vm, vm._eq(v1, v2)?)?;
108112
if !value {
109113
return Ok(false);

0 commit comments

Comments
 (0)