-
Notifications
You must be signed in to change notification settings - Fork 38
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
Introduce the MISSING sentinel and use it for HA timeout on GroupPolicies #885
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
de90985
Introduce the MISSING singleton
sirosen 53009d9
Default to MISSING for GroupPolicies ha timeout
sirosen b1e9f58
Automatically strip MISSING from payloads
sirosen 6ada04d
Minor non-functional changes per review
sirosen 0c28615
Add support for `MISSING` in params and headers
sirosen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
changelog.d/20231025_122826_sirosen_introduce_missingtype.rst
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Added | ||
~~~~~ | ||
|
||
- A new sentinel value, ``globus_sdk.MISSING``, has been introduced. | ||
It is used for method calls which need to distinguish missing parameters from | ||
an explicit ``None`` used to signify ``null`` (:pr:`NUMBER`) | ||
|
||
- ``globus_sdk.MISSING`` is now supported in payload data for all methods, and | ||
will be automatically removed from the payload before sending to the server |
5 changes: 5 additions & 0 deletions
5
changelog.d/20231025_125551_sirosen_introduce_missingtype.rst
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Changed | ||
~~~~~~~ | ||
|
||
- ``GroupPolicies`` objects now treat an explicit instantiation with | ||
``high_assurance_timeout=None`` as setting the timeout to ``null`` (:pr:`NUMBER`) |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import pytest | ||
|
||
from globus_sdk import utils | ||
|
||
|
||
def test_payload_preparation_strips_missing_dict(): | ||
original = {"foo": None, "bar": utils.MISSING} | ||
prepared = utils.PayloadWrapper._prepare(original) | ||
assert prepared == {"foo": None} | ||
|
||
|
||
# this is a weird case (not really recommended usage), but we have well defined behavior | ||
# for it, so exercise it here | ||
@pytest.mark.parametrize("type_", (list, tuple)) | ||
def test_payload_preparation_strips_missing_list_or_tuple(type_): | ||
original = type_([None, 1, utils.MISSING, 0]) | ||
prepared = utils.PayloadWrapper._prepare(original) | ||
assert prepared == [None, 1, 0] | ||
|
||
|
||
@pytest.mark.parametrize("original", (None, 1, 0, True, False, "foo", object())) | ||
def test_payload_preparation_retains_simple_datatype_identity(original): | ||
prepared = utils.PayloadWrapper._prepare(original) | ||
# check not only that the values are equal, but that they pass the identity test | ||
assert prepared is original | ||
|
||
|
||
# this test makes sense in the context of the identity test above: | ||
# check that the values are equal, although the type may be reconstructed | ||
@pytest.mark.parametrize("original", (["foo", "bar"], {"foo": "bar"})) | ||
def test_payload_preparation_retains_complex_datatype_equality(original): | ||
prepared = utils.PayloadWrapper._prepare(original) | ||
assert prepared == original | ||
|
||
|
||
def test_payload_preparation_dictifies_wrappers(): | ||
x = utils.PayloadWrapper() | ||
x["foo"] = 1 | ||
prepared = utils.PayloadWrapper._prepare(x) | ||
assert prepared == {"foo": 1} | ||
assert isinstance(prepared, dict) | ||
assert prepared is not x | ||
assert not isinstance(prepared, utils.PayloadWrapper) | ||
|
||
|
||
def test_payload_preparation_recursively_dictifies_wrappers(): | ||
x = utils.PayloadWrapper() | ||
x["foo"] = 1 | ||
y = utils.PayloadWrapper() | ||
y["bar"] = x | ||
y["baz"] = [2, x] | ||
prepared = utils.PayloadWrapper._prepare(y) | ||
assert prepared == {"bar": {"foo": 1}, "baz": [2, {"foo": 1}]} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import copy | ||
import pickle | ||
|
||
import pytest | ||
|
||
from globus_sdk import utils | ||
|
||
|
||
def test_missing_type_cannot_be_instantiated(): | ||
with pytest.raises(TypeError, match="MissingType should not be instantiated"): | ||
utils.MissingType() | ||
|
||
|
||
def test_missing_sentinel_bools_as_false(): | ||
assert bool(utils.MISSING) is False | ||
|
||
|
||
def test_str_of_missing(): | ||
assert str(utils.MISSING) == "<globus_sdk.MISSING>" | ||
|
||
|
||
def test_copy_of_missing_is_self(): | ||
assert copy.copy(utils.MISSING) is utils.MISSING | ||
assert copy.deepcopy(utils.MISSING) is utils.MISSING | ||
|
||
|
||
def test_pickle_of_missing_is_self(): | ||
assert pickle.loads(pickle.dumps(utils.MISSING)) is utils.MISSING |
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.
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.
Oof. This style runs afoul of my similar preference for implicit string concatenation: in parentheses. I'm surprised that black doesn't modify this already, but I may have to adjust to this style.
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.
It looks like
black
leaves this in the "user specified style".I'll change this one -- and BTW I have a much stronger feeling that parenthesized is better here than with the strings.
I'll look into adding a
slyp
check for this later.