baybe icon indicating copy to clipboard operation
baybe copied to clipboard

Construction metadata

Open AdrianSosic opened this issue 5 months ago • 2 comments

Implements #648 by introducing an access mechanism for optional attributes using a dedicated optional namespace.

Usage Summary

from baybe.targets.numerical import NumericalTarget

t = NumericalTarget.match_absolute("t", match_value=0)

# Optional attributes can be accessed via the `optional` namespace
assert t.optional.match_value == 0

# Works even for constructor arguments that were not explicitly provided but use defaults
assert t.optional.mismatch_instead is False

# When an optional attribute is not available, an access attempt raises an error
NumericalTarget("t").optional.match_value  #  <-- raises `OptionalAttributeError`

AdrianSosic avatar Oct 27 '25 12:10 AdrianSosic

From the user perspective, this looks pretty nice. Is it also possible to just access all kwargs directly as a dict instead of the individual arguments as members (just curiosity, no specific use case in mind)?

dasmy avatar Oct 27 '25 18:10 dasmy

From the user perspective, this looks pretty nice. Is it also possible to just access all kwargs directly as a dict instead of the individual arguments as members (just curiosity, no specific use case in mind)?

Sure, we can easily add a public interface for that. Right now, the dict is already available via a private attribute, but we can add a user-facing getter mechanism like an as_dict method or something. Depends a bit on what we expect it to contain / what should be configurable (i.e. should it contain all attributes, only the passes ones excluding defaults, etc). So I'd perhaps wait until we've an actual use case for it, because the implementation is not really difficult and can be quickly added once needed 👍🏼

AdrianSosic avatar Oct 27 '25 20:10 AdrianSosic