Add utility modules for common types and symbols.

Review Request #13111 — Created June 16, 2023 and submitted

Information

Djblets
release-3.x

Reviewers

The new djblets.util.typing module includes some standard types for
JSON data, keyword argument dictionaries, and safe aliases for
django-stubs StrOrPromise 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 in django-stubs
when type checking, and otherwise fall back to an approximation. This
mostly mirrors what the django_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 an UNSET symbol, useful as default
arguments for other functions where it's important to differentiate from
unset and None.

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
Add utility modules for common types and symbols.
The new `djblets.util.typing` module includes some standard types for JSON data, keyword argument dictionaries, and safe aliases for django-stubs `StrOrPromise` 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 in `django-stubs` when type checking, and otherwise fall back to an approximation. This mostly mirrors what the `django_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 an `UNSET` symbol, useful as default arguments for other functions where it's important to differentiate from unset and `None`. 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.
a85e2c61145afb5135ae3f43dd33da5df1d45e16
chipx86
maubin
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-3.x (43e5f52)