Commit cfe611f5 authored by Moritz Huebner's avatar Moritz Huebner

Moritz Huebner: Some more simplifications for __repr__

parent bcec60d0
Pipeline #20668 passed with stages
in 12 minutes and 54 seconds
...@@ -72,21 +72,18 @@ class Prior(object): ...@@ -72,21 +72,18 @@ class Prior(object):
def __repr__(self): def __repr__(self):
return self.subclass_repr_helper() return self.subclass_repr_helper()
def subclass_repr_helper(self, subclass_args=list(), subclass_names=list()): def subclass_repr_helper(self, subclass_args=list()):
prior_name = self.__class__.__name__ prior_name = self.__class__.__name__
args = ['name', 'latex_label', 'minimum', 'maximum'] args = ['name', 'latex_label', 'minimum', 'maximum']
args.extend(subclass_args) args.extend(subclass_args)
args = self.repr_format_helper(args)
return "{}({})".format(prior_name, args)
def repr_format_helper(self, keys):
property_names = [p for p in dir(self.__class__) if isinstance(getattr(self.__class__, p), property)] property_names = [p for p in dir(self.__class__) if isinstance(getattr(self.__class__, p), property)]
dict_with_properties = self.__dict__.copy() dict_with_properties = self.__dict__.copy()
for key in property_names: for key in property_names:
dict_with_properties[key] = getattr(self, key) dict_with_properties[key] = getattr(self, key)
args = ', '.join(['{}={}'.format(key, repr(dict_with_properties[key])) for key in keys]) args = ', '.join(['{}={}'.format(key, repr(dict_with_properties[key])) for key in args])
return args return "{}({})".format(prior_name, args)
@property @property
def is_fixed(self): def is_fixed(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment