Skip to content

Parameter sharing for primitive types❓  #37

@maksay

Description

@maksay

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions