Python: Fix bug in handling of **kwargs
in class bases
#17809
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This caused a dataset check error on the
python/cpython
database, as we had aDictUnpacking
node whose parent was not adict_item_list
, but rather anexpr_list
.Investigating a bit further revealed that this was because in a construction like
we were mistakenly adding
**kwargs
to the same list asbase
(which is just a list of expressions), rather than the same list asfoo=bar
(which is a list of dictionary items)The ultimate cause of this was the use of
! name
inpython.tsg
to distinguish between bases and keyword arguments (only the latter of which have thename
field). Becausedictionary_splat
doesn't have aname
field either, these were mistakenly put in the wrong list, leading to the error.Also, because our previous test of
class
statements did not include a**kwargs
construction, we were not checking that the new parser behaved correctly in this case. For the most part this was not a problem, but on files that use syntax not supported by the old parser (like type parameters on classes), this became an issue. This is alsowhy we did not see this error previously.
To fix this, we added
! value
(which is a field present ondictionary_splat
nodes) as a secondary filter, and added a third stanza to handledictionary_splat
nodes.Pull Request checklist
All query authors
.qhelp
. See the documentation in this repository.Internal query authors only
.ql
,.qll
, or.qhelp
files. See the documentation (internal access required).