forked from zarr-developers/zarr-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v3' into generalize-stateful-store
* v3: chore: update pre-commit hooks (zarr-developers#2222) fix: validate v3 dtypes when loading/creating v3 metadata (zarr-developers#2209) fix typo in store integration test (zarr-developers#2223) Basic Zarr-python 2.x compatibility changes (zarr-developers#2098) Make Group.arrays, groups compatible with v2 (zarr-developers#2213) Typing fixes to test_indexing (zarr-developers#2193) Default to RemoteStore for fsspec URIs (zarr-developers#2198) Make MemoryStore serialiazable (zarr-developers#2204) [v3] Implement Group methods for empty, full, ones, and zeros (zarr-developers#2210) implement `store.list_prefix` and `store._set_many` (zarr-developers#2064) Fixed codec for v2 data with no fill value (zarr-developers#2207)
- Loading branch information
Showing
34 changed files
with
1,321 additions
and
520 deletions.
There are no files selected for viewing
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,68 @@ | ||
import warnings | ||
from collections.abc import Callable | ||
from functools import wraps | ||
from inspect import Parameter, signature | ||
from typing import Any, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
# Based off https://github.com/scikit-learn/scikit-learn/blob/e87b32a81c70abed8f2e97483758eb64df8255e9/sklearn/utils/validation.py#L63 | ||
|
||
|
||
def _deprecate_positional_args( | ||
func: Callable[..., T] | None = None, *, version: str = "3.1.0" | ||
) -> Callable[..., T]: | ||
"""Decorator for methods that issues warnings for positional arguments. | ||
Using the keyword-only argument syntax in pep 3102, arguments after the | ||
* will issue a warning when passed as a positional argument. | ||
Parameters | ||
---------- | ||
func : callable, default=None | ||
Function to check arguments on. | ||
version : callable, default="3.1.0" | ||
The version when positional arguments will result in error. | ||
""" | ||
|
||
def _inner_deprecate_positional_args(f: Callable[..., T]) -> Callable[..., T]: | ||
sig = signature(f) | ||
kwonly_args = [] | ||
all_args = [] | ||
|
||
for name, param in sig.parameters.items(): | ||
if param.kind == Parameter.POSITIONAL_OR_KEYWORD: | ||
all_args.append(name) | ||
elif param.kind == Parameter.KEYWORD_ONLY: | ||
kwonly_args.append(name) | ||
|
||
@wraps(f) | ||
def inner_f(*args: Any, **kwargs: Any) -> T: | ||
extra_args = len(args) - len(all_args) | ||
if extra_args <= 0: | ||
return f(*args, **kwargs) | ||
|
||
# extra_args > 0 | ||
args_msg = [ | ||
f"{name}={arg}" | ||
for name, arg in zip(kwonly_args[:extra_args], args[-extra_args:], strict=False) | ||
] | ||
formatted_args_msg = ", ".join(args_msg) | ||
warnings.warn( | ||
( | ||
f"Pass {formatted_args_msg} as keyword args. From version " | ||
f"{version} passing these as positional arguments " | ||
"will result in an error" | ||
), | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
kwargs.update(zip(sig.parameters, args, strict=False)) | ||
return f(**kwargs) | ||
|
||
return inner_f | ||
|
||
if func is not None: | ||
return _inner_deprecate_positional_args(func) | ||
|
||
return _inner_deprecate_positional_args # type: ignore[return-value] |
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
Oops, something went wrong.