Skip to content

feat(core): Python language support#23

Merged
prosdev merged 8 commits into
mainfrom
feat/core-phase4-python-support
Apr 1, 2026
Merged

feat(core): Python language support#23
prosdev merged 8 commits into
mainfrom
feat/core-phase4-python-support

Conversation

@prosdev

@prosdev prosdev commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

dev-agent now indexes Python codebases. All MCP tools work with Python automatically.

What it does

PythonScanner extracts from .py files:

  • Functions (sync + async), classes, methods
  • Decorators (@app.route, @pytest.fixture, @property)
  • Type hints in signatures (def foo(x: int) -> str)
  • Docstrings (triple-quote, first expression in body)
  • __all__ for export control, _ prefix convention as fallback
  • Callees from function bodies (recursive descent)
  • Code snippets for search result previews
  • Imports (import, from...import, relative imports)

Pattern rules for dev_patterns on Python files:

  • Error handling: try/except, raise, except clauses
  • Import style: import, from-import, relative imports
  • Type coverage: typed parameters, return types, function count

Infrastructure improvements:

  • isTestFile() refactored to language-aware pattern map
  • QUERIES_BY_LANGUAGE map replaces if/else chain
  • Skip generated files (_pb2.py, migrations, # Generated by)

Changes

File What
packages/core/src/scanner/python.ts PythonScanner (~520 lines)
packages/core/src/scanner/python-queries.ts 8 S-expression extraction queries
packages/core/src/scanner/index.ts Register PythonScanner
packages/core/src/utils/test-utils.ts Refactored to language-aware patterns
packages/core/src/pattern-matcher/rules.ts 9 Python pattern rules
packages/core/src/pattern-matcher/wasm-matcher.ts Add Python to language map + supported set
packages/core/src/services/pattern-analysis-service.ts QUERIES_BY_LANGUAGE map
packages/core/src/scanner/tree-sitter.ts Add 'python' to TreeSitterLanguage
packages/dev-agent/scripts/copy-wasm.js Bundle tree-sitter-python.wasm (476KB)

Test plan

  • 22 Python scanner tests (functions, classes, methods, imports, async, docstrings, all, callees, snippets, exports, parity)
  • 5 isTestFile Python tests (test_*.py, *_test.py, conftest.py, JS/TS compat)
  • 1673 total tests pass (up from 1651)
  • Build + typecheck pass

Supported languages

Language Scanner Features
TypeScript/JavaScript ts-morph Functions, classes, interfaces, types, arrow functions, hooks
Python tree-sitter Functions, classes, methods, decorators, type hints, docstrings
Go tree-sitter Functions, methods, structs, interfaces, generics
Markdown remark Documentation sections

Generated with Claude Code

prosdev and others added 8 commits March 31, 2026 19:20
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add 'python' to TreeSitterLanguage and SUPPORTED_LANGUAGES. Define
PYTHON_QUERIES with 8 S-expression patterns for functions, classes,
methods, decorators, imports, and module variables.

All queries validated against tree-sitter-python grammar.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
PythonScanner extracts functions, classes, methods, imports, decorators,
type hints, docstrings, __all__ exports, callees, snippets, and async.

- Refactor isTestFile() to language-aware pattern map
- Refactor findTestFile() for Python test path conventions
- Skip generated files (_pb2.py, migrations/, # Generated by)
- Register in scanner registry alongside TypeScript, Go, Markdown

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9 Python-specific S-expression queries for error handling (try/except,
raise, except), imports (import, from-import, relative), and type
coverage (typed params, return types, function count).

- Add 'python' to WasmPatternMatcher supported languages + extension map
- Refactor runAllAstQueries to QUERIES_BY_LANGUAGE map (no if/else chain)
- Update tests: .py is now supported, use .rs for unsupported language

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
22 tests covering FastAPI fixture (async, decorators, type hints,
docstrings, imports, callees, exports), utils fixture (__all__,
private/public, module constants), document parity with Go/TS,
and isTestFile Python patterns.

Fixtures: fastapi-app.py, python-utils.py
Changeset: v0.11.0 (minor — new language support)
Docs: README, website release notes, latest-version

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add test verifying decorated functions not extracted twice
- Clean up dead ternary in callee extraction
- Remove unused _allExports param from extractMethods
- Add comment explaining basename usage in Python isTestFile
- Add generated file skip test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…edge cases

New python-service.py fixture tests:
- __init__, @Property, @classmethod, @staticmethod extraction
- Multi-line Google-style docstrings (Args, Returns, Raises preserved)
- Async methods inside classes
- Private method export detection

33 Python scanner tests total (was 24).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@prosdev prosdev merged commit b26a876 into main Apr 1, 2026
1 check passed
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