#33939 closed Cleanup/optimization (fixed)
Change docs for transaction.on_commit to suggest functools.partial instead of lambda
| Reported by: | Alex Morega | Owned by: | Alex Morega |
|---|---|---|---|
| Component: | Documentation | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I've recently got bitten by a silly bug:
for n in range(10): transaction.on_commit(lambda: do_something(n))
Of course, instead of calling do_something(0), do_something(1) ..., it's going to call do_something(9) 10 times.
The docs could help by suggesting functools.partial instead of lambda. The above example becomes:
for n in range(10): transaction.on_commit(partial(do_something, n))
If this change is a good idea I can have a go at making a PR.
Change History (8)
comment:1 by , 3 years ago
| Component: | Uncategorized → Documentation |
|---|---|
| Version: | 4.0 → dev |
comment:2 by , 3 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Uncategorized → Cleanup/optimization |
comment:3 by , 3 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 3 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Note:
See TracTickets
for help on using tickets.
Hey Alex. OK... I might be a bit marginal but, certainly happy to look at a PR if you're keen to make it.