3612013
From 70f3f3c87fcb254373f54011270fbe40b6507a0d Mon Sep 17 00:00:00 2001
3612013
From: "Benjamin A. Beasley" <code@musicinmybrain.net>
3612013
Date: Thu, 13 Jan 2022 20:30:54 -0500
3612013
Subject: [PATCH 1/2] Make pyrsistent._pmap doctests order-insensitive
3612013
MIME-Version: 1.0
3612013
Content-Type: text/plain; charset=UTF-8
3612013
Content-Transfer-Encoding: 8bit
3612013
3612013
This keeps them from failing if CPython’s hashing algorithms change,
3612013
fixing #238.
3612013
---
3612013
 pyrsistent/_pmap.py | 48 ++++++++++++++++++++++-----------------------
3612013
 1 file changed, 24 insertions(+), 24 deletions(-)
3612013
3612013
diff --git a/pyrsistent/_pmap.py b/pyrsistent/_pmap.py
3612013
index 81d99c0..056d478 100644
3612013
--- a/pyrsistent/_pmap.py
3612013
+++ b/pyrsistent/_pmap.py
3612013
@@ -31,12 +31,12 @@ class PMap(object):
3612013
     >>> m1 = m(a=1, b=3)
3612013
     >>> m2 = m1.set('c', 3)
3612013
     >>> m3 = m2.remove('a')
3612013
-    >>> m1
3612013
-    pmap({'b': 3, 'a': 1})
3612013
-    >>> m2
3612013
-    pmap({'c': 3, 'b': 3, 'a': 1})
3612013
-    >>> m3
3612013
-    pmap({'c': 3, 'b': 3})
3612013
+    >>> m1 == {'a': 1, 'b': 3}
3612013
+    True
3612013
+    >>> m2 == {'a': 1, 'b': 3, 'c': 3}
3612013
+    True
3612013
+    >>> m3 == {'b': 3, 'c': 3}
3612013
+    True
3612013
     >>> m3['c']
3612013
     3
3612013
     >>> m3.c
3612013
@@ -171,12 +171,12 @@ def set(self, key, val):
3612013
         >>> m1 = m(a=1, b=2)
3612013
         >>> m2 = m1.set('a', 3)
3612013
         >>> m3 = m1.set('c' ,4)
3612013
-        >>> m1
3612013
-        pmap({'b': 2, 'a': 1})
3612013
-        >>> m2
3612013
-        pmap({'b': 2, 'a': 3})
3612013
-        >>> m3
3612013
-        pmap({'c': 4, 'b': 2, 'a': 1})
3612013
+        >>> m1 == {'a': 1, 'b': 2}
3612013
+        True
3612013
+        >>> m2 == {'a': 3, 'b': 2}
3612013
+        True
3612013
+        >>> m3 == {'a': 1, 'b': 2, 'c': 4}
3612013
+        True
3612013
         """
3612013
         return self.evolver().set(key, val).persistent()
3612013
 
3612013
@@ -213,8 +213,8 @@ def update(self, *maps):
3612013
         maps the rightmost (last) value is inserted.
3612013
 
3612013
         >>> m1 = m(a=1, b=2)
3612013
-        >>> m1.update(m(a=2, c=3), {'a': 17, 'd': 35})
3612013
-        pmap({'c': 3, 'b': 2, 'a': 17, 'd': 35})
3612013
+        >>> m1.update(m(a=2, c=3), {'a': 17, 'd': 35}) == {'a': 17, 'b': 2, 'c': 3, 'd': 35}
3612013
+        True
3612013
         """
3612013
         return self.update_with(lambda l, r: r, *maps)
3612013
 
3612013
@@ -225,8 +225,8 @@ def update_with(self, update_fn, *maps):
3612013
 
3612013
         >>> from operator import add
3612013
         >>> m1 = m(a=1, b=2)
3612013
-        >>> m1.update_with(add, m(a=2))
3612013
-        pmap({'b': 2, 'a': 3})
3612013
+        >>> m1.update_with(add, m(a=2)) == {'a': 3, 'b': 2}
3612013
+        True
3612013
 
3612013
         The reverse behaviour of the regular merge. Keep the leftmost element instead of the rightmost.
3612013
 
3612013
@@ -381,15 +381,15 @@ def evolver(self):
3612013
 
3612013
         The underlying pmap remains the same:
3612013
 
3612013
-        >>> m1
3612013
-        pmap({'b': 2, 'a': 1})
3612013
+        >>> m1 == {'a': 1, 'b': 2}
3612013
+        True
3612013
 
3612013
         The changes are kept in the evolver. An updated pmap can be created using the
3612013
         persistent() function on the evolver.
3612013
 
3612013
         >>> m2 = e.persistent()
3612013
-        >>> m2
3612013
-        pmap({'c': 3, 'b': 2})
3612013
+        >>> m2 == {'b': 2, 'c': 3}
3612013
+        True
3612013
 
3612013
         The new pmap will share data with the original pmap in the same way that would have
3612013
         been done if only using operations on the pmap.
3612013
@@ -442,8 +442,8 @@ def pmap(initial={}, pre_size=0):
3612013
     may have a positive performance impact in the cases where you know beforehand that a large number of elements
3612013
     will be inserted into the map eventually since it will reduce the number of reallocations required.
3612013
 
3612013
-    >>> pmap({'a': 13, 'b': 14})
3612013
-    pmap({'b': 14, 'a': 13})
3612013
+    >>> pmap({'a': 13, 'b': 14}) == {'a': 13, 'b': 14}
3612013
+    True
3612013
     """
3612013
     if not initial and pre_size == 0:
3612013
         return _EMPTY_PMAP
3612013
@@ -455,7 +455,7 @@ def m(**kwargs):
3612013
     """
3612013
     Creates a new persistent map. Inserts all key value arguments into the newly created map.
3612013
 
3612013
-    >>> m(a=13, b=14)
3612013
-    pmap({'b': 14, 'a': 13})
3612013
+    >>> m(a=13, b=14) == {'a': 13, 'b': 14}
3612013
+    True
3612013
     """
3612013
     return pmap(kwargs)
3612013
3612013
From e09ed69b32b8c5ab139a32e154ebe6e6a3e5744e Mon Sep 17 00:00:00 2001
3612013
From: "Benjamin A. Beasley" <code@musicinmybrain.net>
3612013
Date: Thu, 13 Jan 2022 20:33:21 -0500
3612013
Subject: [PATCH 2/2] No longer need to set PYTHONHASHSEED=0
3612013
3612013
Now that there are no doctests sensitive to string keying order,
3612013
randomized hashing will not cause doctest failures.
3612013
---
3612013
 tox.ini | 3 ---
3612013
 1 file changed, 3 deletions(-)
3612013
3612013
diff --git a/tox.ini b/tox.ini
3612013
index b77d93b..f05caeb 100644
3612013
--- a/tox.ini
3612013
+++ b/tox.ini
3612013
@@ -44,9 +44,6 @@ changedir = .
3612013
 commands = python tests/memory_profiling.py
3612013
 
3612013
 [testenv:doctest38]
3612013
-# Need to disable the random hashing or all docs printing a map with more than
3612013
-# one item in it will be flaky.
3612013
-setenv = PYTHONHASHSEED=0
3612013
 basepython = python3.8
3612013
 deps = pytest
3612013
 changedir = .