Add reference tag to allow getting a varaible by reference #3025
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Adds the ability to reference a variable without making a copy, similar to that proposed in #1393
Instead of singleton: true being added to the object, instead anywhere that wants to be instantiated as a reference to that variable can use the syntax:
foo: bar: _target_: "myclass" x: 4.0 reference_variable: _reference_: "foo.bar"
Then reference variable and foo.bar will refer to the same object after instantiate.
By registering a custom resolver the syntax ends up looking even nicer:
foo: bar: _target_: "myclass" x: 4.0 reference_variable: ${ref:foo.bar}
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Add test cases, especially for almost circular cases, e.g.
`
foo:
a: ${ref:bar.y}
b:
target: "ClassA"
bar:
x: ${ref:foo.b}
y:
target: "ClassB"
`
Also a bit worried about performance/memory usage with the proposed implementation but not sure about the best way to test that.
Related Issues and PRs
A different approach to PR#3103 but solves similar problem