Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/engine/analyzer/python/common/python-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ class PythonAnalyzer extends (Analyzer as any) {
return SymbolValue(new_node)
}

/**
*
* @param fclos
* @param argvalues
* @param state
* @param node
* @param scope
*/
Comment on lines +249 to +256
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.
   */

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.

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

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

argvalues[0] = fclos._this
}
return super.executeSingleCall(fclos, argvalues, state, node, scope)
}

/**
*
* @param scope
Expand Down