From a4a4d4bd0472d6e23cbfb11269da95504fd7b233 Mon Sep 17 00:00:00 2001 From: Akshay Modi Date: Thu, 28 Feb 2019 10:03:03 -0800 Subject: [PATCH] Better error message when non kwargs are provided to raw ops PiperOrigin-RevId: 236142699 --- tensorflow/python/ops/raw_ops_test.py | 2 +- tensorflow/python/util/tf_export.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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(