Conversation
…ct_fields When extract_fields is given a list of field names and the function returns a TypedDict, a name that is not in the TypedDict was recorded as an error and then looked up anyway, so users got a bare KeyError instead of the error that lists the invalid fields. Skip the lookup for unknown fields so the collected errors are raised. Generated-by: Claude Code (Claude Opus 5.5)
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.
When
@extract_fieldsgets a list of field names and the function returns aTypedDict, a name that is not in theTypedDictis recorded inerrors. It is then looked up anyway on the next line. Users get a bareKeyErrorat graph-build time instead of theInvalidDecoratorExceptionthat lists the invalid fields.The dict form (
extract_fields({"tset": int})) already reports this properly, because that branchcontinues after recording the error.Changes
hamilton/function_modifiers/expanders.py: in_determine_fields_to_extract,continueafter recording an unknown field, matching the dict branch just below it.tests/function_modifiers/test_expanders.py: one more case intest_extract_fields_invalid_annotations_for_inferred_types,("MyDict", (["test", "not_a_field"])).How I tested this
main(661aa888): fails withKeyError: 'not_a_field'.InvalidDecoratorExceptionis raised).pytest tests/function_modifiers tests/test_function_modifiers.py tests/test_end_to_end.py tests/test_hamilton_driver.py tests/test_async_driver.py: 528 passed.ruff checkandruff format --check(0.15.14) are clean.git diff --checkis clean.Notes
This was introduced with the list-of-names support for
TypedDictin d601a92 (2025-07).Checklist
AI disclosure (per the ASF Generative Tooling guidance): this change was written with an AI coding tool (Claude Code, Claude Opus 5.5) working through the
breken-aiaccount. The tool found the bug, wrote the fix and the test, and wrote this description. The commit carries aGenerated-by:trailer. The diff is a small original change to existing Hamilton code and includes no third-party material. The red/green runs above are real and can be re-run from the diff. If you would rather not take AI-assisted contributions here, say so and I will close this.