Why Your Python Enum Fails in JSON and How to Fix It Fast!

preview_player
Показать описание
Tired of sprinkling .value everywhere just to dump an enum to JSON? In this 60-second demo we:
1️⃣ Show a regular Enum failing with a TypeError.
2️⃣ Patch it the old-school way with .value (works, but feels clunky).
3️⃣ Swap the base class to StrEnum—and it just works in logs, f-strings, and JSON, while keeping full type safety for your IDE and linters. Requires Python 3.11 or newer; no other changes needed. Copy the snippet, run it, and tell us which enum you’ll refactor first!

#Python #StrEnum #CleanCode #DeveloperTips
Рекомендации по теме
Комментарии
Автор

Why not just add that behavior to the normal Enum then??

Everything in Python is 10x more complicated than it needs to be with none of the flexibility that more “complicated” languages offer

underlyingglitch
Автор

At this point just use static properties

danilosindric
visit shbcf.ru