Repository navigation
Document when on_setattr hooks run - #1663
Open
iamdatvt94 wants to merge 1 commit into
Open
iamdatvt94 wants to merge 1 commit into
iamdatvt94 wants to merge 1 commit into
Conversation
chrikrah
approved these changes
Nov 26, 2026
chrikrah
left a comment
There was a problem hiding this comment.
@iamdatvt94 The paragraph is accurate for the generated __init__, and the doctest pins it, so I'm approving; one gap below, non-blocking.
# head 225715e (base 2a1fb86), git archive, Python 3.14, attr.__file__ under the tree
$ sphinx-build -n -T -W -b doctest -d /tmp/dt docs docs/_build/html
477 tests, 0 failures in tests # 471 at 2a1fb86
# first expected `3` edited to `6`
1 failure in tests, init.md line 536
# your Counter, plus __attrs_post_init__ doing self.count = self.count + 1
>>> Counter(3).count
8
non-blocking: the new text sits right under the execution order list that ends with __attrs_post_init__, and an assignment made there does go through the hook (3 + 1, doubled). A reader could take "skips on_setattr hooks" to cover the whole construction. I'd add a clause along the lines of "an assignment you make in __attrs_post_init__ is an ordinary assignment and runs them".
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #672.
Clarify why a custom
on_setattrhook runs on assignment but is skipped when the generated__init__initializes fields. The example shows the same value passed through both paths, and the guide points readers to converters and validators for initialization-time behavior.Testing
tox run -e docs-doctests,docs-buildon Windows with Python 3.14.git diff --check.Pull Request Checklist
OpenAI Codex assisted with the documentation change and verification. I reviewed the diff before submission.