From 9b15aaf55d313de7aeffcb813b5cbc33c7196310 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Wed, 1 Jul 2020 02:49:28 -0400
Subject: [PATCH] Don't duplicate deprecated parameter addendum.

Since `kwargs` is from the outer scope, adding to it will persist for
every time the deprecated wrapper function is called. Instead, save
the original `addendum` in the outer scope, and don't modify the outer
variables in the inner wrapper function.
---
 lib/matplotlib/cbook/deprecation.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/matplotlib/cbook/deprecation.py b/lib/matplotlib/cbook/deprecation.py
index 955d7c3d9e3c..d84709fb9373 100644
--- a/lib/matplotlib/cbook/deprecation.py
+++ b/lib/matplotlib/cbook/deprecation.py
@@ -379,6 +379,8 @@ def func(used_arg, other_arg, unused, more_args): ...
             f"Matplotlib internal error: {name!r} must be a parameter for "
             f"{func.__name__}()")
 
+    addendum = kwargs.pop('addendum', None)
+
     @functools.wraps(func)
     def wrapper(*inner_args, **inner_kwargs):
         arguments = signature.bind(*inner_args, **inner_kwargs).arguments
@@ -396,16 +398,15 @@ def wrapper(*inner_args, **inner_kwargs):
         # wrappers always pass all arguments explicitly.
         elif any(name in d and d[name] != _deprecated_parameter
                  for d in [arguments, arguments.get(kwargs_name, {})]):
-            addendum = (f"If any parameter follows {name!r}, they should be "
-                        f"passed as keyword, not positionally.")
-            if kwargs.get("addendum"):
-                kwargs["addendum"] += " " + addendum
-            else:
-                kwargs["addendum"] = addendum
+            deprecation_addendum = (
+                f"If any parameter follows {name!r}, they should be passed as "
+                f"keyword, not positionally.")
             warn_deprecated(
                 since,
                 name=repr(name),
                 obj_type=f"parameter of {func.__name__}()",
+                addendum=(addendum + " " + deprecation_addendum) if addendum
+                         else deprecation_addendum,
                 **kwargs)
         return func(*inner_args, **inner_kwargs)