Missing argument/default errors

19 views
Skip to first unread message

Matthew Berry

unread,
Jun 25, 2024, 10:32:47 AM6/25/24
to xlSlim Support
Hi Russel,

I am running xlSlim 3.3.1.0

I have the following function, which tests some default arguments:

def test_args(series_id:str, sort:int=1, limit:int=None, fill:bool=True) -> List[List]:
    output = [ ['series_id', series_id, repr(type(series_id))], 
               ['sort',      sort,      repr(type(sort))], 
               ['limit',     limit,     repr(type(limit))], 
               ['fill',      fill,      repr(type(fill))] ]
    return output

It is called from Excel like this: =test_args("DBAA")

It returns, as follows.  The errors are in red

series_id DBAA <class 'str'>
sort 0.00 <class 'int'>
limit #N/A <class 'NoneType'>
fill FALSE <class 'bool'>

As the sort and fill arguments were missing, they should default to 1 and True respectively.  Somehow, this isn't happening.  It works when called from within Python. So I think this is probably a bug.

Thanks!
Matt


xlSlim Dev

unread,
Jun 25, 2024, 1:08:20 PM6/25/24
to xlSlim Support
Thanks I will investigate. Which version of Python are you running?

xlSlim Dev

unread,
Jun 25, 2024, 1:14:49 PM6/25/24
to xlSlim Support
Hi,

I believe the type hints are slightly incorrect, they should be Optional[int], Optional[bool], etc

This version works for me:

from typing import Optional

def test_args(series_id:str, sort:Optional[int]=1, limit:Optional[int]=None, fill:Optional[bool]=True) -> List[List]:

    output = [ ['series_id', series_id, repr(type(series_id))],
               ['sort',      sort,      repr(type(sort))],
               ['limit',     limit,     repr(type(limit))],
               ['fill',      fill,      repr(type(fill))] ]
    return output

All the best,
Russel

xlSlim Dev

unread,
Jun 25, 2024, 1:32:28 PM6/25/24
to xlSlim Support
Python's typing docs indicate that sort:int = 1 is perfectly acceptable, so xlSlim should handle it. I will investigate further. In the meantime, amending to explicitly be Optional[int] fixes the bug.

Matthew Berry

unread,
Jun 25, 2024, 1:55:40 PM6/25/24
to xlSlim Dev, xlSlim Support
Awesome. I will start making optional type hints explicit.  Thanks for your help.

--
You received this message because you are subscribed to the Google Groups "xlSlim Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xlslim-suppor...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/xlslim-support/47cf09ce-9280-4d9e-bb65-804370927c72n%40googlegroups.com.

xlSlim Dev

unread,
Jun 27, 2024, 11:23:13 AM6/27/24
to xlSlim Support
Hi Matt,

This is fixed in 3.3.2
 
Both versions:

def test_args(series_id:str, sort:int=1, limit:int=None, fill:bool=True) -> List[List]:
    output = [ ['series_id', series_id, repr(type(series_id))], 
               ['sort',      sort,      repr(type(sort))], 
               ['limit',     limit,     repr(type(limit))], 
               ['fill',      fill,      repr(type(fill))] ]
    return output

def test_args(series_id:str, sort:Optional[int]=1, limit:Optional[int]=None, fill:Optional[bool]=True) -> List[List]:

    output = [ ['series_id', series_id, repr(type(series_id))],
               ['sort',      sort,      repr(type(sort))],
               ['limit',     limit,     repr(type(limit))],
               ['fill',      fill,      repr(type(fill))] ]
    return output

now work as expected.

Regards,
Russel
Reply all
Reply to author
Forward
0 new messages