google / google/gin-config

Access instance attributes in config [Enhancement]

Open
#93 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.2k
Forks
122
Avg merge
5d 10h
Merged PRs (30d)
2

Description

Say we have a setup like this

```python
class A:
def __init___(self, x, y):
# some value computed from the parameters
self.n = x ** 2 + y

class B:
def __init___(self, n):
self.n = n
```

I would like to be able to do this in my config:

```python
A.x = 3
A.y = 2
B.n = @A().n
```

Hard-coding `B.n = 11` would be bad because we might forget to change it when we update `A.x`. Obviously one can just not use the config for this and create `a = A()` first in Python then `b = B(a.n)`. If the instances of `A` and `B` wouldn't naturally be created in the same place, though, then this makes the code worse since we have to pass `a` (or at least `a.n`) around.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.