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

Add on_setattr hooks to attr.s and attr.ib #660

Merged
merged 9 commits into from
Jul 20, 2020
Merged

Add on_setattr hooks to attr.s and attr.ib #660

merged 9 commits into from
Jul 20, 2020

Conversation

hynek
Copy link
Member

@hynek hynek commented Jul 10, 2020

This fixes #645 and a billion other issues that asked for freezing attributes and validation on assignment.

I'm not married to all the names and open to better suggestions.

Yes, it was more work to integrate than anticipated. 😳


While working on this I've also noticed that we take no precaution about __setattr__ being inherited, which means that if you subclass a frozen class, you can't easily thaw it. This topic is somewhat related to this PR too but I didn't want to bloat it any further. It goes down to setting __setattr__ to object.__setattr__ if we don't write an own, but if auto_detect is true, only if the user didn't write one?

Copy link
Contributor

@euresti euresti left a comment

Choose a reason for hiding this comment

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

I only looked at the type stuff and made some suggestions. Though I wonder if the typevars I'm suggesting are more trouble than they're worth.

src/attr/setters.pyi Outdated Show resolved Hide resolved
changelog.d/645.change.rst Show resolved Hide resolved
tests/test_functional.py Show resolved Hide resolved
src/attr/__init__.pyi Show resolved Hide resolved
src/attr/__init__.pyi Outdated Show resolved Hide resolved
src/attr/setters.pyi Outdated Show resolved Hide resolved
src/attr/setters.pyi Outdated Show resolved Hide resolved
@hynek
Copy link
Member Author

hynek commented Jul 20, 2020

Since there was no more feedback, I'm YOLO-timeouting this. If someone wants to chime in before the release feel free.

@hynek hynek merged commit 2f6fd85 into master Jul 20, 2020
@hynek hynek deleted the setattr branch July 20, 2020 10:43
@hynek
Copy link
Member Author

hynek commented Jul 20, 2020

P.S. @euresti I took the liberty to relax _ConverterType based on your comments in a74c32b…feel free to yell at me if that's terrible and should be done differently.

@hhnguyen-axon
Copy link

Hi @hynek, I wonder if we have any release plan for this fix? We're having some use-cases which requires this and we're eagerly looking for it to be released. If anything we can help to make it release sooner, can you let us know?

@hynek
Copy link
Member Author

hynek commented Aug 17, 2020

#666 is the last remaining part of the puzzle. I hope I’ll be able to release this week.

@hhnguyen-axon
Copy link

Sounds great, thanks so much @hynek

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.

[RFC] __setattr__ hooks
3 participants