Skip to content

Conversation

@vladoovtcharov
Copy link

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants