Construction metadata
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`
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)?
From the user perspective, this looks pretty nice. Is it also possible to just access all
kwargsdirectly 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 👍🏼