Better error message when non kwargs are provided to raw ops
PiperOrigin-RevId: 236142699
This commit is contained in:
parent
fb31b9fde4
commit
a4a4d4bd04
@ -30,7 +30,7 @@ class RawOpsTest(test.TestCase):
|
||||
|
||||
def testSimple(self):
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
with self.assertRaisesRegexp(TypeError, "only takes keyword args"):
|
||||
_ = gen_math_ops.Add(1., 1.)
|
||||
|
||||
x = constant_op.constant(1)
|
||||
|
@ -382,7 +382,13 @@ class api_export(object): # pylint: disable=invalid-name
|
||||
|
||||
def kwarg_only(f):
|
||||
"""A wrapper that throws away all non-kwarg arguments."""
|
||||
def wrapper(**kwargs):
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
if args:
|
||||
raise TypeError(
|
||||
'{} only takes keyword args. The following args were provided: {}. '
|
||||
'Please pass these args as kwargs instead.'
|
||||
.format(f.__name__, args))
|
||||
return f(**kwargs)
|
||||
|
||||
return tf_decorator.make_decorator(
|
||||
|
Loading…
Reference in New Issue
Block a user