Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
d5067e66
Commit
d5067e66
authored
Mar 18, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept None as typed return value of dict.pop(), which was accidentally disallowed in 0.28.
Closes #2152.
parent
52486bd0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
0 deletions
+28
-0
CHANGES.rst
CHANGES.rst
+3
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+1
-0
tests/run/dict_pop.pyx
tests/run/dict_pop.pyx
+24
-0
No files found.
CHANGES.rst
View file @
d5067e66
...
...
@@ -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)
=================
...
...
Cython/Compiler/Optimize.py
View file @
d5067e66
...
...
@@ -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
(
...
...
tests/run/dict_pop.pyx
View file @
d5067e66
# 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment