Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Order of keyword args between versions can cause breakage. #526

Closed
dhermes opened this issue Sep 27, 2016 · 4 comments
Closed

Order of keyword args between versions can cause breakage. #526

dhermes opened this issue Sep 27, 2016 · 4 comments
Assignees
Labels
lang: python Issues specific to Python.

Comments

@dhermes
Copy link

dhermes commented Sep 27, 2016

In Python, keyword args can also be passed as positional args. So in gapic-google-logging-v2 (0.9.3), LoggingServiceV2Api.list_log_entries had the signature:

def list_log_entries(self,
                     project_ids,
                     filter_='',
                     order_by='',
                     page_size=0,
                     options=None):

but in gapic-google-logging-v2 (0.10.1), it became:

def list_log_entries(self,
                     project_ids,
                     resource_names=None,
                     filter_='',
                     order_by='',
                     page_size=0,
                     options=None):

i.e. it grew resource_names in the middle. Hence when we called via positional only

page_iter = self._gax_api.list_log_entries(
    projects, filter_, order_by, page_size, options)

that code broke on the upgrade from 0.9.x to 0.10.x.


This is somewhat fine, but if you wanted, you could force users to always use some arguments as keywords by using *args, **kwargs and then unpacking args according to a specified length needed for positional and then removing from kwargs to sanitize.

@geigerj
Copy link
Contributor

geigerj commented Sep 29, 2016

@bjwatson and I discussed this, and our initial opinion is not to take such a strong definition of what constitutes a breaking change; that is, if code breaks because it calls keyword arguments as positional parameters, that's not our concern.

To support this would require either (1) moving the options parameter to always be the first argument, and ensuring new optional arguments always appear at the end of the parameter list, or (2) using *args, **kwargs as the signature for all functions as you suggested. We'd prefer not to do (1) for stylistic and pragmatic reasons, and (2) seems un-Pythonic.

Still open to more discussion before we settle, though. @jonparrott, do you have any thoughts on this?

@theacodes
Copy link

Please don't use *args, **kwargs as the signature for all functions.

In general, I feel that the calling code should specify keyword arguments explicitly. If we were in a Python 3-only world, we could use keyword only arguments.

@geigerj
Copy link
Contributor

geigerj commented Nov 23, 2016

I don't think we intend to change GAPIC in this area; we'll consider it the responsibility of the calling code to specify kwargs explicitly.

@geigerj geigerj closed this as completed Nov 23, 2016
@theacodes
Copy link

theacodes commented Nov 24, 2016 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang: python Issues specific to Python.
Projects
None yet
Development

No branches or pull requests

3 participants