Add typing and new features to registries.
Review Request #12701 — Created Oct. 28, 2022 and submitted
Registries are a core part of the extensibility in Djblets and in
Review Board, and perform registration management and fetching for
specific types of items.
To aid in type safety, this change adds typing to
Registryitself is now a
Generic, allowing a subclass to specify
exactly what type of item is being stored. This then enables type safety
within the registry and for callers registering, fetching, or iterating
This unveiled an issue where
especially well with Python typing, as it overrides the
method to use
Optional[T]for the result. Type checkers don't like it
when the function signature gets replaced when mixing in or subclassing,
since it's perceived to violate the contract of the function and produce
a type-unsafe result.
We've worked around that here, but we have had situations in the past
where we've incorrectly called
invalid items when
ItemLookupErrorwould be raised instead, and
To address these issues, a new
Registry.get_or_none()method has been
added, which works like the mixin's
get()method. Callers can move
over to that, and
get()can be made deprecated by subclasses. In time,
we'll probably want to deprecate
but that probably won't happen until Djblets 4 at the earliest.
Some unit tests have also been fixed. We had some bad asserts
assertEqual()), some type-unsafe checks,
and just some very old assertions that needed updating. The tests also
now largely test typed registries.
All unit tests passed.
Verified there are no typing warnings/errors within
pyright), aside from untyped modules being imported.
Built the docs and checked for errors.
Fixed a typo in a docstring.
Revision 2 (+692 -234)
Checks run (2 succeeded)