Skip to content

Ensure some keyword arguments are passed as such #223

@jooola

Description

@jooola

Feature Request

In the current API, we define functions with arguments without forcing those arguments to be keyword arguments.

This is fine as long as we don't introduce new fields in the middle of the argument list.

For example:

def get_list(
    name=None,
    architecture=None,
    page=None,  
    per_page=None, 
):
    pass

get_list(name, architecture, 2, 100)

If we add an extra field, we want to keep the organization logic and put the argument before the pagination argument:

 def get_list(
     name=None,
     architecture=None,
+   some_field=None,
     page=None,  
     per_page=None, 
 ):
     pass

But the above would introduce a breaking change for the function call we previously defined:

get_list(name, architecture, 2, 100) # some_field=2, page=100

Describe the solution you'd like

In Python, we can set at which point in the argument list, the argument MUST be keyword arguments:

def get_list(
    name=None,
    *,
    architecture=None,
    page=None,  
    per_page=None, 
):
    pass

This will force the users to use kwargs like the following:

get_list(name, architecture=architecture, page=2, per_page=100)

Using this will allow us adding fields without risk of breaking someone's code.

This is breaking change, this can only happen in v2.0.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions