feat(kernel): R5 — Python and Go ports, gates passed, default-on
Python (codegraph-kernel/src/python.rs) and Go (src/go.rs) join the native kernel, mirroring the wasm extractors bug-for-bug. Python: decorated_definition docstrings/decorators (decorates refs only for bare-identifier decorators — the call-kind quirk), function-in-class → method, module-level assignments always extract as variable, from-import per-name binding refs, self.x fn-ref candidates as bare names. Go: receiver methods with Recv::name qualified names + contains edges to the first earlier struct of that name, type_spec struct/interface classification with embedding→extends and interface method nodes, composite-literal instantiates keeping the package qualifier, top-level var/const initializer walks attributed to the declared symbol (#693), 2-hop field chains (#1276), New().Method() re-encode (#645/#608), and the GO_SPEC fn-ref layers. Grammars: tree-sitter-python 0.23.6 + tree-sitter-go 0.23.4 crates, with wasm vendored from the same tags (parser.c sha-matched) — both were 2023-era in tree-sitter-wasms. Gates: extraction sweeps 100% (flask 83/83, django 3,035/3,038 +3 error-file deferrals, gin 99/99, prometheus 978/979 +1); full-init dump-diffs byte-identical on flask (10,833 rows), gin (17,540), django (360,794), and prometheus (213,758); torture fixtures enforced in npm test. DEFAULT_ROUTED now covers typescript/tsx/javascript/jsx/java/ python/go. Full suite: 2,471 tests pass. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
28068fa0f1
commit
c2503e2bee
@@ -0,0 +1,61 @@
|
||||
// Go torture fixture — receivers, embedding, interfaces, composite literals.
|
||||
package torture
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
pkga "example.com/other/pkga"
|
||||
)
|
||||
|
||||
const MAX_ITEMS = 128
|
||||
|
||||
var DefaultRegistry = NewRegistry()
|
||||
|
||||
var handlerTable = map[string]func(int){
|
||||
"recv": TargetCb,
|
||||
}
|
||||
|
||||
type Widget struct {
|
||||
*Base
|
||||
Queryable
|
||||
name string
|
||||
}
|
||||
|
||||
type Stack[T any] struct {
|
||||
items []T
|
||||
}
|
||||
|
||||
type Core interface {
|
||||
Reader
|
||||
Marshal(v any) ([]byte, error)
|
||||
Unmarshal(data []byte) error
|
||||
}
|
||||
|
||||
type Dur int
|
||||
|
||||
func NewRegistry() *Registry {
|
||||
w := Widget{name: "w"}
|
||||
q := pkga.Widget{}
|
||||
fmt.Println(w, q, MAX_ITEMS)
|
||||
cfg := loadConfig()
|
||||
cfg.conn.Exec("x")
|
||||
return New().Init()
|
||||
}
|
||||
|
||||
func (s *Stack[T]) Push(item T) {
|
||||
s.items = append(s.items, item)
|
||||
}
|
||||
|
||||
func (w Widget) Render() string {
|
||||
return w.name
|
||||
}
|
||||
|
||||
func TargetCb(n int) {}
|
||||
|
||||
func shadowed() {
|
||||
MAX_ITEMS := 5
|
||||
fmt.Println(MAX_ITEMS)
|
||||
}
|
||||
|
||||
func reads() int {
|
||||
return MAX_ITEMS
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
"""Python torture fixture — decorators, self fn-refs, imports, shadowing."""
|
||||
import os, sys
|
||||
import os.path as osp
|
||||
from collections import OrderedDict, defaultdict
|
||||
from .relative import thing
|
||||
from mypkg.handlers import target_cb
|
||||
|
||||
RETRY_LIMITS = {"a": 1}
|
||||
API_BASE = "https://example.test"
|
||||
x = compute(RETRY_LIMITS)
|
||||
|
||||
|
||||
class Service(BaseService, mixins.LoggerMixin):
|
||||
"""Class docs."""
|
||||
|
||||
def __init__(self, registry):
|
||||
self.registry = registry
|
||||
register(self.on_event)
|
||||
queue(target_cb)
|
||||
|
||||
@staticmethod
|
||||
def helper(arg):
|
||||
return transform(arg)
|
||||
|
||||
async def run(self):
|
||||
cfg = self.registry.lookup("x")
|
||||
limit = RETRY_LIMITS
|
||||
obj.method_chain().deep(cfg)
|
||||
", ".join(cfg)
|
||||
return await fetch(API_BASE)
|
||||
|
||||
def on_event(self):
|
||||
pass
|
||||
|
||||
|
||||
@app.route("/x")
|
||||
def view():
|
||||
def inner():
|
||||
return API_BASE
|
||||
return inner()
|
||||
|
||||
|
||||
def shadowed():
|
||||
API_BASE = "local"
|
||||
return API_BASE
|
||||
|
||||
|
||||
handlers = {"recv": target_cb}
|
||||
callbacks = [target_cb, view]
|
||||
@@ -36,7 +36,7 @@ const kernelBuilt = fs.existsSync(KERNEL_PATH);
|
||||
|
||||
// Every kernel-capable language. `jsx` shares the javascript grammar on BOTH
|
||||
// paths (langs.rs mirrors WASM_GRAMMAR_FILES), so the distinct grammars are:
|
||||
const GRAMMAR_LANGUAGES: Language[] = ['typescript', 'tsx', 'javascript', 'java'];
|
||||
const GRAMMAR_LANGUAGES: Language[] = ['typescript', 'tsx', 'javascript', 'java', 'python', 'go'];
|
||||
|
||||
describe.skipIf(!kernelBuilt)('kernel↔wasm grammar parity', () => {
|
||||
beforeAll(async () => {
|
||||
|
||||
@@ -72,12 +72,12 @@ describe.skipIf(!kernelBuilt)('kernel scaffold', () => {
|
||||
expect(info.languages).toContain('javascript');
|
||||
});
|
||||
|
||||
it('TS/JS family + Java route to the kernel by default; others stay wasm', () => {
|
||||
for (const lang of ['typescript', 'tsx', 'javascript', 'jsx', 'java'] as const) {
|
||||
it('TS/JS family + Java + Python + Go route to the kernel by default; others stay wasm', () => {
|
||||
for (const lang of ['typescript', 'tsx', 'javascript', 'jsx', 'java', 'python', 'go'] as const) {
|
||||
expect(kernelRoutes(lang), lang).toBe(true);
|
||||
}
|
||||
expect(kernelRoutes('python')).toBe(false);
|
||||
expect(tryKernelExtract('src/a.py', 'def f():\n pass\n', 'python')).toBeNull();
|
||||
expect(kernelRoutes('ruby')).toBe(false);
|
||||
expect(tryKernelExtract('src/a.rb', 'def f\nend\n', 'ruby')).toBeNull();
|
||||
// CODEGRAPH_KERNEL_LANGS REPLACES the default set when present.
|
||||
process.env.CODEGRAPH_KERNEL_LANGS = 'tsx';
|
||||
expect(kernelRoutes('typescript')).toBe(false);
|
||||
|
||||
@@ -60,7 +60,7 @@ let savedEnv: Record<string, string | undefined>;
|
||||
describe.skipIf(!kernelBuilt)('kernel TS/JS extraction parity', () => {
|
||||
beforeAll(async () => {
|
||||
await initGrammars();
|
||||
await loadGrammarsForLanguages(['typescript', 'tsx', 'javascript', 'jsx', 'java']);
|
||||
await loadGrammarsForLanguages(['typescript', 'tsx', 'javascript', 'jsx', 'java', 'python', 'go']);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -110,6 +110,16 @@ describe.skipIf(!kernelBuilt)('kernel TS/JS extraction parity', () => {
|
||||
assertParity('fixtures/Torture.java', fs.readFileSync(file, 'utf8'), 'java');
|
||||
});
|
||||
|
||||
it('torture fixture (python): decorators, self fn-refs, imports, shadowing', () => {
|
||||
const file = path.join(FIXTURE_DIR, 'torture.py');
|
||||
assertParity('fixtures/torture.py', fs.readFileSync(file, 'utf8'), 'python');
|
||||
});
|
||||
|
||||
it('torture fixture (go): receivers, embedding, interfaces, composite literals', () => {
|
||||
const file = path.join(FIXTURE_DIR, 'torture.go');
|
||||
assertParity('fixtures/torture.go', fs.readFileSync(file, 'utf8'), 'go');
|
||||
});
|
||||
|
||||
it.each(REAL_SOURCES)('real source parity: %s', (rel) => {
|
||||
const file = path.join(__dirname, '..', rel);
|
||||
assertParity(rel, fs.readFileSync(file, 'utf8'), 'typescript');
|
||||
|
||||
Reference in New Issue
Block a user