Skip to content

Commit 8dff675

Browse files
travisjneumanclaude
andcommitted
fix: nonlocal → global for module-level variables in challenge files
Three challenge files used `nonlocal` to reference module-level variables, which is a SyntaxError. Module-level variables require `global` instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fc20a30 commit 8dff675

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

practice/challenges/intermediate/05-retry-decorator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def retry(max_retries: int = 3, base_delay: float = 0.1, exceptions: tuple = (Ex
3939

4040
@retry(max_retries=3, base_delay=0.001)
4141
def always_works():
42-
nonlocal call_count
42+
global call_count
4343
call_count += 1
4444
return "ok"
4545

@@ -51,7 +51,7 @@ def always_works():
5151

5252
@retry(max_retries=5, base_delay=0.001)
5353
def works_third_try():
54-
nonlocal attempt
54+
global attempt
5555
attempt += 1
5656
if attempt < 3:
5757
raise ValueError("not yet")

practice/challenges/intermediate/13-async-fetcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def async_fetch_all(urls: list[str], fetch_func, max_concurrent: int = 5)
4444
current_simultaneous = 0
4545

4646
async def fake_fetch(url: str) -> str:
47-
nonlocal fetch_count, max_simultaneous, current_simultaneous
47+
global fetch_count, max_simultaneous, current_simultaneous
4848
fetch_count += 1
4949
current_simultaneous += 1
5050
max_simultaneous = max(max_simultaneous, current_simultaneous)

practice/challenges/solutions/intermediate/05-retry-decorator-solution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def wrapper(*args, **kwargs):
3737

3838
@retry(max_retries=3, base_delay=0.001)
3939
def always_works():
40-
nonlocal call_count
40+
global call_count
4141
call_count += 1
4242
return "ok"
4343

@@ -48,7 +48,7 @@ def always_works():
4848

4949
@retry(max_retries=5, base_delay=0.001)
5050
def works_third_try():
51-
nonlocal attempt
51+
global attempt
5252
attempt += 1
5353
if attempt < 3:
5454
raise ValueError("not yet")

practice/challenges/solutions/intermediate/13-async-fetcher-solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def limited_fetch(url: str) -> str:
3434
current_simultaneous = 0
3535

3636
async def fake_fetch(url: str) -> str:
37-
nonlocal fetch_count, max_simultaneous, current_simultaneous
37+
global fetch_count, max_simultaneous, current_simultaneous
3838
fetch_count += 1
3939
current_simultaneous += 1
4040
max_simultaneous = max(max_simultaneous, current_simultaneous)

0 commit comments

Comments
 (0)