8000 FR: Use StringDict-like return value for Thread.Load · Issue #463 · google/starlark-go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
FR: Use StringDict-like return value for Thread.Load #463
Open
@ashi009

Description

@ashi009

I'm implementing a stardoc-like program (extracting docs from bzl files). In such a program, we don't really need to know the concrete types of foreign symbols. For now, the Thread.Load returns a StringDict, which means I need to resolve the loading bzl path, and exec that file just to make the Exec work.

I'm proposing that let Thread.Load returns a StringDict-like interface with Get and Keys methods instead. Which will allow users to mock a load.

The Thread.Load is used as follow:

dict, err2 := thread.Load(thread, module)
thread.beginProfSpan()
if err2 != nil {
err = wrappedError{
msg: fmt.Sprintf("cannot load %s: %v", module, err2),
cause: err2,
}
break loop
}
for i := 0; i < n; i++ {
from := string(stack[sp-1-i].(String))
v, ok := dict[from]
if !ok {
err = fmt.Errorf("load: name %s not found in module %s", from, module)
if n := spell.Nearest(from, dict.Keys()); n != "" {
err = fmt.Errorf("%s (did you mean %s?)", err, n)
}
break loop
}
stack[sp-1-i] = v
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0