Skip to content

Commit e15946b

Browse files
authored
Docstrings v2 (#2276)
* Clock docstrings * Properties should appear on separate lines. * ArcadeContext docstrings * Formatting * Formatting * Typing * geometry docstrings * joystick * math * Line length * paths * Astar attribute documentation * perf_graph * Missing sprite docstrings * formatting
1 parent 55c4755 commit e15946b

File tree

11 files changed

+423
-250
lines changed

11 files changed

+423
-250
lines changed

arcade/clock.py

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,49 +36,66 @@ def __init__(
3636
self._tick_speed: float = tick_speed
3737

3838
def tick(self, delta_time: float):
39+
"""
40+
Update the clock with the time that has passed since the last tick.
41+
42+
Args:
43+
delta_time (float): The amount of time that has passed since the last tick.
44+
"""
3945
self._tick_delta_time = delta_time * self._tick_speed
4046
self._elapsed_time += self._tick_delta_time
4147
self._tick += 1
4248

4349
def set_tick_speed(self, new_tick_speed: float):
50+
"""
51+
Set the speed of time for this clock.
52+
53+
Args:
54+
new_tick_speed (float): A multiplier on the 'speed' of time.
55+
i.e. a value of 0.5 means time elapsed half as fast for this clock.
56+
"""
4457
self._tick_speed = new_tick_speed
4558

46-
def time_since(self, time: float):
59+
def time_since(self, time: float) -> float:
60+
"""
61+
Calculate the amount of time that has passed since the given time.
62+
63+
Args:
64+
time (float): The time to compare against.
65+
"""
4766
return self._elapsed_time - time
4867

49-
def ticks_since(self, tick: int):
68+
def ticks_since(self, tick: int) -> int:
69+
"""
70+
Calculate the number of ticks that have occurred since the given tick.
71+
72+
Args:
73+
tick (int): The tick to compare against.
74+
"""
5075
return self._tick - tick
5176

5277
@property
53-
def time(self):
54-
"""
55-
The total number of seconds that have elapsed for this clock
56-
"""
78+
def time(self) -> float:
79+
"""The total number of seconds that have elapsed for this clock"""
5780
return self._elapsed_time
5881

5982
@property
60-
def t(self):
61-
"""
62-
Alias to Clock.time
63-
"""
83+
def t(self) -> float:
84+
"""Alias to Clock.time"""
6485
return self._elapsed_time
6586

6687
@property
67-
def delta_time(self):
68-
"""
69-
The amount of time that elapsed during the last tick
70-
"""
88+
def delta_time(self) -> float:
89+
"""The amount of time that elapsed during the last tick"""
7190
return self._tick_delta_time
7291

7392
@property
74-
def dt(self):
75-
"""
76-
Alias to Clock.delta_time
77-
"""
93+
def dt(self) -> float:
94+
"""Alias to Clock.delta_time"""
7895
return self.delta_time
7996

8097
@property
81-
def speed(self):
98+
def speed(self) -> float:
8299
"""
83100
A modifier on the delta time that elapsed each tick.
84101
@@ -88,17 +105,13 @@ def speed(self):
88105
return self._tick_speed
89106

90107
@property
91-
def ticks(self):
92-
"""
93-
The number of ticks that have occurred for this clock
94-
"""
108+
def ticks(self) -> int:
109+
"""The number of ticks that have occurred for this clock."""
95110
return self._tick
96111

97112
@property
98-
def tick_count(self):
99-
"""
100-
Alias to Clock.ticks
101-
"""
113+
def tick_count(self) -> int:
114+
"""Alias to Clock.ticks"""
102115
return self._tick
103116

104117

@@ -121,11 +134,24 @@ def __init__(self, sibling: Clock, fixed_tick_rate: float = 1.0 / 60.0):
121134
super().__init__()
122135

123136
def set_tick_speed(self, new_tick_speed: float):
137+
"""
138+
Set the speed of time for this clock.
139+
140+
Args:
141+
new_tick_speed (float): A multiplier on the 'speed' of time.
142+
i.e. a value of 0.5 means time elapsed half as fast for this clock
143+
"""
124144
raise ValueError(
125145
"It is not safe to change the tick speed of a fixed clock post initialization."
126146
)
127147

128148
def tick(self, delta_time: float):
149+
"""
150+
Update the clock with the time that has passed since the last tick.
151+
152+
Args:
153+
delta_time (float): The amount of time that has passed since the last tick.
154+
"""
129155
if delta_time != self._fixed_rate:
130156
raise ValueError(
131157
f"the delta_time {delta_time}, "
@@ -134,15 +160,18 @@ def tick(self, delta_time: float):
134160
super().tick(self._fixed_rate)
135161

136162
@property
137-
def rate(self):
163+
def rate(self) -> float:
164+
"""The fixed number of seconds that pass for this clock every tick."""
138165
return self._fixed_rate
139166

140167
@property
141-
def accumulated(self):
168+
def accumulated(self) -> float:
169+
"""The total number of seconds that have elapsed for this clock"""
142170
return self._sibling_clock.time - self._elapsed_time
143171

144172
@property
145-
def fraction(self):
173+
def fraction(self) -> float:
174+
"""The fraction of a fixed tick that has passed since the last tick."""
146175
return self.accumulated / self._fixed_rate
147176

148177

0 commit comments

Comments
 (0)