Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify GlobusAuthRequiremenetsError validation #795

Commits on Aug 4, 2023

  1. Begin converting GARE to annotated validators

    This is an experimental change to an experimental subpackage.
    Rather than explicitly enumerating types 3x between
    - class declaration
    - SUPPORTED_FIELDS dict
    - init declaration
    
    and then auto-lifting `locals()` values into assignments, take a
    slightly different tack of enumerating the types twice
    - class declaration with Annotated
    - init declaration
    
    And then manually assigning fields (pylint will keep us honest about
    missing parameters).
    
    A new set of validator helpers cover our needs in terms of picking up
    and using the validators.
    sirosen committed Aug 4, 2023
    Configuration menu
    Copy the full SHA
    5fb4733 View commit details
    Browse the repository at this point in the history
  2. GARE validators support a 'DEFAULT' rule

    If a 'DEFAULT' sentinel value is seen in the Annotated data, then the
    type from the annotation can be mapped to a known validator. Bake this
    logic into the validators.
    sirosen committed Aug 4, 2023
    Configuration menu
    Copy the full SHA
    2ba3166 View commit details
    Browse the repository at this point in the history
  3. Refactor GARE validators to protocol system

    Declare a well-typed protocol for validators, which defines the
    `__call__` method to take a name (for the field) and a value to
    validate.
    
    Each field validation is now done with an explicit call to a
    validator, and without any derivation of validators, types, or
    meta-programming.
    
    The tow remaining items which needed special handling were:
    - checking for non-null values being passed for at least one argument
    - loading a data object from a dict filtering out extra params
    
    In these two cases, the desired arg names are found by examining
    `__init__` and excluding `self` and `extra`, each of which has special
    meaning.
    
    In general, the paradigm shift offered here is to be more direct and
    explicit, even if the requirement is that we are verbose in the
    process. Partly, this was based on the realization that many of the
    meta-programming techniques being used were not resulting in the
    desired level of brevity and clarity.
    sirosen committed Aug 4, 2023
    Configuration menu
    Copy the full SHA
    4b9585b View commit details
    Browse the repository at this point in the history
  4. Revert '--keep-runtime-typing' from prior impl

    An aborted implementation of annotation-based validators required that
    we preserve runtime typing. That constraint is gone, meaning we don't
    need the relevant flag for pre-commit.
    sirosen committed Aug 4, 2023
    Configuration menu
    Copy the full SHA
    d69a86f View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    7ffbd01 View commit details
    Browse the repository at this point in the history
  6. Remove runtime use of signature inspection

    Relegate the strategy of looking at `__init__` signatures to the
    testsuite. Rather than doing this at runtime, reintroduce
    `SUPPORTED_FIELDS` as a property of GARE-related classes, but as a set
    of strings.
    
    The testsuite now checks the set against `__init__` for the relevant
    class.
    The result is more verbose but simpler.
    sirosen committed Aug 4, 2023
    Configuration menu
    Copy the full SHA
    768922f View commit details
    Browse the repository at this point in the history

Commits on Aug 5, 2023

  1. Carefully apply inspect to GARE validators

    - Deriving a value from the `locals()` of a parent frame saves us some
      redundancy and is safe so long as the relevant helper remains purely
      internal
    - Inspecting an `__init__` signature is simple and easy if it is done
      in the class declaration context when `__init__` is "just a
      function" and not yet bound to the class. No complex derivation of
      the `__init__` function is therefore needed
    
    In order for this to work, `HasSupportedFields` needs to become an
    explicit Protocol, or mypy incorrectly fails some of the variants.
    sirosen committed Aug 5, 2023
    Configuration menu
    Copy the full SHA
    d3ef171 View commit details
    Browse the repository at this point in the history