Skip to content

Commit 8ebc66c

Browse files
authored
fix(scripts): Fix mixing implicit and explicit returns (#47)
* fix(scripts): Fix mixing implicit and explicit returns in _fetch_full_article_json - Add explicit return None for max_retries < 1 to avoid implicit fall-through - Ensure all code paths in _fetch_full_article_json return explicitly Generated-by: GitHub Copilot <copilot@github.com> Signed-off-by: Ashley Childress <6563688+anchildress1@users.noreply.github.com> * style(scripts): Remove dead return statement in _fetch_full_article_json - The return None after the loop was unreachable since all execution paths return explicitly Commit-generated-by Signed-off-by: Ashley Childress <6563688+anchildress1@users.noreply.github.com> --------- Signed-off-by: Ashley Childress <6563688+anchildress1@users.noreply.github.com>
1 parent 6e46b48 commit 8ebc66c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

scripts/generate_site.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ def _fetch_full_article_json(
168168
timeout: int = 30,
169169
initial_retry_delay: int = 2,
170170
) -> dict | None:
171+
# Defensive: if the caller asks for zero attempts, be explicit about returning None.
172+
# (Avoids mixing explicit and implicit returns.)
173+
if max_retries < 1:
174+
return None
175+
171176
retry_delay = initial_retry_delay
172177
for attempt in range(max_retries):
173178
try:
@@ -176,7 +181,7 @@ def _fetch_full_article_json(
176181
return full_response.json()
177182
except (requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError) as e:
178183
if attempt < max_retries - 1:
179-
print(f" ⚠️ Timeout/connection error on attempt {attempt + 1}, " f"retrying in {retry_delay}s...")
184+
print(f" ⚠️ Timeout/connection error on attempt {attempt + 1}, retrying in {retry_delay}s...")
180185
time.sleep(retry_delay)
181186
retry_delay *= 2 # Exponential backoff
182187
continue
@@ -351,8 +356,7 @@ def fetch_all_articles_from_api(last_run_iso=None) -> FetchArticlesResult:
351356
# Get the post template (from file or inline fallback)
352357
PAGE_TMPL = get_post_template()
353358

354-
COMMENT_NOTE_TMPL = env.from_string(
355-
"""<!doctype html><html lang="en"><head>
359+
COMMENT_NOTE_TMPL = env.from_string("""<!doctype html><html lang="en"><head>
356360
<meta charset="utf-8">
357361
<title>{{ title }}</title>
358362
<link rel="canonical" href="{{ canonical }}">
@@ -405,8 +409,7 @@ def fetch_all_articles_from_api(last_run_iso=None) -> FetchArticlesResult:
405409
<p><a href="{{ url }}">Open on Dev.to →</a></p>
406410
</main>
407411
</body></html>
408-
"""
409-
)
412+
""")
410413

411414

412415
# ----------------------------

0 commit comments

Comments
 (0)