diff --git a/tensorflow/python/ops/raw_ops_test.py b/tensorflow/python/ops/raw_ops_test.py index 82ea137354e..6e47802145b 100644 --- a/tensorflow/python/ops/raw_ops_test.py +++ b/tensorflow/python/ops/raw_ops_test.py @@ -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) diff --git a/tensorflow/python/util/tf_export.py b/tensorflow/python/util/tf_export.py index ff87f97dd46..f9ab5dd5c99 100644 --- a/tensorflow/python/util/tf_export.py +++ b/tensorflow/python/util/tf_export.py @@ -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(