Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMap order changes in Python 3.11a3, causing a doctest failure #238

Closed
musicinmybrain opened this issue Jan 13, 2022 · 2 comments · Fixed by #239
Closed

PMap order changes in Python 3.11a3, causing a doctest failure #238

musicinmybrain opened this issue Jan 13, 2022 · 2 comments · Fixed by #239

Comments

@musicinmybrain
Copy link
Contributor

musicinmybrain commented Jan 13, 2022

One doctest in pyrsistent/_pmap.py fails on Python 3.11a3 because the order of PMap entries is not as expected.

I suspect this is due to the change from siphash24 to siphash13 for str/bytes.

I’m happy to submit a PR if you can suggest a preferred approach to dealing with this. One way to make these doctests order-insensitive would be to compare against a dict and expect a particular Boolean result, e.g. instead of

    >>> m1
    pmap({'b': 3, 'a': 1})

write

    >>> m1 == {'a': 1, 'b': 2}
    True

but of course this has slightly less value as documentation.

@musicinmybrain
Copy link
Contributor Author

The failing doctest is:

___________________________________ [doctest] pyrsistent._pmap.PMap.update ____________________________________
211 
212         Return a new PMap with the items in Mappings inserted. If the same key is present in multiple
213         maps the rightmost (last) value is inserted.
214 
215         >>> m1 = m(a=1, b=2)
216         >>> m1.update(m(a=2, c=3), {'a': 17, 'd': 35})
Expected:
    pmap({'c': 3, 'b': 2, 'a': 17, 'd': 35})
Got:
    pmap({'d': 35, 'c': 3, 'b': 2, 'a': 17})

/home/ben/src/forks/pyrsistent/pyrsistent/_pmap.py:216: DocTestFailure

(Test command was PYTHONHASHSEED=0 PYTHONPATH="$PWD" pytest --doctest-modules pyrsistent.)

@musicinmybrain musicinmybrain changed the title PMap order changes in Python 3.11a3, causing doctest failures PMap order changes in Python 3.11a3, causing a doctest failure Jan 13, 2022
@tobgu
Copy link
Owner

tobgu commented Jan 13, 2022

Nice find! I'm good with the equality comparison you suggest above even though it's slightly contrived as doc. I haven't found any better way after some very quick research. Please file a PR!

musicinmybrain added a commit to musicinmybrain/pyrsistent that referenced this issue Jan 14, 2022
This keeps them from failing if CPython’s hashing algorithms change,
fixing tobgu#238.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants