-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make GARE validation as simple as possible #796
Merged
sirosen
merged 6 commits into
globus:an/add-globus-session-error-support
from
sirosen:spartan-gare
Aug 7, 2023
Merged
Make GARE validation as simple as possible #796
sirosen
merged 6 commits into
globus:an/add-globus-session-error-support
from
sirosen:spartan-gare
Aug 7, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sirosen
requested review from
aaschaer,
ada-globus,
derek-globus and
kurtmckee
as code owners
August 6, 2023 19:40
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
ada-globus
reviewed
Aug 7, 2023
src/globus_sdk/experimental/auth_requirements_error/_serializable.py
Outdated
Show resolved
Hide resolved
…ble.py Co-authored-by: Ada <107940310+ada-globus@users.noreply.github.com>
for more information, see https://pre-commit.ci
ada-globus
reviewed
Aug 7, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make sure this updates the docs to reflect changes to the interfaces? (e.g.,
``GlobusAuthenticationParameters`` classes in an ``extra_fields`` attribute. |
ada-globus
reviewed
Aug 7, 2023
src/globus_sdk/experimental/auth_requirements_error/_validators.py
Outdated
Show resolved
Hide resolved
kurtmckee
reviewed
Aug 7, 2023
src/globus_sdk/experimental/auth_requirements_error/_validators.py
Outdated
Show resolved
Hide resolved
src/globus_sdk/experimental/auth_requirements_error/_validators.py
Outdated
Show resolved
Hide resolved
src/globus_sdk/experimental/auth_requirements_error/_variants.py
Outdated
Show resolved
Hide resolved
ada-globus
reviewed
Aug 7, 2023
src/globus_sdk/experimental/auth_requirements_error/_validators.py
Outdated
Show resolved
Hide resolved
This makes these more uniform.
kurtmckee
approved these changes
Aug 7, 2023
sirosen
merged commit Aug 7, 2023
ab6029e
into
globus:an/add-globus-session-error-support
13 checks passed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changeset completely replaces #795. I'm closing that as I think this is many times superior.
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 dictschecking for non-null values will not accept
session_message
-only GARE data -- at least one of the semantic fields is required by the rewritten checkGlobusAuthRequirementsError does not inherit from
GlobusError
orException
-- it is not clear that this inheritance is useful or instructive to any user, since it mixes Exception hierarchies with data-representing hierarchiesreplace 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 invoketo_dict
down a tree of objectsAlthough 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 shorterto_dict
andfrom_dict
centralization📚 Documentation preview 📚: https://globus-sdk-python--796.org.readthedocs.build/en/796/