Skip to content

Conversation

@jakirkham
Copy link
Member

Adds the subok option to the ensure_* 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 the ensure_* functions to verify the correct behavior is seen.

This can be useful when working with things like MongoDB where bson.Binary is passed around and is a subclass of bytes. In some cases functions are able to handle this subclass without issues. In other cases functions really need a bytes object. This provides a nice switch for enforcing the intended type with the ensure_bytes (or other ensure_*) function.

xref: zarr-developers/zarr-python#372
xref: zarr-developers/zarr-python#401

TODO:

  • Unit tests and/or doctests in docstrings
  • tox -e py37 passes locally
  • tox -e py27 passes locally
  • Docstrings and API docs for any new/modified user-facing classes and functions
  • Changes documented in docs/release.rst
  • tox -e docs passes locally
  • AppVeyor and Travis CI passes
  • Test coverage to 100% (Coveralls passes)

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.
@jakirkham
Copy link
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.

@jakirkham jakirkham closed this Nov 3, 2019
@jakirkham jakirkham deleted the ensure_subok branch November 3, 2019 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant