python

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package python is the v0.5 tspipeline LanguageProvider for Python. FQN form: dotted module path with "." separator. Mirrors the v0.4 Python extractor's logic so existing v3 Python indexes do not need re-extraction (Symbol.IDs match).

src/click/core.py        →  module path "click.core"
def parse(): ...         →  FQN "click.core.parse"
class Command:
    def invoke(...):     →  FQN "click.core.Command.invoke"

The package walk: starting at the file's directory, walk upward as long as each ancestor contains __init__.py. The collected segments (outer-to-inner) become the dotted package path.

If no __init__.py is found at the file's parent (script-style layouts), the FQN falls back to the file-path form ("scripts/standalone.py:parse"). Same rule as v0.4.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFQNDeriver

func NewFQNDeriver() *fqnDeriver

NewFQNDeriver returns a Python FQN deriver. Callers should reuse one instance per repo walk to share the package-probe cache.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements tspipeline.LanguageProvider for Python. M1 surface: SymbolQueries + FQNDeriver only. Calls/heritage/imports arrive in M2–M4.

func New

func New() *Provider

New constructs a Python provider.

func (*Provider) EnclosingName

func (p *Provider) EnclosingName(node *sitter.Node, src []byte) (string, bool)

EnclosingName reports whether node creates a named scope. In Python the only nestable named scope we care about for FQN composition is `class_definition` — function definitions don't add to FQN scope of nested symbols (Python lookup is dynamic), and modules are represented at the module-path layer.

func (*Provider) Extensions

func (p *Provider) Extensions() []string

func (*Provider) ExtractCalls

func (p *Provider) ExtractCalls(tree *sitter.Tree, fctx *tspipeline.FileContext, env *tspipeline.TypeEnvironment) []tspipeline.CallSite

ExtractCalls walks every function/method body in the file for call sites. Each call expression yields one CallSite (the engine resolves the textual target in pass 2).

Tree-sitter-python shapes covered:

call
  ├── function: identifier        → CallDirect (or CallConstructor
  │                                  via PEP 8 uppercase heuristic)
  └── function: attribute         → CallMethod (receiver = object)

The PEP 8 heuristic (uppercase first letter) is the same one typebindings.go's tier 2 uses to distinguish constructors. We surface them as CallConstructor so downstream queries can treat `User()` as constructing a User even without `new`.

func (*Provider) ExtractFields added in v0.5.1

func (p *Provider) ExtractFields(tree *sitter.Tree, fctx *tspipeline.FileContext) []tspipeline.FieldRel

ExtractFields walks every class definition and emits FieldRels for typed class-body assignments and `self.x: T = ...` patterns inside __init__ / methods.

Patterns covered:

class C:
    x: T = default      ← class-body annotated assignment
    def __init__(self):
        self.y: U = ...  ← self-attribute annotated assignment

Untyped assignments (`self.z = ...`) produce no FieldRel — inferring the type would require receiver-flow analysis we don't do in v0.5.1.

func (*Provider) ExtractHeritage

func (p *Provider) ExtractHeritage(tree *sitter.Tree, fctx *tspipeline.FileContext) []tspipeline.HeritageRel

ExtractHeritage walks the file's AST for class definitions and surfaces their base classes.

Tree-sitter-python class shape:

class_definition
  ├── name: identifier
  └── superclasses: argument_list
        └── identifier / attribute / call ...

Each entry in the argument_list is a base class. Python doesn't distinguish syntactic implements from extends; M2 emits all bases as EdgeExtends. (Future work: detect typing.Protocol → emit Implements instead.)

func (*Provider) ExtractImports

func (p *Provider) ExtractImports(tree *sitter.Tree, fctx *tspipeline.FileContext) []tspipeline.Binding

ExtractImports walks the file's import statements.

Tree-sitter-python shapes covered:

import foo                          → Binding{Name:"foo", Target:"foo", Wildcard:true (BindingNamespaceImport)}
import foo.bar                      → Binding{Name:"foo", Target:"foo.bar", Wildcard:true}
import foo as f                     → Binding{Name:"f",   Target:"foo", Wildcard:true (BindingAliasedImport)}

from foo import bar                 → Binding{Name:"bar", Target:"foo.bar", Kind:Named}
from foo import bar as b            → Binding{Name:"b",   Target:"foo.bar", Kind:Aliased}
from foo import *                   → Binding{Name:"",    Target:"foo", Wildcard:true (BindingWildcardImport)}
from . import x                     → relative import → resolved against fctx.ModulePath
from .sub import y                  → relative + sub-package

We do NOT chase __init__.py re-exports in M2; if `from foo import bar` only resolves through foo/__init__.py's `from .bar_impl import bar`, the M2 resolver may miss it. Document; revisit if real-world testing surfaces it.

func (*Provider) ExtractSignatures

func (p *Provider) ExtractSignatures(tree *sitter.Tree, fctx *tspipeline.FileContext) []tspipeline.SignatureRel

ExtractSignatures walks every function/method definition in the file, pulling Accepts (typed parameters) and Returns (return-type annotation, "-> T" form).

Tree-sitter-python shapes:

function_definition
  ├── name: identifier
  ├── parameters: parameters
  │     ├── identifier            (untyped)
  │     ├── typed_parameter       (with `type`)
  │     ├── typed_default_parameter
  │     └── default_parameter     (untyped with default)
  ├── return_type: type           (optional, after "->")
  └── body: ...

Untyped parameters yield no NameRef. `self`/`cls` are untyped receivers and contribute no Accepts entry — they're implicit and downstream queries treat methods specially via Calls(this.x).

func (*Provider) FQNDeriver

func (p *Provider) FQNDeriver() tspipeline.FQNDeriver

func (*Provider) Grammar

func (p *Provider) Grammar() *sitter.Language

func (*Provider) Language

func (p *Provider) Language() string

func (*Provider) SymbolQueries

func (p *Provider) SymbolQueries() []tspipeline.SymbolQuery

SymbolQueries returns the M1 query set for Python.

Top-level functions, classes, and dotted-name assignments at module scope. Methods + class fields are emitted by the class mapper that walks the class body procedurally — same shape as the TS provider.

func (*Provider) TypeBindings

func (p *Provider) TypeBindings() tspipeline.TypeBindingExtractor

TypeBindings returns the per-language extractor that the pipeline dispatches to during the type-environment walk. M3 Phase A: PEP 484 annotations and typed parameters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL