• 
      

    Add typing and correct errors in the authentication backends.

    Review Request #13143 — Created July 13, 2023 and submitted

    Information

    Review Board
    release-6.x

    Reviewers

    This change adds typing information for the authentication backends, in
    preparation for upcoming work. It codifies the types and arguments
    required for any overridden functions, helping to ensure consistent type
    signatures for any subclasses.

    In the process, some issues were found with the implementations:

    1. BaseAuthBackend.authenticate() doesn't require any specific
      credentials, but subclasses do. Those parameters were not made
      optional in the subclasses, and that could lead to crashes calling
      authenticate() with wrong credentials. Now they're optional, and
      error information is logged instead.

    2. We were very inconsistent on whether HttpRequest objects were
      optional or defaulted to None. We now follow Django's lead on most
      of these.

    3. Some code assumed the existence of cetain modules or state that could
      have theoretically been None. We now assert these, helping the type
      checkers.

    Some minor code was rewritten to be more type-safe in the process, and
    some legacy code was modernized for Python 3.

    Unit tests pass.

    Summary ID
    Add typing and correct errors in the authentication backends.
    This change adds typing information for the authentication backends, in preparation for upcoming work. It codifies the types and arguments required for any overridden functions, helping to ensure consistent type signatures for any subclasses. In the process, some issues were found with the implementations: 1. `BaseAuthBackend.authenticate()` doesn't require any specific credentials, but subclasses do. Those parameters were not made optional in the subclasses, and that could lead to crashes calling `authenticate()` with wrong credentials. Now they're optional, and error information is logged instead. 2. We were very inconsistent on whether `HttpRequest` objects were optional or defaulted to `None`. We now follow Django's lead on most of these. 3. Some code assumed the existence of cetain modules or state that could have theoretically been `None`. We now assert these, helping the type checkers. Some minor code was rewritten to be more type-safe in the process, and some legacy code was modernized for Python 3.
    578445f4385db92a6a81d5121836ffe88d53c8c8
    Description From Last Updated

    'typing_extensions.Literal' 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-6.x (079f2a6)