Skip to content

settings-base-class (BTCONF002)

Added in 0.10.0 · Preview · Off by default (warning)

Family: config · Standard: CES-76 · Languages: python

This rule is unstable and in preview. It runs only with preview = true, and only when it is selected.

Directive

A class whose name ends with Settings extends pydantic_settings.BaseSettings, not BaseModel. A warning by default.

Why

A BaseModel named Settings reads nothing from the environment: the values are filled in by hand, usually with the os.environ reads that the standard keeps in one place.

Do

from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    database_url: str

Don't

from pydantic import BaseModel


class Settings(BaseModel):
    database_url: str

Suppression

A comment on the class line silences the finding.

class Settings(BaseModel):  # botica: ignore[settings-base-class]
class Settings(BaseModel):  # noqa: BTCONF002 -- reason

Discussion