Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access instance attributes in config [Enhancement] #93

Open
neighthan opened this issue Nov 3, 2020 · 0 comments
Open

Access instance attributes in config [Enhancement] #93

neighthan opened this issue Nov 3, 2020 · 0 comments

Comments

@neighthan
Copy link

Say we have a setup like this

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant