Add utility modules for common types and symbols.
Review Request #13111 — Created June 16, 2023 and submitted
The new
djblets.util.typing
module includes some standard types for
JSON data, keyword argument dictionaries, and safe aliases for
django-stubsStrOrPromise
implementations.The new JSON types are enhanced versions of our old ones. Modern
versions of mypy and pyright offer recursive type checks, meaning we can
now have deep JSON structures that still type correctly.The
StrOrPromise
/StrPromise
types alias the ones indjango-stubs
when type checking, and otherwise fall back to an approximation. This
mostly mirrors what thedjango_stubs_ext
module gives us (which they
recommend for type checks), but then we'd have to depend on that at
runtime. Plus, this a bit of a better/more correctly typed
implementation.The new
djblets.util.symbols
module gives us common symbols we can use
elsewhere. For now, this provides anUNSET
symbol, useful as default
arguments for other functions where it's important to differentiate from
unset andNone
.Other modules have been updated to use some of these where appropriate.
Not all of this is currently in use within Djblets, but future changes
will build off of these.
Unit tests pass for all supported versions of Python.
Made use of these in some upcoming changes.
Built some test code to ensure that the types were being interpreted
correctly, in particular the recursive JSON typing.
Summary | ID |
---|---|
a85e2c61145afb5135ae3f43dd33da5df1d45e16 |