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

Parameter sharing for primitive types❓ #37

Open
maksay opened this issue May 24, 2022 · 0 comments
Open

Parameter sharing for primitive types❓ #37

maksay opened this issue May 24, 2022 · 0 comments

Comments

@maksay
Copy link

maksay commented May 24, 2022

The Fiddle tutorials describe how to use parameter sharing for any object, but what would be the right way to reuse the same value of the primitive type in multiple places (similar to ConfigDict.get_ref)?

The solution I've found so far relies on replacing the value of primitive type by an fdl.Config for a lambda, but I wonder if there is a better way?

!pip install fiddle-config

import fiddle as fdl
import dataclasses

@dataclasses.dataclass
class Obj:
  value: str

@dataclasses.dataclass
class BaseConfig:
  primitive: str 
  nested: Obj

def build_base():
  primitive = fdl.Config(lambda value: value, "NOT_SPECIFIED")
  obj = fdl.Config(Obj, value=primitive)
  return fdl.Config(BaseConfig, primitive=primitive, nested=obj)

c = build_base()
c.primitive.value = "NEW VALUE"
result = fdl.build(c)

print(result.nested.value)

(fiddle-config-0.1.0)

@maksay maksay changed the title Parameter sharing for primitive types? Parameter sharing for primitive types? ❓ May 24, 2022
@maksay maksay changed the title Parameter sharing for primitive types? ❓ Parameter sharing for primitive types❓ May 24, 2022
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