Skip to content

Detect local arguments and functions used in a function#190

Merged
samwaseda merged 2 commits intoargsfrom
copilot/sub-pr-164
Mar 19, 2026
Merged

Detect local arguments and functions used in a function#190
samwaseda merged 2 commits intoargsfrom
copilot/sub-pr-164

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

Summary

Adds AST-based undefined-variable detection to dependency_parser so that external symbols used by a function can be identified and resolved for dependency tracking. Local (nested) function definitions are explicitly forbidden—raising NotImplementedError early—to avoid silent mis-resolution rather than producing incorrect dependency graphs.

Related Issue(s)

Follow-up to #155.

Backward Compatibility

Functions containing nested def or async def blocks will now raise NotImplementedError when passed to find_undefined_variables or get_call_dependencies. Previously these were silently (and incorrectly) processed.

Implementation Notes

  • UndefinedVariableVisitor — rewrites the AST visitor with a _nesting_depth counter. Any FunctionDef/AsyncFunctionDef encountered at depth > 0 raises NotImplementedError with a message that distinguishes def from ``async def`:
    NotImplementedError: Local function definitions are not supported:
    'def helper' inside a function body cannot be analysed for dependencies.
    
  • Argument coverage — registers all argument kinds (posonlyargs, args, kwonlyargs, *args, **kwargs) in defined_vars, eliminating false positives from these names.
  • get_call_dependencies — resolves each undefined symbol via object_scope and recursively collects unversioned objects.
  • Tests added:
    • test_local_function_definition_raises / test_local_async_function_definition_raises — verify the new early-failure behavior.
    • test_all_argument_kinds_are_defined — guards against regression on argument-kind coverage.

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: samwaseda <37879103+samwaseda@users.noreply.github.com>
Copilot AI changed the title [WIP] Detect local arguments and functions used in a function Detect local arguments and functions used in a function Mar 19, 2026
Copilot AI requested a review from samwaseda March 19, 2026 18:11
@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.65%. Comparing base (2d48634) to head (dbb1188).
⚠️ Report is 3 commits behind head on args.

Additional details and impacted files
@@            Coverage Diff             @@
##             args     #190      +/-   ##
==========================================
+ Coverage   97.47%   97.65%   +0.18%     
==========================================
  Files          34       34              
  Lines        2295     2305      +10     
==========================================
+ Hits         2237     2251      +14     
+ Misses         58       54       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samwaseda samwaseda marked this pull request as ready for review March 19, 2026 18:29
@samwaseda samwaseda merged commit 1e893de into args Mar 19, 2026
15 of 19 checks passed
@samwaseda samwaseda deleted the copilot/sub-pr-164 branch March 19, 2026 18:29
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.

2 participants