Add type hints for webapi auth backends, and fix minor issues.

Review Request #12725 — Created Nov. 15, 2022 and submitted

Information

Djblets
release-3.x

Reviewers

This adds type hints throughout djblets.webapi.auth.backends. Return
types are now properly standardized and documented, as are credential
arguments. This will give us a path forward if we want to enhance these,
and aids in implementing backends in consuming codebases.

Token authentication, which uses both a webapi auth backend and a Django
auth backend with a validate_token() method, now has that relationship
clearly defined through use of Protocols, a typing feature to help with
duck typing. It also skips calling this method if there's no token to
validate, which can avoid problems in backends.

Some places where we were directly setting, deleting, or retrieving
custom Django-namespaced properties now uses setattr(), getattr(),
and delattr(), to avoid attribute errors during type checks.

All unit tests pass in all supported versions of Python.

Summary ID
Add type hints for webapi auth backends, and fix minor issues.
This adds type hints throughout `djblets.webapi.auth.backends`. Return types are now properly standardized and documented, as are credential arguments. This will give us a path forward if we want to enhance these, and aids in implementing backends in consuming codebases. Token authentication, which uses both a webapi auth backend and a Django auth backend with a `validate_token()` method, now has that relationship clearly defined through use of Protocols, a typing feature to help with duck typing. Some places where we were directly setting, deleting, or retrieving custom Django-namespaced properties now uses `setattr(`, `getattr(`, and `delattr()`, to avoid attribute errors during type checks.
53f016bd32152d8cdd175a0982e2552dcb2c1ac8
Description From Last Updated

'typing.TYPE_CHECKING' imported but unused Column: 1 Error code: F401

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

flake8

david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-3.x (b592895)
Loading...