Better error message when non kwargs are provided to raw ops

PiperOrigin-RevId: 236142699
This commit is contained in:
Akshay Modi 2019-02-28 10:03:03 -08:00 committed by TensorFlower Gardener
parent fb31b9fde4
commit a4a4d4bd04
2 changed files with 8 additions and 2 deletions

View File

@ -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)

View File

@ -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(