One function

Munch in Infinidat/munch

The author described this change as Fix __contains__ returning True for Munch’s default attributes Includes changes from #6, as I couldn't test without it.. It counts as a record because the check below fails on the code as it stood at 734460414 and passes on 4e030f6a9, with nothing else changed between the two runs.

Fix saved2015-12-01
Sharing licenceMIT · LICENSE.txt
Change size+0 24

What the code was meant to do, written into the code itself as a docstring

A dictionary that provides attribute-style access. A Munch is a subclass of dict; it supports all the methods a dict does... Including update()... As well as iteration... And "splats". See unmunchify/Munch.toDict, munchify/Munch.fromDict for notes about conversion.

The change

3838 See unmunchify/Munch.toDict, munchify/Munch.fromDict for notes about conversion.
3939 """
4040
41- def __contains__(self, k):
42- """ >>> b = Munch(ponies='are pretty!')
43- >>> 'ponies' in b
44- True
45- >>> 'foo' in b
46- False
47- >>> b['foo'] = 42
48- >>> 'foo' in b
49- True
50- >>> b.hello = 'hai'
51- >>> 'hello' in b
52- True
53- >>> b[None] = 123
54- >>> None in b
55- True
56- >>> b[False] = 456
57- >>> False in b
58- True
59- """
60- try:
61- return dict.__contains__(self, k) or hasattr(self, k)
62- except:
63- return False
64-
6541 # only called if k not found in normal places
6642 def __getattr__(self, k):
6743 """ Gets key if it exists, otherwise throws AttributeError.

The check that tells the two apart

failpass·test_munch.py::test_reserved_attributes[__class__]

Check file test_munch.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 it734460414667af37c8632be84cbb228750c696ef
Broken version dated2015-12-01
Modulemunch.__init__
Units changedMunch
Fingerprint950a24f0bc1aaab5
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.