You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When setting the action="once" option, the deprecation warning should only be logged once.
fromdeprecatedimportdeprecated@deprecated(action='once')defmy_func():
print("running the old func")
if__name__=="__main__":
my_func()
my_func()
my_func()
Actual Behavior
The deprecation warning is displayed every time the function is called:
DeprecationWarning: Call to deprecated function (or staticmethod) my_func.
my_func()
DeprecationWarning: Call to deprecated function (or staticmethod) my_func.
my_func()
DeprecationWarning: Call to deprecated function (or staticmethod) my_func.
my_func()
running the old func
running the old func
running the old func
Environment
Python version: 3.10.6
Deprecated version: 1.2.13
The text was updated successfully, but these errors were encountered:
I agree, it's a problem, but not unique to the Deprecated library.
The "action" parameter is used with the warnings.filterwarnings() function to define the behavior of warnings in a specific part of the Python code.
The value "once" indicates that the warning should only be reported the first time it is encountered. After that, the warning will no longer be signaled even if it occurs again later.
When specifying the action at the deprecated function level, we use a context manager that allows the warning behavior to be modified locally to the function and thus restored at the end of the function call. This is required so as not to modify the application's global context. Indeed, in the case of "once", this has the effect of restoring the internal call counter, so a warning message is issued each time.
One way around this problem is not to specify the parameter at all, as "once" is the default value.
Expected Behavior
When setting the
action="once"
option, the deprecation warning should only be logged once.Actual Behavior
The deprecation warning is displayed every time the function is called:
Environment
The text was updated successfully, but these errors were encountered: