Commit d5067e66 authored by Stefan Behnel's avatar Stefan Behnel

Accept None as typed return value of dict.pop(), which was accidentally disallowed in 0.28.

Closes #2152.
parent 52486bd0
......@@ -26,6 +26,9 @@ Bugs fixed
in some cases where ``bytes`` would have been safe to infer.
(Github issue #2153)
* ``None`` was accidentally disallowed as typed return value of ``dict.pop()``.
(Github issue #2152)
0.28 (2018-03-13)
=================
......
......@@ -3150,6 +3150,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
node, function,
"__Pyx_PyDict_Pop", self.PyDict_Pop_func_type,
'pop', is_unbound_method, args,
may_return_none=True,
utility_code=load_c_utility('py_dict_pop'))
Pyx_PyInt_BinopInt_func_type = PyrexTypes.CFuncType(
......
# mode: run
# tag: dict, pop, builtins
cimport cython
......@@ -32,3 +34,25 @@ def dict_pop_default(dict d, key, default):
(20, {})
"""
return d.pop(key, default), d
cdef class MyType:
cdef public int i
def __init__(self, i):
self.i = i
@cython.test_assert_path_exists("//SingleAssignmentNode//PythonCapiCallNode")
@cython.test_fail_if_path_exists("//SingleAssignmentNode//AttributeNode")
def dict_pop_default_typed(dict d, key, default):
"""
>>> d = {1: MyType(2)}
>>> dict_pop_default_typed(d, 1, None)
2
>>> dict_pop_default_typed(d, 3, None)
>>> dict_pop_default_typed(d, 3, "default") # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: Cannot convert str to ...MyType
"""
cdef MyType x = d.pop(key, default)
return x.i if x is not None else None
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment