-
-
Notifications
You must be signed in to change notification settings - Fork 418
deprecate more enums #3968
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
Merged
Merged
deprecate more enums #3968
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a57f745
refactor(codecs): extract shared enum-deprecation helpers
d-v-b 778519c
refactor(codecs): use shared enum-deprecation helpers in blosc
d-v-b 8e3244d
feat(codecs): deprecate Endian enum
d-v-b a90f4dc
fixup(codecs): restore spec form for Endian deprecation
d-v-b c4f7cb1
refactor(buffer): widen NDBuffer.byteorder to EndianLiteral
d-v-b a5ceda1
chore(codecs): drop now-unused type-ignore in BytesCodec._encode_sync
d-v-b e3895e1
feat(codecs): deprecate ShardingCodecIndexLocation enum
d-v-b 686bcd4
test: rewrite sharding-test parametrize decorators to literal strings
d-v-b f7eca85
refactor(core): use IndexLocationLiteral in array module
d-v-b 7b5c9f6
test: use literal strings for sharding/endian in conftest + test_info
d-v-b 3ff470e
chore(changes): add changelog entry for Endian + sharding enum deprec…
d-v-b 695fb58
chore(changes): document NDBuffer.byteorder and default_system_endian…
d-v-b 123add0
test(codecs): tighten deprecation-warning patterns and cover legacy i…
d-v-b b2633c1
refactor: drop _parse_index_location cross-module imports
d-v-b 3094d99
test(codecs): cover bytes evolve_from_array_spec and init_array dict-…
d-v-b 2908cb8
refactor: rename IndexLocationLiteral to IndexLocation
d-v-b f55f792
Merge branch 'main' into deprecate-more-enums
d-v-b 82cbdce
Merge branch 'main' into deprecate-more-enums
d-v-b 03443fb
Merge origin/deprecate-more-enums into deprecate-more-enums
d-v-b 5a6aaeb
Merge branch 'deprecate-more-enums' of https://github.com/d-v-b/zarr-…
d-v-b d264cc7
Merge branch 'main' of https://github.com/zarr-developers/zarr-python…
d-v-b 8da1333
chore(deps): bump the actions group across 1 directory with 8 updates…
dependabot[bot] 659c734
Merge branch 'main' of https://github.com/d-v-b/zarr-python
d-v-b 51c994b
Merge branch 'main' of https://github.com/zarr-developers/zarr-python
d-v-b 117b7ba
Merge branch 'main' of github.com:d-v-b/zarr-python
d-v-b d4de75d
Merge branch 'main' of github.com:zarr-developers/zarr-python
d-v-b 86dabd5
Merge branch 'main' of github.com:zarr-developers/zarr-python
d-v-b 34a9c78
Merge branch 'deprecate-more-enums' of github.com:d-v-b/zarr-python i…
d-v-b 47b4d81
docs: clarify that _coerce_enum_input only fires for foreign enum ins…
d-v-b 3f54f3e
Merge branch 'main' of github.com:zarr-developers/zarr-python into de…
d-v-b 376a684
docs: rename changelog
d-v-b 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| The ``Endian`` (``zarr.codecs.bytes.Endian``) and ``ShardingCodecIndexLocation`` | ||
| (``zarr.codecs.ShardingCodecIndexLocation``) enums are now deprecated. Pass the | ||
| equivalent literal string instead (e.g. ``"little"`` / ``"big"``, ``"start"`` / | ||
| ``"end"``). The enum classes remain importable but emit ``DeprecationWarning`` | ||
| on member access, and will be removed in a future release. ``BytesCodec.endian`` | ||
| and ``ShardingCodec.index_location`` are now plain strings rather than enum | ||
| members. | ||
|
|
||
| Two follow-on changes from this deprecation: | ||
|
|
||
| - ``NDBuffer.byteorder`` now returns a literal string (``"little"`` or | ||
| ``"big"``) rather than an ``Endian`` member. Subclasses overriding this | ||
| property should update their return type. | ||
| - The module-level binding ``zarr.codecs.bytes.default_system_endian`` was | ||
| removed. ``BytesCodec()`` continues to default to ``sys.byteorder``; | ||
| external callers that imported ``default_system_endian`` should use | ||
| ``sys.byteorder`` directly. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| """Helpers for deprecating string-valued enums in favor of literal strings. | ||
|
|
||
| See PR #3963 for context on the deprecation pattern. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import warnings | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class _DeprecatedStrEnumMeta(type): | ||
| """ | ||
| Metaclass for legacy enum-like classes. Accessing a member name on the | ||
| class (e.g. `LegacyShim.foo`) emits a `DeprecationWarning` and returns | ||
| the equivalent string. Members are declared by setting a `_members` | ||
| class attribute mapping each member name to its string value. | ||
| """ | ||
|
|
||
| _members: dict[str, str] | ||
|
|
||
| def __getattr__(cls, name: str) -> str: | ||
| members: dict[str, str] = type.__getattribute__(cls, "_members") | ||
| if name in members: | ||
| warnings.warn( | ||
| f"{cls.__name__}.{name} is deprecated; pass the string {members[name]!r} instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return members[name] | ||
| raise AttributeError(name) | ||
|
|
||
|
|
||
| def _coerce_enum_input(value: object, param_name: str, codec_name: str) -> object: | ||
| """ | ||
| If `value` is a real `enum.Enum` instance, emit a deprecation warning | ||
| naming `codec_name` and return `value.value`. Otherwise return `value` | ||
| unchanged. The third argument lets the warning text name the actual | ||
| codec (e.g. `BloscCodec`, `BytesCodec`, `ShardingCodec`). | ||
|
|
||
| Note that zarr's own legacy classes (e.g. `ShardingCodecIndexLocation`) | ||
| never reach the `Enum` branch here: they no longer inherit from `Enum`, | ||
| and member access on them already returns a plain string (with its own | ||
| warning) via `_DeprecatedStrEnumMeta`. This branch exists for enum | ||
| instances defined *outside* zarr — in particular `str`-mixin enums that | ||
| downstream code defined to mirror zarr's old enums, which the old | ||
| `parse_enum`-based codepath accepted because they are `str` instances. | ||
| Coercing them to `value.value` keeps the stored attribute a plain string | ||
| and gives those callers a migration warning. | ||
| """ | ||
| if isinstance(value, Enum): | ||
| warnings.warn( | ||
| f"Passing an enum to {codec_name}(..., {param_name}=...) is deprecated; " | ||
| "pass the equivalent literal string instead.", | ||
| DeprecationWarning, | ||
| stacklevel=3, | ||
| ) | ||
| return value.value | ||
| return value | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Something I missed was that this line is not called by instantiating a class with a now-deprecated former
Enumbecause nothing actually inherits fromEnumanymore. What is this for then? Am I misreading this?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.
this is very defensive, to cover a situation where someone defined their own str enum outside of zarr, which would have worked before.