mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
bpo-39264: Fix UserDict.get() to account for __missing__() (GH-17910)
Here's the patch according to the discussion at the [Python-Dev mailing list](https://mail.python.org/archives/list/python-dev@python.org/thread/SDXOEMAEM6KQ3CQCJVBVRT5QNSPAVU6X/). UserDict.get() will match dict's behavior and not call `__missing__`. Automerge-Triggered-By: GH:rhettinger
This commit is contained in:
parent
f481a02e6c
commit
30a43586f0
3 changed files with 19 additions and 1 deletions
|
|
@ -71,6 +71,14 @@ class TestUserObjects(unittest.TestCase):
|
|||
obj[123] = "abc"
|
||||
self._copy_test(obj)
|
||||
|
||||
def test_dict_missing(self):
|
||||
class A(UserDict):
|
||||
def __missing__(self, key):
|
||||
return 456
|
||||
self.assertEqual(A()[123], 456)
|
||||
# get() ignores __missing__ on dict
|
||||
self.assertIs(A().get(123), None)
|
||||
|
||||
|
||||
################################################################################
|
||||
### ChainMap (helper class for configparser and the string module)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue