-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new builtin Spec and conformer for renaming map keys #68
base: master
Are you sure you want to change the base?
Conversation
If ``type_`` is specified, the resulting Spec will only validate the input value as | ||
types named by ``type_``, otherwise :py:class:`dict` will be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you lost me here
def rename_spec( # noqa: MC0001 # pylint: disable=too-many-arguments | ||
tag: Optional[Tag] = None, | ||
replacements: Optional[Mapping[Hashable, Union[Hashable, List[Hashable]]]] = None, | ||
retain_replaced_keys: bool = False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's a big change in a different direction but what if you split this into two specs, rename and copy_value specs. They could reuse this guy under the hood but it might make the api a bit simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would the copy_value spec work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy_value_spec would be rename_spec but hwere retain_replaced_keys = True
This PR adds a new "Spec" factory and conformer under
s.rename
which allows callers to specify simple rename operations as a Spec factory. The Spec returned by this factory performs a simple type check that it's getting adict
(this is configurable by a keyword argument). By default,s.rename
also ships with a validator that ensures no keys are overwritten during the rename (this can be disabled by setting the keyword argumentoverwrite_duplicate_keys=True
). The default conformer will perform the rename operation. The intended use case here is as part of ans.all(...)
chain with a mapping Spec to follow and validate the renamed keys.Fixes #60