Add helpers for deprecating functions, arguments, and values.

Review Request #13012 — Created May 4, 2023 and submitted

chipx86
housekeeping
master
13011
beanbag-misc

This introduces four functions for helping deprecate function-related
code:

  • @deprecate_non_keyword_only_args takes a function with keyword-only
    arguments and allows them to be called with positional arguments while
    emitting a deprecation warning. This is a port of the code used in
    RBTools and Djblets today.

  • @func_deprecated takes a function and emits a deprecation warning
    when called.

  • @func_moved takes a function and emits a deprecation warning
    when called, pointing to a new function elsewhere.

  • deprecated_arg_value wraps a value and emits a deprecation warning
    if it's used in any way. It's useful for passing old arguments to
    callbacks. This is a port of the code used in Djblets today.

Unit tests have been added for all of these functions.

All unit tests pass for all supported versions of Python.

Viewed the README in a GitHub-compatible Markdown viewer.

Summary
Add helpers for deprecating functions, arguments, and values.
Description From Last Updated

'warnings' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

'typing.Type' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

line too long (80 > 79 characters) Column: 80 Error code: E501

reviewbotreviewbot

'typing.Optional' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

'housekeeping.base.DEFAULT_STACK_LEVEL' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

'inspect' imported but unused Column: 1 Error code: F401

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
chipx86
Review request changed

Change Summary:

  • Added a helper for standardizing formatting of class and function names.
  • Fixed decorators to preserve state like names and docs.
  • Removed the func_moved() assignment form from docs, since we can't get the name.
  • Standardized some function arguments.
  • Added stack level arguments to everything, adjusting it for the internal functions to ensure proper stack levels.
  • Added testing of stack levels as a standard part of all warning checks.

Commits:

Summary
-
Add helpers for deprecating functions, arguments, and values.
+
Add helpers for deprecating functions, arguments, and values.

Diff:

Revision 3 (+2786)

Show changes

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to master (f1e1b7f), master (1b18522)
Loading...