Add helpers for deprecating functions, arguments, and values.

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

Information

housekeeping
master

Reviewers

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 ID
Add helpers for deprecating functions, arguments, and values.
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.
e963855fc79344c4b4a5bde4b8c5ef6f329e3ad2
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 ID
Add helpers for deprecating functions, arguments, and values.
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.
962609d504dc80dfe7776a5ee78309c8e71b1280
Add helpers for deprecating functions, arguments, and values.
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.
e963855fc79344c4b4a5bde4b8c5ef6f329e3ad2

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to master (f1e1b7f), master (1b18522)