Issue #2508 resolved

Dictionary pop (with default) fails with KeyError for some keys

Jason Myers
created an issue

Latest release (5.7.0) OSX binary

Seems to depend on the type of keys in the dictionary.

Python 2.7.13 (fa3249d55d15, Mar 19 2017, 19:48:32)
[PyPy 5.7.0 with GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> {}.pop(None, None)
>>>> {1: 1}.pop(None, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: None
>>>> {'a': 'a'}.pop(None, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: None
>>>> {}.pop(1, None)
>>>> {1: 1}.pop(1, None)
1
>>>> {'a': 'a'}.pop(1, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 1
>>>>

Confirmed it does work on previous (5.6.0):

Python 2.7.12 (aff251e54385, Nov 09 2016, 17:25:49)
[PyPy 5.6.0 with GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> {}.pop(None, None)
>>>> {1: 1}.pop(None, None)
>>>> {'a': 'a'}.pop(None, None)
>>>> {}.pop(1, None)
>>>> {1: 1}.pop(1, None)
1
>>>> {'a': 'a'}.pop(1, None)
>>>>

Comments (3)

  1. Log in to comment