Modernize BaseProperty, AliasProperty, and TypedProperty and add typing.
Review Request #13062 — Created May 24, 2023 and submitted
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:
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.
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
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:
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
Most arguments to these properties are now keyword-only arguments.
The old behavior/methods are now deprecated, scheduled to be removed in
Unit tests pass.
Made use of this with some upcoming changes in Review Board for better type