Python
The Python extractor covers.py files. Python has a single grammar construct for functions. Async functions parse as the same function_definition node, with the async keyword folded into it. Both sync and async def become Function.
What it detects
- Functions:
def(sync and async) becomesFunction - Classes:
class_definitionbecomesClass; methods areFunctionnodes nested inside - Decorators:
decoratorbecomesDecorator; a decorated definition becomes aDecoratedDefwrapper around the underlying function or class - Imports:
import_statement,import_from_statement, andfuture_import_statementall becomeImport - Assignments:
assignmentandaugmented_assignmentbecomeAssignment/AugmentedAssignment. Python has no separateVariableconcept. A variable’s name lives in the declarator of the assignment that binds it, not in a canonical label - Control flow: if / elif / else, for / while, try / except / finally, with, match / case
- Comprehensions and lambdas: list / dict / set comprehensions, generator expressions,
lambda - Type annotations:
type,generic_type, andunion_typebecomeTypeAnnotation/GenericType/UnionType
Node type mapping
Node types without a mapping keep their raw tree-sitter type name.
Labels. Labels come from the
name field on the definition node.
Example: refactoring a Python module
Extractapply_discount out of pricing.py into a new discounts.py, rename it to apply_promo, and add a max_discount parameter:
pricing.py losing two functions and discounts.py gaining one. The semantic diff shows one function moved across files, renamed, and given a defaulted parameter. checkout barely changed.
Known limitations
- Methods are not distinct: there is no
Methodconcept; a method is aFunctionnested in aClass. - No
Variableconcept: plain assignments becomeAssignment, so a renamed variable shows up as a change in its declarator children, not on a canonical label. - Decorated definitions wrap the definition:
DecoratedDefis a wrapper node, so a decorator change and a body change are separate edits. - Lambdas have no label:
lambdabecomesLambdawith no name. - Unmapped node types pass through: anything outside the map keeps its raw tree-sitter type name.