Skip to content

fixbug: set name for **kwargs#48

Open
CyanM0un wants to merge 2 commits intoantgroup:mainfrom
CyanM0un:main
Open

fixbug: set name for **kwargs#48
CyanM0un wants to merge 2 commits intoantgroup:mainfrom
CyanM0un:main

Conversation

@CyanM0un
Copy link
Contributor

@CyanM0un CyanM0un commented Feb 15, 2026

Note

Low Risk
Small, localized AST-to-UAST tweaks; risk is limited to potential behavioral differences in constructor return emission and **kwargs argument naming.

Overview
Fixes Python UAST generation for two edge cases.

When visiting call keyword nodes where node.arg is None (i.e., **kwargs expansion), the transformer now assigns a stable identifier name ("kwargs") instead of leaving it null. For __init__ functions, it now appends an implicit return self only if the body is non-empty and does not already end with a ReturnStatement, avoiding duplicate returns.

Written by Cursor Bugbot for commit 59e7590. This will update automatically on new commits. Configure here.

@gemini-code-assist
Copy link

Summary of Changes

Hello @CyanM0un, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a specific bug in the AST visitor for Python, where the name property for **kwargs was not being properly initialized. The change ensures that when **kwargs are encountered, their corresponding AST node correctly reflects 'kwargs' as the identifier name, improving the accuracy of the UAST representation for Python code.

Highlights

  • Bug Fix: Resolved an issue where the name attribute for **kwargs was not being set during AST visitation, leading to None values for node.arg in such cases.
  • AST Representation: Ensured that **kwargs are correctly represented in the Universal Abstract Syntax Tree (UAST) by explicitly assigning the name 'kwargs' when node.arg is None.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • parser-Python/uast/visitor.py
    • Fixed a bug where the id.name for **kwargs was None in visit_keyword by explicitly setting it to 'kwargs'.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

False,
UNode.DynamicType(UNode.SourceLocation(), UNode.Meta())))
if keyword.id.name is None:
keyword.id.name = "kwargs"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keyword expansion loses argument identity

Medium Severity

When node.arg is None, visit_keyword rewrites every expanded keyword to the fixed name kwargs. This makes distinct ** expansions and real kwargs= arguments indistinguishable in CallExpression.arguments, so downstream argument binding can merge or misattribute parameters.

Fix in Cursor Fix in Web

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug where **kwargs in a function call resulted in a None name in the UAST. The proposed fix correctly identifies this case and assigns a default name, "kwargs". My review provides a suggestion to enhance this by using the actual variable name from the ** expansion when available, which will produce a more precise UAST and prevent potential name conflicts.

False,
UNode.DynamicType(UNode.SourceLocation(), UNode.Meta())))
if keyword.id.name is None:
keyword.id.name = "kwargs"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding the name to "kwargs" for ** expansions can be problematic. It loses the actual name of the dictionary being expanded and can cause name collisions if a function call uses multiple ** expansions (e.g., f(**dict1, **dict2)), which is valid in Python 3.5+. A better approach is to use the name of the variable being expanded if it's a simple name, and fall back to "kwargs" for more complex expressions.

Suggested change
keyword.id.name = "kwargs"
if isinstance(node.value, ast.Name):
keyword.id.name = node.value.id
else:
keyword.id.name = "kwargs"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant