Dictionary vs Dataclass: When do you discover the bug?
Dictionary
row
= {
"price"
: 19.99}
# Typo: "prize" instead of "price"
row[
"prize"
]
Code runs...
CRASH!
KeyError
"prize" not found
Runtime error!
Bug found in production
Too late!
Dataclass
@dataclass
class
Product
:
price
:
float
product.
prize
Attribute "prize" not found
Editor warns...
SAFE
Caught before running!
Bug found in editor
Before any code runs!