Introduce an internal TypeGuard library, globus_sdk._guards #798
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 is a very modest internal improvement, but it does lead to cleaner and clearer internal code which is slightly stricter in certain edge-cases.
Some of the improvements are more obvious than others. For example, here's a usage site which reads more easily now:
Is this shorter / leaner / smaller? Not really.
Limiting ourselves to the
src/
tree,_guards.py
itself is 62 LOC, and we have +110,-68.So if we discount the
_guards.py
module itself, it's marginally shorter. That's not really the point though.This is more of a marginal improvement around the edges to how we do things, especially checking of
list
contents.For example, in the TimerAPIError class, we have these changes:
These are not quite the same.
Because the only tool ready-to-hand before was
isinstance(X, list)
, that was used, and then we had to handle, later, the contents of that list. Putting_guards.is_list_of(X, dict)
in easy reach eliminates that potential point of divergence between various components.In the first 2 commits, I went after the "easy" version of this. It works nicely.
In the second 2 commits, I went after an aspirational goal to make the GARE validators part of a broader suite of behaviors we have within the SDK. They add a bit of complexity (
reduce / _Reducer
), but I think the result is nice.📚 Documentation preview 📚: https://globus-sdk-python--798.org.readthedocs.build/en/798/