peng-lab/BaSiCPy

Create a pydantic settings class

Closed this issue · 4 comments

The current development branch implements a Settings class that holds settings for the BaSiC model class. This task should do one of two things:

  1. Turn BaSiC class in a pydantic.BaseModel subclass that implements everything in Settings, then remove the Settings class.
  2. Turn Settings into a pydantic.BaseModel subclass

I vote for option 1, since the utility functions of pydantic.BaseModel make housing the settings for BaSiC in a separate class arbitrary. This will help reduce the complexity of the code since we expect the inputs to BaSiC to contain all parameters for Settings.

In addition, ensure pydantic is added to setup.cfg.

I'd also note that option 1 addresses the problem with duplicated docstrings and function signatures between the Settings dataclass and BaSiC.__init__

Another option is to make Settings an inner class of BaSiC of type pydantic.BaseModel, dataclass, or pydantic.dataclass. The advantage is a namespace and easy settings dump. The disadvantage is not necessarily reducing complexity.

The main point of preferring pydantic is for serializing, right? Otherwise python's standard dataclass would be sufficient for enforcing types and defaults? Are you thinking about emitting settings for something?

Regarding the requirements.txt, if we maintain the dependencies section of setup.cfg, we shouldn't need to keep an extra requirements file, right?

There are multiple reasons for using pydantic, including serialization (and customization), type checking, and use of private fields.

I usually use requirements.txt so I instinctively said that. The way this repo is set up we should do setup.cfg. I'll change it.