Part of the organization development baseline.
Organization baseline for enumerations whose members are strings (API keys, error codes, filter field names, etc.).
Target Python 3.11+. For those enumerations, subclass enum.StrEnum from the standard library. Do not use the older class Foo(str, Enum) mixin pattern.
StrEnumis the documented stdlib base for string enums: members behave asstrin most contexts, with__str__/__format__aligned tostr(see the enum module).(str, Enum)is discouraged for new code in org repositories.
Good:
from enum import StrEnum
class FieldKey(StrEnum):
NAME = "name"Bad:
from enum import Enum
class FieldKey(str, Enum):
NAME = "name"Rare code uses type(x) is str instead of isinstance(x, str). Enum members are instances of the enum class; if a true built-in str is required, pass str(member).
Prefer lint (Ruff). Ruff UP042 (replace-str-enum, pyupgrade) reports class Foo(str, Enum) (and the enum.Enum + str ordering) and can suggest migrating to StrEnum. It is active whenever UP appears in [lint] select (in the org template/baselines/ruff.toml, consumed via [tool.ruff] extend = "baselines/ruff.toml") and your target-version is 3.11+. The org baseline already includes UP in select, so pre-commit / CI running ruff check is the normal enforcement path.
Optional extras:
- A duplicate pre-commit hook or small AST script (fail on
(str, Enum)bases) if you want belt-and-suspenders or stricter failure modes than Ruff alone — keep it aligned with this doc if you keep it. - Agent rules (
.agents/rules/*.md) that point here for editor and agent behavior.
If you disable UP042 explicitly or drop UP from select in baselines/ruff.toml, you are opting out of lint enforcement; document that choice in the consumer repo.