CCL
CCL copied to clipboard
`CCLNamedClass` does not play nice with `dataclass`
I tried making a dataclass
that derived from CCLNamedClass
(analogously to the Baryons
base class) but this causes an obscure error:
from dataclasses import dataclass
from pyccl import CCLNamedClass
class A(CCLNamedClass):
pass
@dataclass
class B(A):
a = 0
B()
Traceback (most recent call last):
File "pyccl/_core/schema.py", line 262, in __new__
instance = super().__new__(cls)
TypeError: Can't instantiate abstract class B with abstract method name
I think that's because any subclass of CCLNamedClass
needs to implement the name
method (see here)
We should probably add some documentation on when and how to use these classes. Is there a reason for name
not defaulting to something like __class__.__name__
?
It was so you can have a from_name
method that you can use with more memorable/meaningful names (e.g. ccl.MassFunction.from_name("Tinker08")
). I agree it may be a bit superfluous, since modern IDEs make finding these things quite easy.