Skip to content

fix: support python @classmethod decorator#106

Open
CrackTC wants to merge 1 commit intoantgroup:mainfrom
CrackTC:fix/python-classmethod
Open

fix: support python @classmethod decorator#106
CrackTC wants to merge 1 commit intoantgroup:mainfrom
CrackTC:fix/python-classmethod

Conversation

@CrackTC
Copy link
Collaborator

@CrackTC CrackTC commented Feb 4, 2026

Note

Medium Risk
Touches Python call execution semantics by mutating call arguments for decorated functions; could affect how method calls are modeled across analyses if decorator detection or undefine handling is wrong.

Overview
Adds a PythonAnalyzer.executeSingleCall override to special-case functions decorated with @classmethod.

When the first argument is missing/undefine, it now injects the captured class context (fclos._this) as the implicit cls argument before delegating to the base Analyzer call execution.

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @CrackTC, 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 bug where Python's @classmethod decorator was not being correctly processed by the analyzer. The changes introduce logic to ensure that the implicit cls argument, passed to class methods, is properly resolved during analysis, thereby improving the accuracy of Python code analysis.

Highlights

  • Python Classmethod Support: Implemented the executeSingleCall method in PythonAnalyzer to correctly handle Python's @classmethod decorator. This ensures that when a class method is called, the first argument (typically cls) is properly set to the class instance (fclos._this) if it's initially undefined.

🧠 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
  • src/engine/analyzer/python/common/python-analyzer.ts
    • Added a new method executeSingleCall to override the superclass's method.
    • Introduced logic within executeSingleCall to detect @classmethod decorators and assign fclos._this to the first argument (argvalues[0]) if it's undefined.
Activity
  • The pull request was opened by CrackTC.
  • No human activity (comments, reviews, or progress updates) has been recorded yet.
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
Contributor

@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 adds support for Python's @classmethod decorator by overriding the executeSingleCall method. The implementation correctly identifies classmethod calls and injects the class object as the first argument if it's missing. The logic is sound. My feedback includes suggestions to improve the documentation and type safety of the new code for better maintainability.

Comment on lines +249 to +256
/**
*
* @param fclos
* @param argvalues
* @param state
* @param node
* @param scope
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The JSDoc for this method is incomplete. It should explain that this method is overridden to handle Python's @classmethod decorator, where the first argument (cls) is implicitly passed.

  /**
   * Overrides the parent `executeSingleCall` to provide special handling for Python's `@classmethod`.
   * For a classmethod, the first argument is the class itself. This method ensures that if the
   * first argument is not defined, it is correctly set to the class object (`fclos._this`).
   *
   * @param fclos The function closure being called.
   * @param argvalues The arguments for the function call.
   * @param state The current analysis state.
   * @param node The AST node for the call expression.
   * @param scope The current scope.
   */

* @param node
* @param scope
*/
executeSingleCall(fclos: any, argvalues: any, state: any, node: any, scope: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The method signature uses any for all its parameters. This reduces type safety and makes the code harder to understand and maintain. While this matches the parent class, consider using more specific types. For example, fclos could be FunctionValue, argvalues an array of SymbolValue, and scope a Scope.

* @param scope
*/
executeSingleCall(fclos: any, argvalues: any, state: any, node: any, scope: any) {
if (fclos.decorators?.some((d: any) => d.name === 'classmethod') && argvalues[0]?.vtype === 'undefine') {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The decorator object d is typed as any. To improve type safety, you could use a more specific inline type like { name: string } or define a Decorator interface.

    if (fclos.decorators?.some((d: { name: string }) => d.name === 'classmethod') && argvalues[0]?.vtype === 'undefine') {

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.

* @param scope
*/
executeSingleCall(fclos: any, argvalues: any, state: any, node: any, scope: any) {
if (fclos.decorators?.some((d: any) => d.name === 'classmethod') && argvalues[0]?.vtype === 'undefine') {
Copy link

Choose a reason for hiding this comment

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

Decorator check uses wrong property name

High Severity

The decorator check d.name === 'classmethod' will always fail because the processed decorator object doesn't have a name property. When an unresolved identifier like classmethod is processed, processIdentifier sets _id and _sid to the identifier name, but not name. The condition should check d._id === 'classmethod' or d._sid === 'classmethod' instead.

Fix in Cursor Fix in Web

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