Modernize BaseProperty, AliasProperty, and TypedProperty and add typing.

Review Request #13062 — Created May 24, 2023 and updated


Djblets provides a few useful property classes for marshalling data or
ensuring strict typing at runtime. These have been updated to support
type hints, in order to help developers provide the right typing
information when working with these classes.

There are a couple caveats in the implementation:

  1. Due to the current lack of widespread support for PEP 696 (Type
    defaults for TypeVarLikes), we can't add any defaults for any of the
    types, meaning that get/set types must be specified.

  2. Pyright and MyPy behave differently when it comes to determining the
    correct type during assignment. MyPy implicitly uses the type of the
    assignment, while Pyright will happily allow other assignments to
    override that type. This means that conusmers need to explicitly type
    the descriptors.

Examples are now present in the docs to help define these correctly.
Best practices here will evolve after PEP 696 is landed, and hopefully
once Pyright and MyPy come closer on implementations.

Some other modernization is present:

  1. Properties now define a __set_name__() in order to know their attribute
    name, rather than having to scan for it. This is safer and faster than the
    old method.

  2. Most arguments to these properties are now keyword-only arguments.

The old behavior/methods are now deprecated, scheduled to be removed in
Djblets 5.0.

Unit tests pass.

Made use of this with some upcoming changes in Review Board for better type

Modernize BaseProperty, AliasProperty, and TypedProperty and add typing.
Checks run (2 succeeded)
flake8 passed.
JSHint passed.
  1. Ship It!