realpython / realpython/python-guide
"Late-binding" isn't the issue with closures on a loop
Nobody has claimed this yet.
- Dominant language
- Batchfile
- Stars
- 29.8k
- Forks
- 5.9k
- PR merge metrics
- No merged PRs in 30d
Description
Lua also has late-binding closures, as can be seen here: https://repl.it/repls/HotpinkEagerQuery (the first one intentionally misused to highlight the difference between block scope and function scope)
It just also has block scope. That's the thing python doesn't have, thus causing the confusion.
Block scope is better emulated with nested functions, such as:
for i in range(5):
def block_scope_emulation(i):
def thing(x):
return x*i
block_scope_emulation(i)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the guide passage that explains closures in a loop and compare its wording with the linked Lua example and the nested-function example in the issue. Done means the explanation distinguishes late binding from block scope and accurately describes the Python behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100