astroid icon indicating copy to clipboard operation
astroid copied to clipboard

Unexpected node listed in Call.keywords

Open ltcmelo opened this issue 5 years ago • 2 comments

This is about the Call node. One of its fields is keywords, and another is kwargs. The former, according to the doc (and intuitively as well), is expected to list the keyword-based arguments; the latter, any unpacking argument.

Now, consider this function:

def ggg(pos_param, **kwargs):
    pass

And the calls 1 and 2:

ggg(123, some_param='actualarg', another_param=456)  # 1

ddd = {'whatever': 'sss', 'other_param': 9.99}
ggg(456, **ddd) # 2

For call 1, I get an empty node.kwargs and 2 Keyword elements in the list of node.keywords. I find this expected.

For call 2, I get on Keyword element in node.kwargs and the same element in node.keywords. I find this unexpected in 2 ways:

  • first, ddd shouldn't be in node.keywords (since it isn't itself a keyword argument), only in node.kwargs;
  • second, ddd shouldn't be a Keyword object, but an unpacking expression.

ltcmelo avatar Aug 17 '20 17:08 ltcmelo

NOTE: There was a change from Python 3.4 to 3.5 in this area; maybe I should rely just on Keyword

ltcmelo avatar Aug 18 '20 11:08 ltcmelo

Thanks for the report.

PCManticore avatar Dec 27 '20 09:12 PCManticore