explosion / explosion/thinc

Passing config object itself to registered functions

Open
#380 0 comments 0 reactions 0 assignees View on GitHub
feat / config
Dominant language
Python
Stars
2.9k
Forks
295
PR merge metrics
No merged PRs in 30d

Description

Configuration entries marked with a `@` are treated as calls to function registries and the other entries within that dictionary are treated as function arguments. Is there a way to pass the configuration file itself as a function parameter? For example, let's say I have a registered function defined as:

```
@registry.visualizer("v1")
def my_visualizer_v1(a, b):
# do stuff
```

And a configuration file:

```
[Global]
var1 = 123
var2 = "foo"
[Visualizer]
@visualizer = "v1"
a = ${Global:var1}
b = ${Global:var2}
```

Is there a way to pass the configuration object itself to `my_visualizer_v1` and let it retrieve the values it needs, e.g.

```
@registry.visualizer("v1")
def my_visualizer_v1(cfg):
a = cfg.Global.var1
b = cfg.Global.var2
# do stuff
```

My use case is that the parameters defined in the config file are used throughout the library; only a few of them are actually unique to the visualizer function(s). I don't want users to have to remember which of the parameters a certain version of a function needs (for example, another version of the function may require additional or fewer parameters than `v1` does) and would rather have the functions themselves extract what they need from the config file.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.