File size: 1,322 Bytes
fe1a549
 
90bddf2
 
 
 
 
 
 
 
 
fe1a549
90bddf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
license: mit
language:
- en
pretty_name: Python Bug Fixes
size_categories:
- n<1K
tags:
- code
- python
- debugging
---

# Python Bug Fixes

Common Python bugs fixed and explained — real broken scripts with before and after code and what went wrong.

Source: [Battingchart300/python-bug-fixes](https://github.com/Battingchart300/python-bug-fixes) on GitHub (MIT).

## Data

One record per bug, in `data.jsonl`:

| Field | What it is |
| --- | --- |
| `bug` | Short slug, e.g. `mutable-default-arg` |
| `title` | Human-readable bug name |
| `broken_code` | The buggy version — run it and see the bug happen |
| `fixed_code` | The fixed version — run it and see the correct result |
| `what_went_wrong` | Plain-English explanation of the bug |
| `fix` | Plain-English explanation of the fix |

## Bugs

| Bug | In short |
| --- | --- |
| `mutable-default-arg` | `def f(x=[])` shares one list between all calls |
| `late-binding-closures` | A `lambda` in a loop sees the last loop value, not the one from its own round |
| `modifying-list-while-iterating` | Deleting from a list while looping over it skips elements |

## Use

```python
from datasets import load_dataset

ds = load_dataset("Battingchart300/python-bug-fixes")
print(ds["train"][0]["title"])
print(ds["train"][0]["broken_code"])
```

## License

MIT