• 
      

    Move all function introspection/argument generation into new classes.

    Review Request #10920 — Created Feb. 26, 2020 and submitted

    Information

    kgb
    master

    Reviewers

    kgb

    As FunctionSpy got more complicated and continued to add compatibility
    with newer versions of Python, the code got increasingly complex and
    littered with Python version checks. This could make it more challenging
    to reason about some parts of code.

    To address this, this change introduces a new set of FunctionSig
    classes, which consist of BaseFunctionSig, FunctionSigPy2, and
    FunctionSigPy3.

    These are responsible for taking a function and storing information on
    the function type, owner, and arguments. It's also responsible for
    generating code for a function's argument signature or for referencing a
    variable defined in a spy-generated function, for the purposes of
    generating those functions.

    The Py2 and Py3 versions of these classes implement the logic for
    Python 2 and Python 3, respectively. There's some common logic in the
    base class, but the bulk are in these. They also contain constants used
    for function attribute states, which used to be defined per-version in
    spies.py.

    A FunctionSig alias exists that points to the appropriate class for
    the current version of Python.

    FunctionSpy generates an instance of this for the provided function
    up-front, and uses it to figure out the owner and other information. It
    ditches the argspec-related methods in favor of calls to this. It also
    provides some property wrappers for attributes on the signature, for
    compatibility purposes.

    Version checks are still required in FunctionSpy for many purposes,
    such as when filling out attributes for a CodeType or FunctionType,
    but a lot of the complexities are now isolated to the FunctionSigs.

    This should help keep the codebase more maintainable and future-proof as
    we go on.

    Unit tests pass on Python 2.7 and 3.5-3.8.

    Ran Djblets and Review Board unit test suites with these Python
    versions to make sure nothing broke in real-world usage.

    Summary ID
    Move all function introspection/argument generation into new classes.
    As `FunctionSpy` got more complicated and continued to add compatibility with newer versions of Python, the code got increasingly complex and littered with Python version checks. This could make it more challenging to reason about some parts of code. To address this, this change introduces a new set of `FunctionSig` classes, which consist of `BaseFunctionSig`, `FunctionSigPy2`, and `FunctionSigPy3`. These are responsible for taking a function and storing information on the function type, owner, and arguments. It's also responsible for generating code for a function's argument signature or for referencing a variable defined in a spy-generated function, for the purposes of generating those functions. The `Py2` and `Py3` versions of these classes implement the logic for Python 2 and Python 3, respectively. There's some common logic in the base class, but the bulk are in these. They also contain constants used for function attribute states, which used to be defined per-version in `spies.py`. A `FunctionSig` alias exists that points to the appropriate class for the current version of Python. `FunctionSpy` generates an instance of this for the provided function up-front, and uses it to figure out the owner and other information. It ditches the argspec-related methods in favor of calls to this. It also provides some property wrappers for attributes on the signature, for compatibility purposes. Version checks are still required in `FunctionSpy` for many purposes, such as when filling out attributes for a `CodeType` or `FunctionType`, but a lot of the complexities are now isolated to the `FunctionSig`s. This should help keep the codebase more maintainable and future-proof as we go on.
    e3f3f5ea5c02167d15d12f8ccf4ec795881aaa84
    Description From Last Updated

    E127 continuation line over-indented for visual indent

    reviewbotreviewbot

    E127 continuation line over-indented for visual indent

    reviewbotreviewbot

    E127 continuation line over-indented for visual indent

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

    flake8

    chipx86
    david
    1. Nice cleanup!

    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to master (d5de4e1)