Skip to content

Commit 838671b

Browse files
committed
cell-var-from-loop
1 parent 308d216 commit 838671b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

docs/examples/python/tutorial-tic-tac-toe/tic_tac_toe.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ def square(value, on_square_click):
1313

1414
@component
1515
def board(x_is_next, squares, on_play):
16+
1617
def handle_click(i):
17-
def event(_event):
18+
def handle_click_event(_event):
19+
"""Due to a quirk of Python, if your event handler needs args other than
20+
`event`, you will need to create a wrapper function as seen above.
21+
Ref: https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/cell-var-from-loop.html"""
1822
if calculate_winner(squares) or squares[i]:
1923
return
2024

2125
next_squares = squares.copy()
2226
next_squares[i] = "X" if x_is_next else "O"
2327
on_play(next_squares)
2428

25-
return event
29+
return handle_click_event
2630

2731
winner = calculate_winner(squares)
2832
status = (

docs/src/learn/tutorial-tic-tac-toe.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ In the code example below, click **Run** to open the editor in a new tab using t
8181
1. Install [Python](https://www.python.org/downloads/)
8282
2. Copy the example above into a file called `app.py`
8383
3. Install ReactPy for your [backend](../reference/fastapi.md), for example `pip install reactpy[fastapi]`
84-
4. Run `python app.py` to start a local server and follow the prompts to view the code running in a browser
84+
4. Add `reactpy.run(...)` to the end of your Python file
85+
5. Run `python app.py` to start a local server and follow the prompts to view the code running in a browser
8586

8687
If you get stuck, don't let this stop you! Follow along online instead and try a local setup again later.
8788

0 commit comments

Comments
 (0)