Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions fiddle/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,11 @@ def __init__(self, fn_or_cls: Union['Buildable', TypeOrCallableProducingT], /,
**kwargs: Any keyword arguments to configure for `fn_or_cls`.
"""
if isinstance(fn_or_cls, Buildable):
# TODO Turn this into a ValueError once code that uses this
# pattern has been updated to use fdl.cast or fdl.copy_with.
logging.warning(
raise ValueError(
'Using the Buildable constructor to convert a buildable to a new '
'type or to override arguments is deprecated; please use either '
'`fdl.cast(new_type, buildable)` (for casting) or '
'`fdl.copy_with(buildable, **kwargs)` (for overriding arguments).')
copy_constructor_arguments = fn_or_cls.__arguments__
fn_or_cls = fn_or_cls.__fn_or_cls__
else:
copy_constructor_arguments = None

# Using `super().__setattr__` here because assigning directly would trigger
# our `__setattr__` override. Using `super().__setattr__` instead of special
Expand Down Expand Up @@ -134,10 +128,6 @@ def __init__(self, fn_or_cls: Union['Buildable', TypeOrCallableProducingT], /,
elif param.kind == param.VAR_KEYWORD:
arguments.update(arguments.pop(param.name))

if copy_constructor_arguments:
for name, value in copy_constructor_arguments.items():
arguments.setdefault(name, value)

if hasattr(fn_or_cls, '__fiddle_init__'):
fn_or_cls.__fiddle_init__(self)

Expand Down Expand Up @@ -709,6 +699,7 @@ def get_tags(buildable: Buildable,


_SUPPORTED_CASTS = set()

BuildableT = TypeVar('BuildableT', bound=Buildable)


Expand Down
1 change: 1 addition & 0 deletions fiddle/experimental/autobuilders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from fiddle.experimental.autobuilders.autobuilders import auto_skeleton
from fiddle.experimental.autobuilders.autobuilders import config
from fiddle.experimental.autobuilders.autobuilders import partial
from fiddle.experimental.autobuilders.autobuilders import Registry
from fiddle.experimental.autobuilders.autobuilders import skeleton
from fiddle.experimental.autobuilders.autobuilders import validator
8 changes: 8 additions & 0 deletions fiddle/experimental/autobuilders/autobuilders.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ def config(self,
entry.skeleton_fn(base_config)
return base_config

def partial(self,
fn_or_cls: FnOrCls[T],
require_skeleton: bool = True) -> config_lib.Partial[T]:
"""Creates a fdl.Partial instance of a given function or class."""
return config_lib.cast(config_lib.Partial,
self.config(fn_or_cls, require_skeleton))

def skeleton(
self, fn_or_cls: FnOrCls[T]) -> Callable[[SkeletonFn[T]], SkeletonFn[T]]:
"""Registers a function as a skeleton for a given type.
Expand Down Expand Up @@ -318,6 +325,7 @@ def inner(validator_fn: ValidatorFn[T]) -> ValidatorFn[T]:
# module level.
_default_registry = Registry()
config = _default_registry.config
partial = _default_registry.partial
skeleton = _default_registry.skeleton
auto_skeleton = _default_registry.auto_skeleton
validator = _default_registry.validator
4 changes: 2 additions & 2 deletions fiddle/experimental/yaml_serialization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def _config_constructor(loader, node):


def _partial_constructor(loader, node):
return fdl.Partial(_config_constructor(loader, node))
return fdl.cast(fdl.Partial, _config_constructor(loader, node))


def _fixture_constructor(loader, node):
return fixture_node.FixtureNode(_config_constructor(loader, node))
return fdl.cast(fixture_node.FixtureNode, _config_constructor(loader, node))


class SemiSafeLoader(yaml.SafeLoader):
Expand Down