Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make GARE validation as simple as possible
Rather than trying to build a framework, this is the "no framework" solution, in which we define very concrete helpers for very concrete purposes, including a dedicated one for the "ConsentRequired" Literal. All of the GARE classes now inherit from an internal helper class, Serializable, which defines from_dict, to_dict, and _supported_fields in a generic way. The last of these *does* use some signature inspection magic, but nothing too abstruse. The basic transformation is to replace each combination of a class-level annotation + a `SUPPORTED_FIELDS` entry with relevant assignment in `__init__`. Some tangentially related simplifications and minor improvements are included: - `extra_fields -> extra` - Removal of unnecessary str splitting (after object is initialized) - `isinstance` checking can also handle deserialization of dicts - checking for non-null values will not accept `session_message`-only GARE data -- at least one of the semantic fields is required by the rewritten check - GlobusAuthRequirementsError does not inherit from `GlobusError` or `Exception` -- it is not clear that this inheritance is useful or instructive to any user, since it mixes Exception hierarchies with data-representing hierarchies - replace direct `ValueError` usage with a custom ValidationError class -- this avoids any messy scenarios in which a ValueError is accidentally introduced and incorrectly caught (e.g. from a stdlib call) There are also some more significant improvements included. Most notably: - Annotations explicitly do not accept `None` unless it is a valid value (i.e. annotations align with validation requirements) - to_dict can now look for a concrete type (`Serializable`) and therefore can automatically invoke `to_dict` down a tree of objects Although brevity is a non-goal of this changeset -- more verbose but clearer would be acceptable -- the result is almost 200 LOC lighter in the `src/` tree. The primary ways in which things became shorter appear to be: - explicit version is often much shorter than the framework-ized version (e.g. `LegacyConsentRequiredAPError`), and even where the two are close, the explicit version is shorter - `to_dict` and `from_dict` centralization
- Loading branch information