Path: blob/main/extensions/copilot/test/simulation/fixtures/review/bank-account-2.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):16with self.lock:17if self.is_open:18raise ValueError('account already open')19self.is_open = True20self.balance = 02122def deposit(self, amount):23with self.lock:24if not self.is_open:25raise ValueError('account not open')26if amount <= 0:27raise ValueError('amount must be greater than 0')28self.balance += amount2930def withdraw(self, amount):31with self.lock:32if not self.is_open:33raise ValueError('account not open')34if amount <= 0:35raise ValueError('amount must be greater than 0')36if amount > self.balance:37raise ValueError('amount must be less than balance')38self.balance -= amount3940def close(self):41with self.lock:42if not self.is_open:43raise ValueError('account not open')44self.is_open = False4546