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
Boxiang Sun
cython
Commits
d7764340
Commit
d7764340
authored
Aug 27, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some more testing and tweaking of common cases, follow more descriptive Py3 error messages
parent
805cf073
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
72 additions
and
48 deletions
+72
-48
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+35
-31
tests/run/callargs.pyx
tests/run/callargs.pyx
+20
-0
tests/run/classkwonlyargs.pyx
tests/run/classkwonlyargs.pyx
+2
-2
tests/run/extkwonlyargs.pyx
tests/run/extkwonlyargs.pyx
+2
-2
tests/run/extstarargs.pyx
tests/run/extstarargs.pyx
+4
-4
tests/run/kwonlyargs.pyx
tests/run/kwonlyargs.pyx
+2
-2
tests/run/kwonlyargscall.pyx
tests/run/kwonlyargscall.pyx
+3
-3
tests/run/starargs.pyx
tests/run/starargs.pyx
+4
-4
No files found.
Cython/Compiler/Nodes.py
View file @
d7764340
...
...
@@ -1685,12 +1685,6 @@ class DefNode(FuncDefNode):
def
generate_arg_decref
(
self
,
arg
,
code
):
if
arg
:
code
.
put_var_decref
(
arg
.
entry
)
def
arg_address
(
self
,
arg
):
if
arg
:
return
"&%s"
%
arg
.
entry
.
cname
else
:
return
0
def
generate_stararg_copy_code
(
self
,
code
):
if
not
self
.
star_arg
:
...
...
@@ -1703,9 +1697,17 @@ class DefNode(FuncDefNode):
code
.
globalstate
.
use_utility_code
(
keyword_string_check_utility_code
)
if
self
.
starstar_arg
:
if
self
.
star_arg
:
kwarg_check
=
"unlikely(%s)"
%
Naming
.
kwds_cname
else
:
kwarg_check
=
"%s"
%
Naming
.
kwds_cname
else
:
kwarg_check
=
"unlikely(%s) && unlikely(PyDict_Size(%s) > 0)"
%
(
Naming
.
kwds_cname
,
Naming
.
kwds_cname
)
code
.
putln
(
"if (
unlikely(%s)
&& unlikely(!__Pyx_CheckKeywordStrings(%s,
\
"
%s
\
"
, %d))) return %s;"
%
(
Naming
.
kwds_cname
,
Naming
.
kwds_cname
,
self
.
name
,
"if (
%s
&& unlikely(!__Pyx_CheckKeywordStrings(%s,
\
"
%s
\
"
, %d))) return %s;"
%
(
kwarg_check
,
Naming
.
kwds_cname
,
self
.
name
,
bool
(
self
.
starstar_arg
),
self
.
error_value
()))
if
self
.
starstar_arg
:
...
...
@@ -4423,10 +4425,10 @@ static INLINE void __Pyx_RaiseDoubleKeywordsError(
keyword_string_check_utility_code
=
[
"""
static int __Pyx_CheckKeywordStrings(PyObject *kwdict,
static
INLINE
int __Pyx_CheckKeywordStrings(PyObject *kwdict,
const char* function_name, int kw_allowed); /*proto*/
"""
,
"""
static int __Pyx_CheckKeywordStrings(
static
INLINE
int __Pyx_CheckKeywordStrings(
PyObject *kwdict,
const char* function_name,
int kw_allowed)
...
...
@@ -4435,27 +4437,29 @@ static int __Pyx_CheckKeywordStrings(
Py_ssize_t pos = 0;
while (PyDict_Next(kwdict, &pos, &key, 0)) {
#if PY_MAJOR_VERSION < 3
if (unlikely(!PyString_Check(key))) {
#else
if (unlikely(!PyUnicode_Check(key))) {
#endif
PyErr_Format(PyExc_TypeError,
"%s() keywords must be strings", function_name);
return 0;
}
}
if (unlikely(!kw_allowed) && unlikely(key)) {
PyErr_Format(PyExc_TypeError,
#if PY_MAJOR_VERSION < 3
"'%s' is an invalid keyword argument for this function",
PyString_AsString(key));
if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
#else
"'%U' is an invalid keyword argument for this function",
key);
if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key)))
#endif
return 0
;
goto invalid_keyword_type
;
}
if ((!kw_allowed) && unlikely(key))
goto invalid_keyword;
return 1;
invalid_keyword_type:
PyErr_Format(PyExc_TypeError,
"%s() keywords must be strings", function_name);
return 0;
invalid_keyword:
PyErr_Format(PyExc_TypeError,
#if PY_MAJOR_VERSION < 3
"%s() got an unexpected keyword argument '%s'",
function_name, PyString_AsString(key));
#else
"%s() got an unexpected keyword argument '%U'",
function_name, key);
#endif
return 0;
}
"""
]
...
...
@@ -4535,11 +4539,11 @@ invalid_keyword_type:
invalid_keyword:
PyErr_Format(PyExc_TypeError,
#if PY_MAJOR_VERSION < 3
"
'%s' is an invalid keyword argument for this function
",
PyString_AS_STRING
(key));
"
%s() got an unexpected keyword argument '%s'
",
function_name, PyString_AsString
(key));
#else
"
'%U' is an invalid keyword argument for this function
",
key);
"
%s() got an unexpected keyword argument '%U'
",
function_name,
key);
#endif
bad:
return -1;
...
...
tests/run/callargs.pyx
View file @
d7764340
...
...
@@ -58,6 +58,26 @@ __doc__ = u"""
Traceback (most recent call last):
TypeError: h() takes at least 3 positional arguments (2 given)
>>> f(1,2, d=5)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'd'
>>> f(1, d=5)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'd'
>>> f(d=5)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'd'
>>> g(1,2, d=5)
Traceback (most recent call last):
TypeError: g() takes exactly 0 positional arguments (2 given)
>>> g(1,2)
Traceback (most recent call last):
TypeError: g() takes exactly 0 positional arguments (2 given)
>>> g(1)
Traceback (most recent call last):
TypeError: g() takes exactly 0 positional arguments (1 given)
>>> test_int_kwargs(e)
Traceback (most recent call last):
TypeError: e() keywords must be strings
...
...
tests/run/classkwonlyargs.pyx
View file @
d7764340
...
...
@@ -21,7 +21,7 @@ __doc__ = u"""
TypeError: d() takes exactly 3 positional arguments (4 given)
>>> d(1,2, d=1)
Traceback (most recent call last):
TypeError:
'd' is an invalid keyword argument for this function
TypeError:
d() got an unexpected keyword argument 'd'
>>> e(1,2)
>>> e(1,2, c=1)
...
...
@@ -43,7 +43,7 @@ __doc__ = u"""
TypeError: f() needs keyword-only argument c
>>> f(1,2, c=1, e=2)
Traceback (most recent call last):
TypeError:
'e' is an invalid keyword argument for this function
TypeError:
f() got an unexpected keyword argument 'e'
>>> g(1,2, c=1, f=2)
>>> g(1,2, c=1, e=0, f=2, d=11)
...
...
tests/run/extkwonlyargs.pyx
View file @
d7764340
...
...
@@ -21,7 +21,7 @@ __doc__ = u"""
TypeError: d() takes exactly 2 positional arguments (3 given)
>>> d(1,2, d=1)
Traceback (most recent call last):
TypeError:
'd' is an invalid keyword argument for this function
TypeError:
d() got an unexpected keyword argument 'd'
>>> e(1,2)
>>> e(1,2, c=1)
...
...
@@ -43,7 +43,7 @@ __doc__ = u"""
TypeError: f() needs keyword-only argument c
>>> f(1,2, c=1, e=2)
Traceback (most recent call last):
TypeError:
'e' is an invalid keyword argument for this function
TypeError:
f() got an unexpected keyword argument 'e'
>>> g(1,2, c=1, f=2)
>>> g(1,2, c=1, e=0, f=2, d=11)
...
...
tests/run/extstarargs.pyx
View file @
d7764340
...
...
@@ -13,7 +13,7 @@ __doc__ = u"""
TypeError: spam() takes exactly 3 positional arguments (4 given)
>>> spam(1,2,3, a=1) #doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError:
'a' is an invalid keyword argument for this function
TypeError:
spam() got an unexpected keyword argument 'a'
>>> grail(1,2,3)
(1, 2, 3, ())
...
...
@@ -26,7 +26,7 @@ __doc__ = u"""
TypeError: grail() takes at least 3 positional arguments (2 given)
>>> grail(1,2,3, a=1) #doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError:
'a' is an invalid keyword argument for this function
TypeError:
grail() got an unexpected keyword argument 'a'
>>> swallow(1,2,3)
(1, 2, 3, ())
...
...
@@ -57,10 +57,10 @@ __doc__ = u"""
(1, 2)
>>> onlyt(a=1)
Traceback (most recent call last):
TypeError:
'a' is an invalid keyword argument for this function
TypeError:
onlyt() got an unexpected keyword argument 'a'
>>> onlyt(1, a=2)
Traceback (most recent call last):
TypeError:
'a' is an invalid keyword argument for this function
TypeError:
onlyt() got an unexpected keyword argument 'a'
>>> onlyk(a=1)
(('a', 1),)
...
...
tests/run/kwonlyargs.pyx
View file @
d7764340
...
...
@@ -18,7 +18,7 @@ __doc__ = u"""
TypeError: d() takes exactly 2 positional arguments (3 given)
>>> d(1,2, d=1)
Traceback (most recent call last):
TypeError:
'd' is an invalid keyword argument for this function
TypeError:
d() got an unexpected keyword argument 'd'
>>> e(1,2)
>>> e(1,2, c=1)
...
...
@@ -40,7 +40,7 @@ __doc__ = u"""
TypeError: f() needs keyword-only argument c
>>> f(1,2, c=1, e=2)
Traceback (most recent call last):
TypeError:
'e' is an invalid keyword argument for this function
TypeError:
f() got an unexpected keyword argument 'e'
>>> g(1,2, c=1, f=2)
>>> g(1,2, c=1, e=0, f=2, d=11)
...
...
tests/run/kwonlyargscall.pyx
View file @
d7764340
...
...
@@ -36,7 +36,7 @@ __doc__ = u"""
TypeError: d() takes exactly 2 positional arguments (3 given)
>>> call2d(d)
Traceback (most recent call last):
TypeError:
'd' is an invalid keyword argument for this function
TypeError:
d() got an unexpected keyword argument 'd'
>>> call0abc(e)
1 2 3 []
...
...
@@ -69,7 +69,7 @@ __doc__ = u"""
TypeError: f() needs keyword-only argument c
>>> call2ce(f)
Traceback (most recent call last):
TypeError:
'e' is an invalid keyword argument for this function
TypeError:
f() got an unexpected keyword argument 'e'
>>> call2cf(g)
1 2 1 42 17 2 []
...
...
@@ -133,7 +133,7 @@ __doc__ = u"""
TypeError: m() needs keyword-only argument c
>>> call2cd(m)
Traceback (most recent call last):
TypeError:
'd' is an invalid keyword argument for this function
TypeError:
m() got an unexpected keyword argument 'd'
"""
# the calls:
...
...
tests/run/starargs.pyx
View file @
d7764340
...
...
@@ -9,7 +9,7 @@ __doc__ = u"""
TypeError: spam() takes exactly 3 positional arguments (4 given)
>>> spam(1,2,3, a=1)
Traceback (most recent call last):
TypeError:
'a' is an invalid keyword argument for this function
TypeError:
spam() got an unexpected keyword argument 'a'
>>> grail(1,2,3)
(1, 2, 3, ())
...
...
@@ -22,7 +22,7 @@ __doc__ = u"""
TypeError: grail() takes at least 3 positional arguments (2 given)
>>> grail(1,2,3, a=1)
Traceback (most recent call last):
TypeError:
'a' is an invalid keyword argument for this function
TypeError:
grail() got an unexpected keyword argument 'a'
>>> swallow(1,2,3)
(1, 2, 3, ())
...
...
@@ -53,10 +53,10 @@ __doc__ = u"""
(1, 2)
>>> onlyt(a=1)
Traceback (most recent call last):
TypeError:
'a' is an invalid keyword argument for this function
TypeError:
onlyt() got an unexpected keyword argument 'a'
>>> onlyt(1, a=2)
Traceback (most recent call last):
TypeError:
'a' is an invalid keyword argument for this function
TypeError:
onlyt() got an unexpected keyword argument 'a'
>>> onlyk(a=1)
(('a', 1),)
...
...
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