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

Make pyrsistent._pmap doctests order-insensitive #239

Merged
merged 2 commits into from Jan 14, 2022

Conversation

musicinmybrain
Copy link
Contributor

This PR fixes #238 by removing all doctest assumptions about the particular hash values of str or bytes objects.

This keeps them from failing if CPython’s hashing algorithms change,
fixing tobgu#238.
Now that there are no doctests sensitive to string keying order,
randomized hashing will not cause doctest failures.
@musicinmybrain
Copy link
Contributor Author

The doctests in pyrsistent._pset are still sensitive to the hash order of small integers. While this could change in theory, these have always hashed to themselves in CPython.

I would be happy to apply a similar adjustment there if desired, e.g.:

    >>> s = pset([1, 2, 3, 1])
    >>> s2 = s.add(4)
    >>> s3 = s2.remove(2)
    >>> s == {1, 2, 3}
    True

The doctests in pyrsistent._pbag are also sensitive to the hash order of small integers. These are a little more awkward to handle; I think something like this would be needed:

    >>> s = pbag([1, 2, 3, 1])
    >>> s2 = s.add(4)
    >>> s3 = s2.remove(1)
    >>> sorted(s)
    [1, 1, 2, 3]

Please let me know whether you would like me to make these changes or leave the doctests that depend only on small-integer hashing alone.

@tobgu
Copy link
Owner

tobgu commented Jan 14, 2022

Great, thanks!

@tobgu tobgu merged commit 564905c into tobgu:master Jan 14, 2022
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 this pull request may close these issues.

PMap order changes in Python 3.11a3, causing a doctest failure
2 participants