MCPcopy Index your code
hub / github.com/saltstack/salt / kwargs_warn_until

Function kwargs_warn_until

salt/utils/versions.py:278–346  ·  view source on GitHub ↗

Helper function to raise a warning (by default, a ``DeprecationWarning``) when unhandled keyword arguments are passed to function, until the provided ``version_info``, after which, a ``RuntimeError`` will be raised to remind the developers to remove the ``**kwargs`` because the targ

(
    kwargs,
    version,
    category=DeprecationWarning,
    stacklevel=None,
    _version_info_=None,
    _dont_call_warnings=False,
)

Source from the content-addressed store, hash-verified

276
277
278def kwargs_warn_until(
279 kwargs,
280 version,
281 category=DeprecationWarning,
282 stacklevel=None,
283 _version_info_=None,
284 _dont_call_warnings=False,
285):
286 """
287 Helper function to raise a warning (by default, a ``DeprecationWarning``)
288 when unhandled keyword arguments are passed to function, until the
289 provided ``version_info``, after which, a ``RuntimeError`` will be raised
290 to remind the developers to remove the ``**kwargs`` because the target
291 version has been reached.
292 This function is used to help deprecate unused legacy ``**kwargs`` that
293 were added to function parameters lists to preserve backwards compatibility
294 when removing a parameter. See
295 :ref:`the deprecation development docs <deprecations>`
296 for the modern strategy for deprecating a function parameter.
297
298 :param kwargs: The caller&#x27;s ``**kwargs`` argument value (a ``dict``).
299 :param version: The version info or name after which the warning becomes a
300 ``RuntimeError``. For example ``(0, 17)`` or ``Hydrogen``
301 or an instance of :class:`salt.version.SaltStackVersion`.
302 :param category: The warning class to be thrown, by default
303 ``DeprecationWarning``
304 :param stacklevel: There should be no need to set the value of
305 ``stacklevel``. Salt should be able to do the right thing.
306 :param _version_info_: In order to reuse this function for other SaltStack
307 projects, they need to be able to provide the
308 version info to compare to.
309 :param _dont_call_warnings: This parameter is used just to get the
310 functionality until the actual error is to be
311 issued. When we&#x27;re only after the salt version
312 checks to raise a ``RuntimeError``.
313 """
314 if not isinstance(version, (tuple, str, salt.version.SaltStackVersion)):
315 raise RuntimeError(
316 "The 'version' argument should be passed as a tuple, string or "
317 "an instance of 'salt.version.SaltStackVersion'."
318 )
319 elif isinstance(version, tuple):
320 version = salt.version.SaltStackVersion(*version)
321 elif isinstance(version, str):
322 version = salt.version.SaltStackVersion.from_name(version)
323
324 if stacklevel is None:
325 # Attribute the warning to the calling function,
326 # not to kwargs_warn_until() or warn_until()
327 stacklevel = 3
328
329 if _version_info_ is None:
330 _version_info_ = salt.version.__version_info__
331
332 _version_ = salt.version.SaltStackVersion(*_version_info_)
333
334 if kwargs or _version_.info >= version.info:
335 arg_names = ", ".join(f"'{key}'" for key in kwargs)

Callers

nothing calls this directly

Calls 3

warn_untilFunction · 0.85
formatMethod · 0.80
from_nameMethod · 0.45

Tested by

no test coverage detected