Resolve field aliases before calling field_transformer#1509
Resolve field aliases before calling field_transformer#1509veeceey wants to merge 2 commits intopython-attrs:mainfrom
Conversation
|
Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed. |
|
Thanks for confirming @AdrianSosic, really glad it solves the problem on your end! Hopefully @hynek can find a moment to take a look when he gets a chance. |
|
Sorry for the delays, but I got caught up in a PR slop wave last week and while your PR looks legit on a brief look, given the current legal status I cannot merge it as long as there's a credit for Claude in the history. This is not meant belligerently in any way; I appreciate that your PR conforms to our current contribution rules and one of the reasons I didn't reply earlier is because I was drafting #1518. I'm happy to take your feedback over there too, FWIW, but until we have more legal clarity, we can't permit the copyright status of attrs to become unclear by having a paper trail of legally questionable contributions. I'm genuinely sorry for the inconvenience, and I would've preferred to spend my time differently too, but these are crazy times. There's also the technical issue of whether this change is too breaking, but I don't want to waste your time/split the discussion until we have mergeable PR. |
5754f24 to
476dcbd
Compare
|
Hey @hynek, good catch - I've cleaned up the git history and removed the co-author attribution. All commits are now solely under my name. Let me know if there's anything else needed! |
|
amazing, thank you for that @veeceey! Before I zoom in on the implementation, and given we had some breakage related to field transformers in the past: hey @ashb is this likely to break Airflow? It looks additive/harmless enough but I'm not sure what kind of assumptions y'all are making. Also cc @sscherfke. |
|
@hynek first thought is that it should be fine as i don't think we use field transformers much if at all. I'll run this through our tests today |
|
All good on the Airflow side, he have exactly one field_transformer which doesn't make any assumptions about private fields or not. |
Previously, field_transformer received attributes with alias=None for fields without an explicit alias. The default alias (e.g., stripping leading underscores) was only resolved after the transformer ran, making it impossible for transformers to access or use alias values. This moves alias resolution to before the field_transformer call, so transformers receive fully populated Attribute objects. A second pass after the transformer handles any new fields the transformer may have added. Additionally, Attribute.evolve() now automatically updates the alias when the name changes, if the alias was auto-generated (matching the default for the old name). Explicit aliases are preserved. Fixes python-attrs#1479
- Update extending.md doctest to reflect that field_transformer now
receives pre-resolved aliases (use alias == name.lstrip("_") instead
of `not field.alias` to detect auto-generated aliases)
- Add changelog entry for python-attrs#1479
- Add test_hook_new_field_without_alias to cover the post-transformer
alias resolution path (line 496 of _make.py)
476dcbd to
ebb6f6a
Compare
|
Thanks for running the tests @ashb, glad to hear it's all clear on the Airflow side! @hynek just a heads up - I noticed the commit messages still had co-author lines from earlier, and the PR description had a leftover attribution line too. I've now cleaned both up completely - the git history and PR description are fully clean. Ready for your review whenever you get a chance! |
Summary
Fixes #1479
_privatetoprivate) to before thefield_transformercallback, so transformers receive fully populatedAttributeobjects with usablealiasvalues instead ofNone.Attribute.evolve()to automatically update the alias when thenamechanges, if the alias was auto-generated (matches the default for the old name). Explicit aliases are preserved.Before (broken)
After (fixed)
Test plan
test_hook_alias_available- verifies transformer sees resolved aliasestest_hook_evolve_name_updates_auto_alias- verifiesevolve(name=...)updates auto-generated aliastest_hook_evolve_name_keeps_explicit_alias- verifiesevolve(name=...)preserves explicit aliasNone