Do some normalization of error messages from argument checking - #16038
Open
dcbaker wants to merge 18 commits into
Open
Do some normalization of error messages from argument checking#16038dcbaker wants to merge 18 commits into
dcbaker wants to merge 18 commits into
Conversation
All of this can be handled by typed_kwargs instead.
We will make more use of these later
this gives more consistent output between them.
This allows us to use slots easily, which reduces our memory usage. It also allows us to implement `evolve()` in terms of `dataclasses.replace`, which simplifies our work considerably.
…cated_values This allows writing simpler descriptions when adding or removing multiples types.
Including the new tuple of types support.
The problem for this function is it basically has two overloaded signatures: (name: str, ...sources: str | File) () This is really difficult to model for `typed_pos_args`, because optional arguments and variadic arguments are inherently ambiguous. We can, however, use variadic arguments and then narrow the allowed type for the first argument if it's given.
dcbaker
force-pushed
the
submit/typed-args-normalize
branch
from
July 27, 2026 17:19
006a275 to
6821d80
Compare
dnicolodi
reviewed
Jul 31, 2026
| else: | ||
| shouldbe = f'"{type_.__name__}"' | ||
| raise InvalidArguments(f'{name} argument {i} was of type "{type(arg).__name__}" but should have been {shouldbe}') | ||
| raise InvalidArguments(f'{name} argument {i} was of type "{_raw_description(arg)}" but should have been {_types_description(type_)}') |
Member
There was a problem hiding this comment.
Any reason to remove the double quotes around {_types_description(type_)}? I find having the quotes around the actual type but not around the expected type a distracting asymmetry.
dnicolodi
reviewed
Jul 31, 2026
| candidates.append(t.__name__) | ||
| shouldbe = 'one of: ' if len(candidates) > 1 else '' | ||
| shouldbe += ', '.join(candidates) | ||
| shouldbe += ', '.join(f'"{c}"' for c in candidates) |
Member
There was a problem hiding this comment.
Never mind, the quotes are coming back here...
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.
This is ground work for a larger set of work to clean up argument validation.
There's also a few cases of making use of typed_kwargs and typed_pos_args for checking where it was previously being done by open coding.