econ-ark / HARK

Heterogenous Agents Resources & toolKit
Apache License 2.0
336 stars 199 forks source link

dataclasses #605

Open sbenthall opened 4 years ago

sbenthall commented 4 years ago

Python 3.7 introduces dataclasses, which essentially are an optional way to have stricter type system within Python.

This is a way to set up abstract classes with interfaces, i.e. with canonical sets of available variables.

This may turn out to be a better abstraction for things like AgentTypes and more complex multi-agent models than the way things are currently handled with inheritance.

This linked file is an example of the kinds of things that can be done with dataclasses: https://github.com/glasgow-ipl/ietfdata/blob/master/ietfdata/datatracker.py

sbenthall commented 4 years ago

A particularly good place to start using dataclasses would be the Solution classes, which fit the dataclass use case nicely. The constructor could be replaced by a decorator, and we'd get a repr method for free.

https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsIndShockModel.py

https://docs.python.org/3/library/dataclasses.html