Skip to content

Commit

Permalink
doc:type hints in bank renege example
Browse files Browse the repository at this point in the history
  • Loading branch information
galenseilis committed Dec 1, 2024
1 parent 4634e10 commit 4a76088
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions examples/simpy/bank_renege.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def __init__(self, env: EventScheduler, capacity: int) -> None:
self.env: EventScheduler = env
self.capacity: int = capacity
self.available: int = capacity
self.queue = []
self.queue: list[Customer] = []

def request(self, customer):
def request(self, customer: Customer) -> None:
"""Request service for a customer. If there's space, they will be served immediately,
otherwise, they join the queue.
"""
Expand All @@ -80,7 +80,7 @@ def request(self, customer):
self.queue.append(customer)
print(f"{customer.name} is waiting at {self.env.current_time}")

def release(self):
def release(self) -> None:
"""Release a spot when a customer finishes service. If there are customers in the queue,
schedule the next one to be served.
"""
Expand Down Expand Up @@ -108,13 +108,13 @@ class Customer:

def __init__(
self, env: EventScheduler, name: str, counter: Counter, time_in_bank: float
):
self.env = env
self.name = name
self.counter = counter
self.patience = random.uniform(MIN_PATIENCE, MAX_PATIENCE)
self.time_in_bank = time_in_bank
self.arrive_time = self.env.current_time
) -> None:
self.env: EventScheduler = env
self.name: str = name
self.counter: Counter = counter
self.patience: float = random.uniform(MIN_PATIENCE, MAX_PATIENCE)
self.time_in_bank: float = time_in_bank
self.arrive_time: float = self.env.current_time
print(f"{self.arrive_time:.4f} {self.name}: Here I am")
self.env.schedule(Event(self.arrive_time, self.check_patience))

Expand Down

0 comments on commit 4a76088

Please sign in to comment.