Ensure subok#173
Closed
jakirkham wants to merge 4 commits intozarr-developers:masterfrom
jakirkham:ensure_subok
Closed
Ensure subok#173jakirkham wants to merge 4 commits intozarr-developers:masterfrom jakirkham:ensure_subok
jakirkham wants to merge 4 commits intozarr-developers:masterfrom
jakirkham:ensure_subok
Conversation
This was referenced Feb 21, 2019
Closed
Provides a `subok` flag to the `ensure_*` functions much like the one NumPy frequently uses. It's purpose is to either accept subclassed types and work with them or not accept them and force them into the exact type (e.g. an `ndarray` or a `bytes` object). This is useful in cases where subclassed objects would otherwise cause problems.
Tries using `subok` as `True` or `False` with different inputs that are the expected type or a subclass. Checks each case to see that it either preserves the original type or is reconstructed as the exact type.
Member
Author
|
Wound up solving this in a better way with PR ( zarr-developers/zarr-python#429 ), which has been incorporated here with PR ( #201 ). So going to close this out. |
This file contains hidden or 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
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.
Adds the
subokoption to theensure_*functions. This merely determines whether subclasses of the expected type should be preserved or whether they should be forced into the expected type. By default subclasses are allowed (existing behavior), but users are now able to override this as needed. Tests exercise subclasses with theensure_*functions to verify the correct behavior is seen.This can be useful when working with things like MongoDB where
bson.Binaryis passed around and is a subclass ofbytes. In some cases functions are able to handle this subclass without issues. In other cases functions really need abytesobject. This provides a nice switch for enforcing the intended type with theensure_bytes(or otherensure_*) function.xref: zarr-developers/zarr-python#372
xref: zarr-developers/zarr-python#401
TODO:
tox -e py37passes locallytox -e py27passes locallytox -e docspasses locally