Description:
Currently, accessing the parameters of an instantiated ParametricFamilyDistribution is quite verbose. Users have to explicitly route their calls through the parametrization object or dictionary:
dist = normal_family.distribution(mu=0.0, sigma=1.0)
# Current behavior
val = dist.parametrization.mu
# or
val = dist.parameters["mu"]
Because of this lack of syntactic sugar, downstream projects (such as pysatl-mpest) are forced to implement thick wrapper classes just to provide a clean, object-oriented API like dist.mu. This leads to code duplication, synchronization issues, and architectural debt.
I propose adding a magic __getattr__ method directly to the ParametricFamilyDistribution class in pysatl_core/families/distribution.py. This method would automatically delegate unresolved attribute lookups to the internal _parametrization dataclass.
Proposed implementation:
def __getattr__(self, name: str) -> Any:
"""
Delegate attribute access to the underlying parametrization.
Allows writing `dist.mu` instead of `dist.parametrization.mu`.
"""
if hasattr(self._parametrization, name):
return getattr(self._parametrization, name)
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
With this change, the API becomes much cleaner:
val = dist.mu
val = dist.sigma
Describe alternatives you've considered
Keeping the ParametricAdapter wrapper in pysatl-mpest. However, this requires manually maintaining duplicate distributions (e.g., Normal, Uniform) and hiding the pysatl-core API from the end user.
Description:
Currently, accessing the parameters of an instantiated
ParametricFamilyDistributionis quite verbose. Users have to explicitly route their calls through theparametrizationobject or dictionary:Because of this lack of syntactic sugar, downstream projects (such as
pysatl-mpest) are forced to implement thick wrapper classes just to provide a clean, object-oriented API likedist.mu. This leads to code duplication, synchronization issues, and architectural debt.I propose adding a magic
__getattr__method directly to theParametricFamilyDistributionclass inpysatl_core/families/distribution.py. This method would automatically delegate unresolved attribute lookups to the internal_parametrizationdataclass.Proposed implementation:
With this change, the API becomes much cleaner:
Describe alternatives you've considered
Keeping the
ParametricAdapterwrapper inpysatl-mpest. However, this requires manually maintaining duplicate distributions (e.g.,Normal,Uniform) and hiding thepysatl-coreAPI from the end user.