google / google/fiddle

Parameter sharing for primitive types❓

Open
#37 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
386
Forks
21
Avg merge
15h 18m
Merged PRs (30d)
1

Description

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)

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.