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:
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:
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)
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;
}
"""]
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;
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
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)
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)
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)
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)
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, ())
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, ())
(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),)
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)
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)
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 []
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 []
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:
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, ())
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, ())
(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),)