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
Gwenaël Samain
cython
Commits
4a279e63
Commit
4a279e63
authored
Jan 14, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement #470: non-dicts as **kwargs
parent
f81c75f4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
0 deletions
+74
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+22
-0
tests/run/non_dict_kwargs_T470.pyx
tests/run/non_dict_kwargs_T470.pyx
+52
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
4a279e63
...
...
@@ -2775,6 +2775,7 @@ class GeneralCallNode(CallNode):
def
generate_result_code
(
self
,
code
):
if
self
.
type
.
is_error
:
return
dict_temp
=
dict_ref
=
None
if
self
.
keyword_args
and
self
.
starstar_arg
:
code
.
put_error_if_neg
(
self
.
pos
,
"PyDict_Update(%s, %s)"
%
(
...
...
@@ -2785,6 +2786,23 @@ class GeneralCallNode(CallNode):
keyword_code
=
self
.
keyword_args
.
py_result
()
elif
self
.
starstar_arg
:
keyword_code
=
self
.
starstar_arg
.
py_result
()
if
self
.
starstar_arg
.
type
is
not
Builtin
.
dict_type
:
# CPython supports calling functions with non-dicts, so do we
dict_temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
False
)
dict_ref
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
code
.
putln
(
"if (unlikely(!PyDict_Check(%s))) {"
%
keyword_code
)
code
.
putln
(
"%s = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, %s, NULL); %s"
%
(
dict_ref
,
keyword_code
,
code
.
error_goto_if_null
(
dict_ref
,
self
.
pos
)))
code
.
put_gotref
(
dict_ref
)
code
.
putln
(
"%s = %s;"
%
(
dict_temp
,
dict_ref
))
code
.
putln
(
"} else {"
)
code
.
putln
(
"%s = 0;"
%
dict_ref
)
code
.
putln
(
"%s = %s;"
%
(
dict_temp
,
keyword_code
))
code
.
putln
(
"}"
)
keyword_code
=
dict_temp
else
:
keyword_code
=
None
if
not
keyword_code
:
...
...
@@ -2802,6 +2820,10 @@ class GeneralCallNode(CallNode):
call_code
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
py_result
())
if
dict_ref
is
not
None
:
code
.
funcstate
.
release_temp
(
dict_temp
)
code
.
put_xdecref_clear
(
dict_ref
,
py_object_type
)
code
.
funcstate
.
release_temp
(
dict_ref
)
class
AsTupleNode
(
ExprNode
):
...
...
tests/run/non_dict_kwargs_T470.pyx
0 → 100644
View file @
4a279e63
__doc__
=
u"""
>>> func(**{'a' : 7})
True
>>> func(**SubDict())
True
>>> call_non_dict_test()
True
>>> call_non_dict_test_kw()
True
>>> call_sub_dict_test()
True
>>> call_sub_dict_test_kw()
True
"""
import
sys
if
sys
.
version_info
>=
(
2
,
6
):
__doc__
+=
u"""
>>> func(**NonDict())
True
"""
def
func
(
**
kwargs
):
return
type
(
kwargs
)
is
dict
and
kwargs
[
'a'
]
==
7
class
NonDict
(
object
):
def
__getitem__
(
self
,
k
):
assert
k
==
'a'
return
7
def
keys
(
self
):
return
[
'a'
]
def
call_non_dict_test
():
return
func
(
**
NonDict
())
def
call_non_dict_test_kw
():
return
func
(
a
=
5
,
**
NonDict
())
class
SubDict
(
dict
):
def
__init__
(
self
):
self
[
'a'
]
=
7
def
call_sub_dict_test
():
return
func
(
**
SubDict
())
def
call_sub_dict_test_kw
():
return
func
(
a
=
5
,
**
SubDict
())
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