Path: blob/main/extensions/copilot/test/simulation/fixtures/review/bank-account-1.py
13399 views
import threading123class BankAccount:4def __init__(self):5self.is_open = False6self.balance = None7self.lock = threading.Lock()89def get_balance(self):10with self.lock:11if not self.is_open:12raise ValueError('account not open')13return self.balance1415def open(self):16if self.is_open:17raise ValueError('account already open')18self.is_open = True19self.balance = 02021def deposit(self, amount):22with self.lock:23if not self.is_open:24raise ValueError('account not open')25if amount <= 0:26raise ValueError('amount must be greater than 0')27self.balance += amount2829def withdraw(self, amount):30with self.lock:31if not self.is_open:32raise ValueError('account not open')33if amount <= 0:34raise ValueError('amount must be greater than 0')35if amount > self.balance:36raise ValueError('amount must be less than balance')37self.balance -= amount3839def close(self):40if not self.is_open:41raise ValueError('account not open')42self.is_open = False4344