@@ -205,11 +205,23 @@ def __repr__(cls):
205205
206206
207207class DEPRECATED (metaclass = PatchClassRepr ):
208- """Signal value to help with deprecating parameters that use None .
208+ """Signal that a deprecated parameter has not been set .
209209
210- This is a proxy object, used to signal that a parameter has not been set.
211210 This is useful if ``None`` is already used for a different purpose or just
212211 to highlight a deprecated parameter in the signature.
212+
213+ This is a sentinel and not meant to be initialized.
214+ """
215+
216+
217+ class DEPRECATED_GOT_VALUE (metaclass = PatchClassRepr ):
218+ """Signal that a value was passed to a deprecated parameter.
219+
220+ Used by :class:`deprecate_parameter` to replace values that were passed to
221+ deprecated parameters. This allows further handling of the deprecated case
222+ inside the decorated function.
223+
224+ This is a sentinel and not meant to be initialized.
213225 """
214226
215227
@@ -228,9 +240,13 @@ class deprecate_parameter:
228240 template : str, optional
229241 If given, this message template is used instead of the default one.
230242 new_name : str, optional
231- If given, the default message will recommend the new parameter name and an
232- error will be raised if the user uses both old and new names for the
233- same parameter.
243+ The name of a new parameter replacing the deprecated one. If given:
244+ - The default message will recommend the new parameter name.
245+ - Values passed to `deprecated_name` are replaced with
246+ :class:`DEPRECATED_GOT_VALUE`, and the replaced value is passed to
247+ `new_name` instead.
248+ - An error will be raised if the user uses both `deprecated_name` and
249+ `new_name`.
234250 modify_docstring : bool, optional
235251 If the wrapped function has a docstring, add the deprecated parameters
236252 to the "Other Parameters" section.
@@ -267,6 +283,7 @@ class deprecate_parameter:
267283 """
268284
269285 DEPRECATED = DEPRECATED # Make signal value accessible for convenience
286+ DEPRECATED_GOT_VALUE = DEPRECATED_GOT_VALUE
270287
271288 remove_parameter_template = (
272289 "Parameter `{deprecated_name}` is deprecated since version "
@@ -341,21 +358,20 @@ def fixed_func(*args, **kwargs):
341358 deprecated_value = DEPRECATED
342359 new_value = DEPRECATED
343360
344- # Extract value of deprecated parameter
361+ # Extract value of deprecated parameter and overwrite with
362+ # DEPRECATED_GOT_VALUE if replacement exists
345363 if len (args ) > deprecated_idx :
346364 deprecated_value = args [deprecated_idx ]
347- # Overwrite old with DEPRECATED if replacement exists
348365 if self .new_name is not None :
349366 args = (
350367 args [:deprecated_idx ]
351- + (DEPRECATED ,)
368+ + (DEPRECATED_GOT_VALUE ,)
352369 + args [deprecated_idx + 1 :]
353370 )
354371 if self .deprecated_name in kwargs .keys ():
355372 deprecated_value = kwargs [self .deprecated_name ]
356- # Overwrite old with DEPRECATED if replacement exists
357373 if self .new_name is not None :
358- kwargs [self .deprecated_name ] = DEPRECATED
374+ kwargs [self .deprecated_name ] = DEPRECATED_GOT_VALUE
359375
360376 # Extract value of new parameter (if present)
361377 if new_idx is not False and len (args ) > new_idx :
0 commit comments