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

Recursively evolve nested attrs classes #759

Merged
merged 5 commits into from
Feb 19, 2021
Merged

Conversation

sscherfke
Copy link
Contributor

@sscherfke sscherfke commented Feb 14, 2021

Fixes: #634

Pull Request Check List

This is just a friendly reminder about the most common mistakes. Please make sure that you tick all 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 left to do. If your pull request is a documentation fix or a trivial typo, feel free to delete the whole thing.

  • Added tests for changed code.
  • New features have been added to our Hypothesis testing strategy.
  • Changes or additions to public APIs are reflected in our type stubs (files ending in .pyi).
    • ...and used in the stub test file tests/typing_example.py.
  • 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.
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives. Find the appropriate next version in our __init__.py file.
  • 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!

changelog.d/759.change.rst Outdated Show resolved Hide resolved
src/attr/_funcs.py Outdated Show resolved Hide resolved
docs/examples.rst Outdated Show resolved Hide resolved
tests/test_funcs.py Outdated Show resolved Hide resolved
tests/test_funcs.py Outdated Show resolved Hide resolved
@sscherfke
Copy link
Contributor Author

sscherfke commented Feb 18, 2021

Applied your suggestions and updated the test to include a change to b. :)

@hynek hynek merged commit fe6eb31 into python-attrs:master Feb 19, 2021
@hynek
Copy link
Member

hynek commented Feb 19, 2021

Thanks!

changes[init_name] = value
elif has(value):
# Evolve nested attrs classes
changes[init_name] = evolve(value, **changes[init_name])

Choose a reason for hiding this comment

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

doesn't that break the edge case of legitimately replacing a attrs instance with a dict where permissible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

has(value) makes sure we only attempt recursion when the current value is an attrs class.

I added a test asserting that dicts can still normaly be replaced, nonetheless. :)

sscherfke added a commit that referenced this pull request Feb 19, 2021
hynek added a commit that referenced this pull request May 6, 2021
* Revert "Recursively evolve nested attrs classes (#759)"

* Add regression test

* lol legacy python

* Add newsfragment

* Add a test to prevent inst -> dict replacement breaking
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.

Recursive attr.evolve
3 participants