Is your feature request related to a problem?
This is a gentle suggestion.
Currently we experience a lot of this:
There are several ways to alleviate this issue.
I have used a requires_<attribute>() method pattern in the past:
def require_grain_crops(self) -> dict[int, GrainCrop]:
"""
Return a non-None grain_crops mapping or raise and exception.
Returns
-------
dict[int, GrainCrop]
The grain crops for the molecule.
Raises
------
RuntimeError
If grain_crops is None.
"""
if self.grain_crops is None:
raise RuntimeError("grain_crops is None")
return self.grain_crops
But since we are using pydantic, we could use @property instead:
@property
def property_grain_crops(self) -> dict[int, GrainCrop]:
if self.grain_crops is None:
raise RuntimeError("grain_crops is None")
return self.grain_crops
Which would also solve the issue.
But of course this would require a nomenclature change in all classes, to use _grain_crops for the internal attribute name, and then grain_crops for the property` and that would be a bit of a hassle.
Describe the solution you would like.
Implement one of the above to get rid of the numerous type issues in the codebase?
Describe the alternatives you have considered.
Not essential but would be nice.
Additional context
No response
Is your feature request related to a problem?
This is a gentle suggestion.
Currently we experience a lot of this:
There are several ways to alleviate this issue.
I have used a
requires_<attribute>()method pattern in the past:But since we are using pydantic, we could use
@propertyinstead:Which would also solve the issue.
But of course this would require a nomenclature change in all classes, to use
_grain_cropsfor the internal attribute name, and thengrain_cropsfor the property` and that would be a bit of a hassle.Describe the solution you would like.
Implement one of the above to get rid of the numerous type issues in the codebase?
Describe the alternatives you have considered.
Not essential but would be nice.
Additional context
No response