Skip to content

Improve documentation of safety constraints on hashable objects#505

Merged
hynek merged 5 commits intopython-attrs:masterfrom
gabbard:503-hash-safety-docs
Feb 14, 2019
Merged

Improve documentation of safety constraints on hashable objects#505
hynek merged 5 commits intopython-attrs:masterfrom
gabbard:503-hash-safety-docs

Conversation

@gabbard
Copy link
Copy Markdown
Member

@gabbard gabbard commented Feb 14, 2019

Although #503 referred to cache_hash, on reflection it occurred to me that the concern is valid for all hashable objects. At the same time, I've clarified the documentation to be clear that if you mutate a cache_hash object or an object referred to in its hash computation, the resulting object hash code is undefined. This seemed better than making any more particular comment since it leaves the API uncommitted as to whether the hash code is computed at object-construction time or lazily on the first call to hash

This closes #503 .

Pull Request Check List

This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!

If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.

  • Added tests for changed code. (n/a, docs only)
  • [X ] New features have been added to our Hypothesis testing strategy. (n/a, docs only)
  • Changes or additions to public APIs are reflected in our type stubs (files ending in .pyi). (n/a, docs only)
    • ...and used in the stub test file tests/typing_example.py. (n/a, docs only)
  • Updated documentation for changed code.
    • New functions/classes have to be added to docs/api.rst by hand.
    • Changes to the signature of @attr.s() have to be added by hand too.
    • [X ] Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Documentation in .rst files is written using semantic newlines.
  • Changes (and possible deprecations) have news fragments in changelog.d.

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

Ryan Gabbard added 4 commits October 31, 2018 17:04
Sync up to main attrs repository
Makes clear that hashable objects need to be deeply immutable, in
practice even if not in theory.

Closes python-attrs#503 .
@gabbard gabbard changed the title Improve documentation of safety constraints on hashable objects [WIP] Improve documentation of safety constraints on hashable objects Feb 14, 2019
@gabbard gabbard changed the title [WIP] Improve documentation of safety constraints on hashable objects Improve documentation of safety constraints on hashable objects Feb 14, 2019
@gabbard
Copy link
Copy Markdown
Member Author

gabbard commented Feb 14, 2019

@hynek : Ready for review.

@hynek hynek merged commit 659aa48 into python-attrs:master Feb 14, 2019
@hynek
Copy link
Copy Markdown
Member

hynek commented Feb 14, 2019

thanks!

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.

Requirement for safety of cache_hash is stronger than documented

2 participants