define: accept the collect_by_mro kwarg that the docstring documents#1580
Closed
HrachShah wants to merge 3 commits into
Closed
define: accept the collect_by_mro kwarg that the docstring documents#1580HrachShah wants to merge 3 commits into
HrachShah wants to merge 3 commits into
Conversation
os.environb yields bytes on POSIX and the documented use case
for to_bool is reading values out of environment variables. The
truthy and falsy lookup tuples only contain str and int, so a
bytes('true') input raised 'Cannot convert value to bool: b\'true\''
even though its ASCII-decoded value is the canonical truthy
literal.
Decode bytes and bytearray as ASCII before the lowercase + lookup
step, matching the str path. Non-ASCII bytes raise ValueError
('Cannot convert value to bool: ...') the same way an unknown
string does, since the decoded text would still not match any
known literal. Unknown byte values raise the same ValueError.
The docstring of attrs.define documents a `collect_by_mro (bool)` parameter and explains its behavior in detail, but the function signature never exposed the kwarg, so `@attrs.define(collect_by_mro=False)` raised `TypeError: define() got an unexpected keyword argument 'collect_by_mro'`. Inside `do_it` the value was hard-coded to `True`, so the documented opt-out for attrs' dataclasses-style "collect fields by MRO in diamond inheritance" behavior was unreachable from the public API. The 2024 "Invert API docs" transplant (python-attrs#1316) moved the parameter docstring from `attr.s` to `attrs.define` but the matching signature addition was missed. This commit finishes that work: add `collect_by_mro=True` to `define()`'s signature (matching the previous hard-coded default) and forward the value through `do_it` instead of hard-coding it. Three new tests in TestDefineCollectByMro: - test_define_accepts_collect_by_mro_kwarg: the basic reproducer (`@attrs.define(collect_by_mro=False)`) — fails on the pre-fix code with the TypeError above, passes with the fix. - test_define_collect_by_mro_false_matches_attrs_false: a linear inheritance graph produced by `@attrs.define(collect_by_mro=False)` has the same field order in __init__ and repr as the equivalent `@attr.s(collect_by_mro=False)` class (the dataclasses-style path). Fails on the pre-fix code (TypeError on the kwargs), passes with the fix. - test_define_collect_by_mro_default_is_true: regression guard so future edits don't drop the default value (the behavior that `do_it` has had since 2020). Verified with `python3 -m pytest tests/test_next_gen.py tests/test_make.py tests/test_funcs.py tests/test_validators.py tests/test_converters.py`: 592 passed, 1 pre-existing unrelated failure (test_converters.py::TestPipe::test_wrapped_annotation, on main without this change too).
Member
|
thanks, but this is not a missing feature, but a mistake when copying over the docs from that said, your PR is also blatant AI slop that introduces spurious changes and violates several contribution rules. Please read CONTRIBUTING.md and AI_POLICY.md for the futures, thank you. fixed in 45de9be |
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.
Fixes a documentation/behavior mismatch.