• 
      

    Add a decorator for migrating to functions with keyword-only arguments.

    Review Request #12555 — Created Aug. 19, 2022 and submitted

    Information

    RBTools
    release-4.x

    Reviewers

    The RBTools codebase is old, and we have a lot of code that doesn't
    quite follow best practices. These include functions that take a whole
    lot of keyword arguments, but with calls passing values as positional
    arguments instead.

    Python 3 allows us to define keyword-only arguments, which can help us
    clean things up, but as we aim to provide backwards-compatibility during
    deprecation phases, we can't just simply use them.

    This change introduces a decorator to help with this.

    rbtools.deprecation.deprecate_non_keyword_only_args() can be used for
    any function taking keyword-only arguments. Any call that supplies such
    an argument via a positional argument value will trigger a deprecation
    warning. The arguments will then be rewritten to pass those in as
    keyword arguments.

    We'll want this pattern for other codebases in time. Unfortunately, no
    other packages we depend on provide a decorator like this, so we'll need
    to maintain it ourselves. (Packages like debtcollector do not provide
    anything for this.). For now, it will remain in RBTools.

    Decorated some functions and tested calls with and without using
    keyword arguments for the values. Verified the warnings only appeared
    when passing values as positional arguments.

    Verified that the warning's stack trace had the right stack level,
    showing the call to the function.

    Unit tests pass on Python 3.7-3.11.

    Summary ID
    Add a decorator for migrating to functions with keyword-only arguments.
    The RBTools codebase is old, and we have a lot of code that doesn't quite follow best practices. These include functions that take a whole lot of keyword arguments, but with calls passing as positional arguments instead. Python 3 allows us to define keyword-only arguments, which can help us clean things up, but as we aim to provide backwards-compatibility during deprecation phases, we can't just simply use them. This change introduces a decorator to help with this. `rbtools.deprecation.deprecate_non_keyword_only_args()` can be used for any function taking keyword-only arguments. Any call that supplies such an argument via a positional argument value will trigger a deprecation warning. The arguments will then be rewritten to pass those in as keyword arguments. We'll want this pattern for other codebases in time. Unfortunately, no other packages we depend on provide a decorator like this, so we'll need to maintain it ourselves. (Packages like `debtcollector` do not provide anything for this.)
    533994de031c53efcde528b5b5777c26534cc62f
    Description From Last Updated

    'itertools.islice' imported but unused Column: 1 Error code: F401

    reviewbotreviewbot

    'typing_extensions.Concatenate' imported but unused Column: 1 Error code: F401

    reviewbotreviewbot

    'typing_extensions.ParamSpecArgs' imported but unused Column: 1 Error code: F401

    reviewbotreviewbot

    'typing_extensions.ParamSpec' imported but unused Column: 1 Error code: F401

    reviewbotreviewbot

    'typing_extensions.ParamSpecKwargs' imported but unused Column: 1 Error code: F401

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

    flake8

    chipx86
    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-4.x (88f0504)