Skip to content

PyAnalyzer should ignore nested functions/assignments when extracting module/class members #71

@bbopen

Description

@bbopen

Summary

PyAnalyzer uses a recursive findNodesByType traversal for functions, methods, and assignments. This pulls in nested functions (inside methods) and local assignments, causing duplicate module functions and spurious class properties.

Failure mode

  • Methods are also emitted as module-level functions.
  • Nested inner functions inside methods are emitted as class methods.
  • Local assignments inside methods are recorded as class properties.

Evidence

  • src/core/analyzer.ts:
    • extractFunctions calls findNodesByType(root, 'function_definition').
    • extractClass uses findNodesByType(bodyNode, 'function_definition') and findNodesByType(bodyNode, 'assignment').
    • findNodesByType traverses the full subtree, including nested scopes.

Proposed fix

  • Only consider direct children of the module/class body for functions and assignments.
  • When extracting class members, avoid descending into function bodies.
  • Add tests with nested functions and method-local assignments to ensure they’re ignored.

Acceptance criteria

  • Module-level functions exclude class methods and nested functions.
  • Class methods exclude nested inner functions.
  • Class properties exclude assignments inside methods.
  • Tests cover nested scopes and confirm correct extraction.

Metadata

Metadata

Assignees

Labels

area:toolingArea: tooling and CLIbugSomething isn't workingpriority:p2Priority P2 (medium)

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions