From 8d0fde19612e5e3502947a324cdf102664685e7d Mon Sep 17 00:00:00 2001 From: Gabriel Busnot Date: Thu, 19 Jan 2023 11:08:51 +0000 Subject: [PATCH] python: Fix deprecated decorator The deprecation message was firing during the decoration process instead of firing upon first call to deprecated function. The message now fires only if the deprected function is called. Change-Id: I2d510eb24884fdba0123e71e8472db68ae9d2ce4 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67334 Maintainer: Jason Lowe-Power Reviewed-by: Jason Lowe-Power Reviewed-by: Daniel Carvalho Tested-by: kokoro Reviewed-by: Richard Cooper --- src/python/m5/util/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/python/m5/util/__init__.py b/src/python/m5/util/__init__.py index bc4ab4a0f5..5ae48754ab 100644 --- a/src/python/m5/util/__init__.py +++ b/src/python/m5/util/__init__.py @@ -108,8 +108,12 @@ def deprecated(replacement=None, logger=warn): message += f" Prefer {replacement} instead." logger(message) - notifyDeprecation() - return func + @wraps(func) + def wrapper(*args, **kwargs): + notifyDeprecation() + return func(*args, **kwargs) + + return wrapper return decorator