-1

I am receiving this warning, and I want to prepare in advance for this version update

[*] Updating Google sheet.../home/myname/.local/lib/python3.11/site-packages/gspread/worksheet.py:1046: 
UserWarning: [Deprecated][in version 6.0.0]: method signature will change to: 'Worksheet.update(value = [[]], range_name=)' arguments 'range_name' and 'values' will swap, values will be mandatory of type: 'list(list(...))'
  warnings.warn(
Done.

We are currently using gspread 5.10.0, here is function signature on our machine

myname@my-machine:~/ourdir-analytics/project$ python3.11
Python 3.11.0 (main, Aug 21 2023, 05:23:52) [GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect
>>> from gspread import Worksheet  # or wherever the update function is located
>>> 
>>> sig = inspect.signature(Worksheet.update)
>>> print(sig)
(self, range_name, values=None, **kwargs)
>>> 

I've tried the following, and have received the following errors

# a helper function to connect to spreadsheet
def get_sheets_tab(spreadsheet_name, worksheet_name):
    print('[*] Accessing sheets account... ', flush=True, end='')
    key_file = settings.SERVICE_ACCOUNT_FILE_LINUX if platform.system() == 'Linux' else settings.SERVICE_ACCOUNT_FILE_MAC
    gc = gspread.service_account(key_file)
    print('Done.', flush=True)
    sheet = gc.open(spreadsheet_name) # have to grab tabs by index #, so bad...
    tab = sheet.worksheet(worksheet_name)

    return tab

calling update(), here is where the issue lies, with the named parameters

import gspread
tab = get_sheets_tab("our tools", "our sheet tab")

# try 1
tab.update(values = [output_df.columns.values.tolist()] + output_df.values.tolist())
# error 1 # TypeError: update got unexpected keyword arguments: ['values']

tab.update(value = [output_df.columns.values.tolist()] + output_df.values.tolist())
# error 2 # update got unexpected keyword arguments: ['value']

tab.update(range_name = 'A1', values = [output_df.columns.values.tolist()] + output_df.values.tolist())
# error 3 # update got unexpected keyword arguments: ['value', 'range_name']

`tab.update(values = [output_df.columns.values.tolist()] + output_df.values.tolist())` is throwing the error
# error 4 # update got unexpected keyword arguments: ['values', 'range_name']

This function works just fine if I remove all parameter names, however the whole purpose of what I am doing here is attempting to add the parameter names so that the warning won't be a problem in the future. What's going on here? Why can't I pass parameter names to this function?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Canovice
  • 9,012
  • 22
  • 93
  • 211
  • 1
    If they're positional-only and swapping order then you _can't_ prepare in advance. – jonrsharpe Aug 21 '23 at 11:04
  • I see. There's no way to used named parameters for this? – Canovice Aug 21 '23 at 13:39
  • 1
    First, I deeply apologize that my answer was not useful. About `What's going on here? Why can't I pass parameter names to this function?`, when the script of `Worksheet.update` is seen, the range and values are directly used as the values. [Ref](https://github.com/burnash/gspread/blob/master/gspread/worksheet.py#L967) I think that the reason for your issue is due to this. But, although I'm not sure whether I could correctly understand, I noticed that `method signature will change to: 'Worksheet.update(value = [[]], range_name=)'` is added in the script. Is this related to your expected result? – Tanaike Aug 22 '23 at 02:21

0 Answers0