One function
Dict in mewwts/addict
The author described this change as “Should fix issue #28 with the constructor not working well”. It counts as a record because the check below fails on the code as it stood at 1ae299183 and passes on bc5a78e62, with nothing else changed between the two runs.
Projectmewwts/addict
Fix saved2014-12-14
Sharing licenceMIT · LICENSE
Change size+10 −4
What the code was meant to do, written into the code itself as a docstring
Dict is a subclass of dict, which allows you to get AND SET(!!) items in the dict using the attribute syntax! When you previously had to write: my_dict = {'a': {'b': {'c': [1, 2, 3]}}} you can now do the same simply by: my_Dict = Dict() my_Dict.a.b.c = [1, 2, 3] Or for instance, if you'd like to add some additional stuff, where you'd with the normal dict would write my_dict['a']['b']['d'] = [4, 5, 6], you may now do the AWESOME my_Dict.a.b.d = [4, 5, 6] instead. But hey, you can always use the same syntax as a regular dict, however, this will not raise TypeErrors or AtrributeErrors at any time while you try to get an item. A lot like a defaultdict.
The change
| 34 | 34 | """ | |
| 35 | 35 | for arg in args: | |
| 36 | 36 | if not arg: | |
| 37 | - | pass | |
| 37 | + | continue | |
| 38 | 38 | elif isinstance(arg, dict): | |
| 39 | 39 | for key, val in arg.items(): | |
| 40 | 40 | self[key] = val | |
| 41 | - | else: | |
| 41 | + | elif isinstance(arg, list) or isgenerator(arg): | |
| 42 | + | for key, val in arg: | |
| 43 | + | self[key] = val | |
| 44 | + | elif isinstance(arg, tuple): | |
| 42 | 45 | self[arg[0]] = arg[1] | |
| 46 | + | else: | |
| 47 | + | raise TypeError("Dict does not understand " | |
| 48 | + | "{0} types".format(type(arg))) | |
| 43 | 49 | ||
| 44 | 50 | for key, val in kwargs.items(): | |
| 45 | 51 | self[key] = val | |
| ⋯ | |||
| 50 | 56 | ||
| 51 | 57 | """ | |
| 52 | 58 | if hasattr(Dict, name): | |
| 53 | - | raise AttributeError("'Dict' object attribute" | |
| 54 | - | " '{0}' is read-only".format(name)) | |
| 59 | + | raise AttributeError("'Dict' object attribute " | |
| 60 | + | "'{0}' is read-only".format(name)) | |
| 55 | 61 | else: | |
| 56 | 62 | self[name] = value | |
| 57 | 63 | ||
The check that tells the two apart
fail→pass·test_addict.py::Tests::test_init_raises
Check file test_addict.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it1ae29918391857bac904361ad6cf7b9a9c568632
Broken version dated2014-12-14
Moduleaddict.addict
Units changedDict
Fingerprintc6ca7d722d4a1820
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in mewwts/addict
- 2017-03-05Should fix #85, #86 and #88