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

Fixed frozen and cache_hash incompatibility #612

Merged
merged 3 commits into from
Jan 13, 2020

Conversation

pganssle
Copy link
Member

@pganssle pganssle commented Jan 7, 2020

This uses the same mechanism to clear the cache hash as __hash__ uses to set the cache hash in frozen classes - bypassing the object's __setattr__ in favor of object.__setattr__. Neat trick.

Fixes #611.

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) New features have been added to our Hypothesis testing strategy.
  • (N/A) Changes or additions to public APIs are reflected in our type stubs (files ending in .pyi).
  • (N/A) Updated documentation for changed code.
  • 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!

tests/test_make.py Outdated Show resolved Hide resolved
changelog.d/611.change.rst Outdated Show resolved Hide resolved
tests/test_make.py Outdated Show resolved Hide resolved
@pganssle pganssle force-pushed the fix_frozen_cache_hash branch from 809e0d0 to a2a6713 Compare January 8, 2020 16:30
Copy link
Member Author

@pganssle pganssle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review Hynek!

This is a failing test for GH issue python-attrs#611, with the xfail decorator to be
removed when the issue is fixed.
@pganssle pganssle force-pushed the fix_frozen_cache_hash branch from a2a6713 to b7a5dcd Compare January 8, 2020 17:04
Fixes GH issue python-attrs#611: serialization of a class with frozen=True and
cache_hash=True will now succeed rather than raising a
FrozenInstanceError.
@pganssle pganssle force-pushed the fix_frozen_cache_hash branch from b7a5dcd to fa5b63c Compare January 8, 2020 17:06
@pganssle
Copy link
Member Author

pganssle commented Jan 8, 2020

Oops, thanks to the coverage result I realized that the test was copying the class, not an instance of the class. This is what I get for skipping my usual semi-TDD style of putting the test under an xfail in a separate commit, and removing the xfail in the commit that fixes it, so I've refactored the commit history a bit.

Feel free to squash the commits if you don't like that style - I mainly do it to give an easy(-enough)-to-verify way to show that the test is probably testing what we expect.

@hynek hynek merged commit 9b5e988 into python-attrs:master Jan 13, 2020
@hynek
Copy link
Member

hynek commented Jan 13, 2020

Thanks, Paul!

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.

frozen=True incompatible with cache_hash=True as of 19.1.0
2 participants