Skip to content
Merged
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
19 changes: 19 additions & 0 deletions fiddle/_src/experimental/auto_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@
_GenericCallable = TypeVar('_GenericCallable', bound=Callable[..., Any])


@dataclasses.dataclass(frozen=True)
class AutoConfigClassMethod:
"""A wrapper for auto_config'd class methods."""

func: Callable[..., Any]
always_inline: bool

def __get__(self, obj, objtype=None):
return AutoConfig(
func=types.MethodType(self.func, objtype),
buildable_func=types.MethodType(self.func, objtype),
always_inline=self.always_inline,
)

@property
def __wrapped__(self):
return self.func


@dataclasses.dataclass(frozen=True)
class AutoConfig:
"""A function wrapper for auto_config'd functions.
Expand Down
6 changes: 3 additions & 3 deletions fiddle/_src/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def new(cls, default: Any = NO_VALUE) -> Any:
return TaggedValue(tags=(cls,), default=default)

if not typing.TYPE_CHECKING:
new = classmethod(
auto_config.AutoConfig(
func=new.__func__, buildable_func=new.__func__, always_inline=True))
new = auto_config.AutoConfigClassMethod(
func=new.__func__, always_inline=True
)


T = TypeVar('T')
Expand Down
Loading