Skip to content
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

Allow overriding of the the arg_name convention #867

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

sirosen
Copy link
Collaborator

@sirosen sirosen commented Aug 2, 2023

Rather than {location}_args being a hardcoded behavior, allow users to subclass and override it with a custom method.

This will allow users to set alternate naming conventions in a centralized place, on their parser class. By passing the schema object to get_default_arg_name, we enable schemas which provide their own argument names to the parser.

There are some ordering considerations which make it impossible to guarantee that get_default_arg_name gets a schema object (rather than, e.g. a callable which returns a schema). For this first implementation, I have opted to move the call after any dict-to-schema conversion happens, so that users have fewer types they need to handle.


This PR addresses this thread at the end of #830, but also expands to a use-case which I have and would like to support, which is making the argument names relate to the schema in some way.

Rather than `{location}_args` being a hardcoded behavior, allow users
to subclass and override it with a custom method.

This will allow users to set alternate naming conventions in a
centralized place, on their parser class. By passing the schema object
to get_default_arg_name, we enable schemas which provide their own
argument names to the parser.

There are some ordering considerations which make it impossible to
guarantee that `get_default_arg_name` gets a schema object (rather
than, e.g. a callable which returns a schema). For this first
implementation, I have opted to move the call after any dict-to-schema
conversion happens, so that users have fewer types they need to
handle.
@sirosen sirosen requested a review from lafrech August 2, 2023 15:38
Copy link
Member

@lafrech lafrech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. Nice improvement.

Thanks.

@sirosen sirosen merged commit 0835ede into marshmallow-code:dev Aug 8, 2023
@sirosen sirosen deleted the customizable-arg-name branch August 8, 2023 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants