Skip to content

Instantly share code, notes, and snippets.

@timurbakibayev
Created February 20, 2022 20:26
Show Gist options
  • Save timurbakibayev/c4df970caecf502ad678f78d5211b79a to your computer and use it in GitHub Desktop.
Save timurbakibayev/c4df970caecf502ad678f78d5211b79a to your computer and use it in GitHub Desktop.
A mutable dataclass
from dataclasses import dataclass
from decimal import Decimal
@dataclass
class Account:
amount: Decimal
blocked: Decimal
def add_amount(self, amount: Decimal) -> None:
self.amount += amount
def block_amount(self, amount: Decimal) -> None:
if amount > self.amount:
raise ValueError("Insufficient balance")
self.blocked += amount
@property
def available_amount(self) -> Decimal:
return self.amount - self.blocked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment