Skip to content

Commit 21e81b5

Browse files
committed
Fix linting errors.
1 parent f65b854 commit 21e81b5

File tree

17 files changed

+76
-98
lines changed

17 files changed

+76
-98
lines changed

examples/alert/alert.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@
5555
def make_starfield():
5656
# populates the starfield with random stars and ships
5757
global stars, pmc, ship
58-
stars = []
5958
pmc = (random.randint(0, WIDTH - 50), random.randint(HEIGHT - 160, HEIGHT - 120))
60-
for i in range(90):
61-
stars.append((random.randint(8, WIDTH - 8), random.randint(HEIGHT - 180, HEIGHT - 100)))
59+
stars = [(random.randint(8, WIDTH - 8), random.randint(HEIGHT - 180, HEIGHT - 100)) for _ in range(90)]
6260
ship = (random.randint(0, WIDTH - 50), random.randint(HEIGHT - 160, HEIGHT - 120), random.choice(SHIPS))
6361

6462

@@ -88,7 +86,7 @@ def full_refresh():
8886
frequency = 440
8987
# draw the elements that we don't need to redraw every time
9088
# we're drawing them twice, so they end up in both buffers
91-
for i in range(2):
89+
for _ in range(2):
9290
# clear the screen
9391
graphics.set_pen(BLACK)
9492
graphics.clear()
@@ -140,14 +138,12 @@ def rectangle(x, y, w, h, cx=0, cy=0):
140138
graph_hue = 0.0
141139
pulse = 0.0
142140
pulse_direction = PULSE_SPEED
143-
graph_data = []
144141
frequency = 440
145142

146143
# setup
147144
current_mode = MODES[0]
148-
# populate the graph data list with 12 random values between 1 and 100
149-
for i in range(12):
150-
graph_data.append(random.randint(1, 100))
145+
# create the graph data list with 12 random values between 1 and 100
146+
graph_data = [random.randint(1, 100) for _ in range(12)]
151147
vector.set_antialiasing(ANTIALIAS_X16)
152148
full_refresh()
153149

examples/bouncing_logo/bouncing_logo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ def draw_background():
180180
"""Draws a gradient background"""
181181
t = time.ticks_ms() / 1000.0
182182
grid_size = 40
183-
for y in range(0, HEIGHT // grid_size):
184-
for x in range(0, WIDTH // grid_size):
183+
for y in range(HEIGHT // grid_size):
184+
for x in range(WIDTH // grid_size):
185185
h = x + y + int(t * 5)
186186
h = h / 50.0
187187

examples/co2/co2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def line_polygon(top, bottom, min, max, value):
115115

116116
# if lists are empty, populate the list with the current readings
117117
if len(co2_readings) == 0:
118-
for i in range(MAX_READINGS):
118+
for _ in range(MAX_READINGS):
119119
co2_readings.append(co2)
120120
temperature_readings.append(temperature)
121121
humidity_readings.append(humidity)

examples/floppy_birb/floppy_birb.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
# The pipe cap will hide any overshoot.
4343
SPRITE_PIPE_HEIGHT = 10
4444

45+
# Twice to fill the front/back buffers
4546
for _ in range(2):
4647
# Pipes and goals
4748
display.load_sprite("/floppy_birb/pipe.png", SPRITE_PIPE, (0, 0, 20, SPRITE_PIPE_HEIGHT))
@@ -103,7 +104,7 @@
103104
game_state = GAME_GET_READY
104105
t_start = 0
105106

106-
107+
# Twice to fill the front/back buffers
107108
for _ in range(2):
108109
# Scroll position two for fixed top/bottom
109110
display.set_scroll_group_for_lines(2, 0, GAME_TOP - 20)
@@ -168,8 +169,8 @@ def draw_score():
168169

169170

170171
def prep_game():
171-
# Prep the backdrop
172-
for display_index in range(2):
172+
# Prep the backdrop, twice to fill the front/back buffers
173+
for _ in range(2):
173174
display.set_pen(GROUND)
174175
display.clear()
175176
display.set_pen(BLACK)
@@ -218,7 +219,8 @@ def reset_game():
218219

219220
birb.reset()
220221

221-
for display_index in range(2):
222+
# Twice to fill front/back buffer
223+
for _ in range(2):
222224
draw_score()
223225
display.update()
224226

@@ -265,8 +267,9 @@ def test(self, x, y, w, h):
265267
action(**args)
266268

267269
def debug(self, offset_x):
270+
# Twice to fill the front/back buffers
268271
for _ in range(2):
269-
for zone, action in self.zones:
272+
for zone, _ in self.zones:
270273
zx, zy, zw, zh = zone
271274
display.set_pen(display.create_pen(255, 0, 0))
272275
display.rectangle(zx + offset_x, zy, zw, zh)
@@ -358,7 +361,7 @@ def main_game_running(t_current):
358361
if hq_xoffset < GAME_WIDTH and hq_xoffset > -(hq * 32) - 32:
359362
spritelist.add(spr, hq_xoffset + (hq * 32), hq_yoffset)
360363

361-
for pipe in range(0, SLICES + 1):
364+
for pipe in range(SLICES + 1):
362365
try:
363366
gap = PIPE_GAPS[level_offset + pipe]
364367
gap_width = GAP_WIDTHS[level_offset + pipe]

examples/magic_mirror/magic_mirror.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ def connect_to_wifi():
122122
if wlan.isconnected():
123123
print("Connected to WiFi successfully.")
124124
return True
125-
else:
126-
print("Failed to connect to WiFi. Retrying...")
127-
retries += 1
128-
time.sleep(2) # Wait for 2 seconds before retrying
125+
print("Failed to connect to WiFi. Retrying...")
126+
retries += 1
127+
time.sleep(2) # Wait for 2 seconds before retrying
129128

130129
print("Failed to connect to WiFi after maximum retries.")
131130
return False
@@ -137,14 +136,13 @@ def get_data():
137136
if connect_to_wifi() is False:
138137
wifi_problem = True
139138
return
140-
else:
141-
wifi_problem = False
139+
wifi_problem = False
142140

143141
try:
144142
print("Setting time from NTP")
145143
ntptime.settime()
146144
print(f"Time set (UTC): {rtc.datetime()}")
147-
except Exception as e:
145+
except OSError as e:
148146
print(e)
149147

150148
get_weather_data()
@@ -169,7 +167,7 @@ def get_weather_data():
169167
weathercode = current["weathercode"]
170168
date, now = current["time"].split("T")
171169
r.close()
172-
except Exception as e:
170+
except OSError as e:
173171
print(e)
174172

175173

@@ -186,13 +184,13 @@ def get_quote_data():
186184
quote = j[0]["content"]
187185
author = j[0]["author"]
188186
r.close()
189-
except Exception as e:
187+
except OSError as e:
190188
print(e)
191189

192190

193191
def calculate_bearing(d):
194192
# calculates a compass direction from the wind direction in degrees
195-
dirs = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW']
193+
dirs = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]
196194
ix = round(d / (360. / len(dirs)))
197195
return dirs[ix % len(dirs)]
198196

examples/magic_mirror/magic_mirror_home_assistant.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,11 @@
8686
temperature = None
8787
wifi_problem = False
8888

89-
buildings = []
9089
BUILDING_COUNT = 20
91-
for b in range(WIDTH // BUILDING_COUNT):
92-
buildings.append(random.randint(0, HEIGHT // 6))
90+
buildings = [random.randint(0, HEIGHT // 6) for _ in range(WIDTH // BUILDING_COUNT)]
9391

94-
95-
stars = []
9692
STAR_COUNT = 50
97-
for s in range(STAR_COUNT):
98-
stars.append((random.randint(0, WIDTH), random.randint(0, HEIGHT)))
93+
stars = [(random.randint(0, WIDTH), random.randint(0, HEIGHT)) for _ in range(STAR_COUNT)]
9994

10095

10196
# Connect to wifi
@@ -132,10 +127,9 @@ def connect_to_wifi():
132127
if wlan.isconnected():
133128
print("Connected to WiFi successfully.")
134129
return True
135-
else:
136-
print("Failed to connect to WiFi. Retrying...")
137-
retries += 1
138-
time.sleep(2) # Wait for 2 seconds before retrying
130+
print("Failed to connect to WiFi. Retrying...")
131+
retries += 1
132+
time.sleep(2) # Wait for 2 seconds before retrying
139133

140134
print("Failed to connect to WiFi after maximum retries.")
141135
return False
@@ -147,14 +141,13 @@ def get_data():
147141
if connect_to_wifi() is False:
148142
wifi_problem = True
149143
return
150-
else:
151-
wifi_problem = False
144+
wifi_problem = False
152145

153146
try:
154147
print("Setting time from NTP")
155148
ntptime.settime()
156149
print(f"Time set (UTC): {rtc.datetime()}")
157-
except Exception as e:
150+
except OSError as e:
158151
print(e)
159152

160153
get_home_assistant_data()
@@ -177,7 +170,7 @@ def get_home_assistant_data():
177170
print(j)
178171
sunset_date, sunset_time = j["state"].split("T")
179172
r.close()
180-
except Exception as e:
173+
except OSError as e:
181174
print(e)
182175

183176
print("Requesting Home Assistant data")
@@ -188,7 +181,7 @@ def get_home_assistant_data():
188181
print(j)
189182
sunrise_date, sunrise_time = j["state"].split("T")
190183
r.close()
191-
except Exception as e:
184+
except OSError as e:
192185
print(e)
193186

194187

@@ -238,8 +231,8 @@ def redraw_display_if_reqd():
238231

239232
if sunrise_date and sunset_date is not None:
240233
# Convert the sunrise, sunset and RTC times to a common 'minutes since midnight' format, so we can compare:
241-
sunrise_split = sunrise_time.split(':')
242-
sunset_split = sunset_time.split(':')
234+
sunrise_split = sunrise_time.split(":")
235+
sunset_split = sunset_time.split(":")
243236
sunrise_minutes = (int(sunrise_split[0]) + UTC_OFFSET) * 60 + int(sunrise_split[1])
244237
sunset_minutes = (int(sunset_split[0]) + UTC_OFFSET) * 60 + int(sunset_split[1])
245238
rtc_minutes = (rtc.datetime()[4] + UTC_OFFSET) * 60 + rtc.datetime()[5]

examples/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def menu() -> str:
132132
omg_toasters = False
133133
last_button = time.ticks_ms() / 1000.0
134134

135+
# Twice to fill the front/back buffers
135136
for _ in range(2):
136137
display.set_scroll_group_for_lines(1, HEIGHT - 20, HEIGHT)
137138
display.set_scroll_group_offset(1, 0, 0, wrap_x=WIDTH)
@@ -198,7 +199,7 @@ def menu() -> str:
198199

199200
scroll_position += (target_scroll_position - scroll_position) / 5
200201

201-
for y in range(0, int(HEIGHT / 2)):
202+
for y in range(int(HEIGHT / 2)):
202203
bg = background_pen
203204
sl = scanline_pen
204205
if y <= 10:

examples/screenmodes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
modechange = 0
5555

5656
while True:
57-
for p in range(2):
57+
# Twice to fill the front/back buffers
58+
for _ in range(2):
5859
if modeChange == 0:
5960
display.set_pen(0)
6061
display.clear()
@@ -92,7 +93,8 @@
9293
while display.is_button_x_pressed():
9394
m = 0
9495

95-
for p in range(2):
96+
# Twice to fill the front/back buffers
97+
for _ in range(2):
9698
display.set_pen(DARKGREY)
9799
display.rectangle(14, 22, 137, numModes * 10 + 14)
98100
for f in range(numModes):

examples/scrollgroups.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ def drawShip(s):
269269

270270

271271
while True:
272-
for p in range(2):
272+
# Twice to fill the front/back buffers
273+
for _ in range(2):
273274
display.set_scroll_group_for_lines(1, 0, 30)
274275
display.set_scroll_group_for_lines(2, 30, 55)
275276
display.set_scroll_group_for_lines(3, 55, 75)

examples/seafax.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def network_connect(ssid, psk):
5858
if wlan.status() < 0 or wlan.status() >= 3:
5959
break
6060
max_wait -= 1
61-
print('waiting for connection...')
61+
print("waiting for connection...")
6262
time.sleep(1)
6363

6464
# Handle connection error.
@@ -151,8 +151,7 @@ def parse_xml_stream(s, accept_tags, group_by, max_items=7):
151151
def get_rss():
152152
try:
153153
stream = urequest.urlopen(URL)
154-
output = list(parse_xml_stream(stream, [b"title", b"description", b"guid", b"pubDate"], b"item"))
155-
return output
154+
return list(parse_xml_stream(stream, [b"title", b"description", b"guid", b"pubDate"], b"item"))
156155

157156
except OSError as e:
158157
print(e)

examples/sneks_and_ladders/sneks_and_ladders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def draw_level():
146146
fire_tilemap = [0, 2, 1, 4, 3]
147147

148148
# Repeat the frame sequence, adding one to each frame and wrapping on FIRE_FRAMES
149-
for x in range(FIRE_FRAMES + 4):
149+
for _ in range(FIRE_FRAMES + 4):
150150
next_step = [(n + 1) % FIRE_FRAMES for n in fire_tilemap[-FIRE_FRAMES:]]
151151
fire_tilemap += next_step
152152

examples/starfield.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,21 @@
1616
BLACK = graphics.create_pen(0, 0, 0)
1717
WHITE = graphics.create_pen(255, 255, 255)
1818

19-
stars = []
20-
2119

2220
def new_star():
2321
# Create a new star, with initial x, y, and size
2422
# Initial x will fall between -WIDTH / 2 and +WIDTH / 2 and y between -HEIGHT/2 and +HEIGHT/2
2523
# These are relative values for now, treating (0, 0) as the centre of the screen.
26-
star = [random.randint(0, WIDTH) - WIDTH // 2, random.randint(0, HEIGHT) - HEIGHT // 2, 0.5]
27-
return star
24+
return [random.randint(0, WIDTH) - WIDTH // 2, random.randint(0, HEIGHT) - HEIGHT // 2, 0.5]
2825

2926

30-
for i in range(0, NUMBER_OF_STARS):
31-
stars.append(new_star())
27+
stars = [new_star() for _ in range(NUMBER_OF_STARS)]
3228

3329
while True:
3430
graphics.set_pen(BLACK)
3531
graphics.clear()
3632
graphics.set_pen(WHITE)
37-
for i in range(0, NUMBER_OF_STARS):
33+
for i in range(NUMBER_OF_STARS):
3834
# Load a star from the stars list
3935
s = stars[i]
4036

examples/starfield_rainbow.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,20 @@
1818
BLACK = graphics.create_pen(0, 0, 0)
1919
WHITE = graphics.create_pen(255, 255, 255)
2020

21-
stars = []
22-
2321

2422
def new_star():
2523
# Create a new star, with initial x, y, size and hue
2624
# Initial x will fall between -WIDTH / 2 and +WIDTH / 2 and y between -HEIGHT/2 and +HEIGHT/2
2725
# These are relative values for now, treating (0, 0) as the centre of the screen.
28-
star = [random.randint(0, WIDTH) - WIDTH // 2, random.randint(0, HEIGHT) - HEIGHT // 2, 1.0, random.random()]
29-
return star
26+
return [random.randint(0, WIDTH) - WIDTH // 2, random.randint(0, HEIGHT) - HEIGHT // 2, 1.0, random.random()]
3027

3128

32-
for i in range(0, NUMBER_OF_STARS):
33-
stars.append(new_star())
29+
stars = [new_star() for _ in range(NUMBER_OF_STARS)]
3430

3531
while True:
3632
graphics.set_pen(BLACK)
3733
graphics.clear()
38-
for i in range(0, NUMBER_OF_STARS):
34+
for i in range(NUMBER_OF_STARS):
3935
# Load a star from the stars list
4036
s = stars[i]
4137

examples/vector_clock_smooth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
clip_max_y = max(second_hand_bounds[1] + second_hand_bounds[3], minute_hand_bounds[1] + minute_hand_bounds[3], hour_hand_bounds[1] + hour_hand_bounds[3]) + 5
131131

132132
# Remember this clipping window for 2 frames time
133-
last_clip.append((clip_x, clip_y, clip_max_x, clip_max_y),)
133+
last_clip.append((clip_x, clip_y, clip_max_x, clip_max_y))
134134

135135
# Expand to also cover the clipping window from 2 frames ago
136136
clip_x = min(clip_x, last_clip[0][0])

lib/boot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import cppmem
22
# Switch C++ memory allocations to use MicroPython's heap
3-
cppmem.set_mode(cppmem.MICROPYTHON)
3+
cppmem.set_mode(cppmem.MICROPYTHON)

0 commit comments

Comments
 (0)