Skip to content

Commit

Permalink
[116] Fixes to kargs and kwargs, bumps version (#117)
Browse files Browse the repository at this point in the history
* failing test

* fixes

* version bump and doc
  • Loading branch information
tjhunter authored Mar 11, 2021
1 parent b11a265 commit ad2b0dc
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 615 deletions.
2 changes: 1 addition & 1 deletion dds/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.7.2"
version = "0.7.3"
12 changes: 10 additions & 2 deletions dds/fun_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ def get_arg_ctx(
for (idx, (n, p_)) in enumerate(arg_sig.parameters.items()):
p: inspect.Parameter = p_
# _logger.debug(f"get_arg_ctx: {f}: idx={idx} n={n} p={p}")
if p.kind != Parameter.POSITIONAL_OR_KEYWORD:
if p.kind not in (Parameter.POSITIONAL_OR_KEYWORD, Parameter.VAR_KEYWORD):
raise NotImplementedError(
f"Argument type not understood: {p.kind} {f} {arg_sig}"
)
h: Optional[PyHash]
if idx < num_args:
# It is a list argument
# TODO: should it discard arguments of not-whitelisted types?
Expand All @@ -110,6 +111,9 @@ def get_arg_ctx(
# TODO: should it discard arguments of not-whitelisted types?
# TODO: raise a warning for non-whitelisted objects
h = dds_hash(p.default or "__none__")
elif p.kind == Parameter.VAR_KEYWORD:
# kwargs: for now, just ignored
h = None
else:
raise NotImplementedError(
f"Cannot deal with argument name {n} {p.kind} {f} {arg_sig}"
Expand Down Expand Up @@ -145,7 +149,11 @@ def process_arg(node: ast.AST) -> Optional[PyHash]:
p: inspect.Parameter = p_
# _logger.debug(f"get_arg_ctx: {f}: idx={idx} n={n} p={p}")
h: Optional[PyHash]
if p.kind != Parameter.POSITIONAL_OR_KEYWORD:
if p.kind not in (
Parameter.POSITIONAL_OR_KEYWORD,
Parameter.VAR_KEYWORD,
Parameter.VAR_POSITIONAL,
):
raise NotImplementedError(
f"Argument type not understood {p.kind} {f} {arg_sig}"
)
Expand Down
49 changes: 49 additions & 0 deletions dds_tests/test_kargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import dds
import pytest
from .utils import cleandir

_ = cleandir

path_1 = "/path_1"


def f1(x, y, z):
return x + y + z


def f1_1():
kargs = [1, 2, 3]
return dds.keep("/p1", f1, *kargs)


def f1_2():
kargs = [2]
kwargs = [{"z": 3}]
return f1(1, *kargs, **kwargs[0])


@pytest.mark.usefixtures("cleandir")
def test_kargs_1():
assert dds.eval(f1_1) == 6
assert dds.eval(f1_2) == 6


def f2(*args, **kwargs):
return len(args) + len(kwargs)


def f2_1():
kargs = [1, 2, 3]
return dds.keep("/p1", f2, *kargs)


def f2_2():
kargs = [2]
kwargs = [{"z": 3}]
return f2(1, *kargs, **kwargs[0])


@pytest.mark.usefixtures("cleandir")
def test_kargs_2():
assert dds.eval(f2_1) == 3
assert dds.eval(f2_2) == 3
5 changes: 5 additions & 0 deletions doc_source/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.7.3

Fixes the usage of positional and keyworded arguments when used in conjunction
with `dds.keep`.

## v0.7.2

Small usability fixes in this release:
Expand Down
2 changes: 1 addition & 1 deletion doc_source/tut_sklearn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Seting up the `dds` store:"
"Seting up the `dds` store. This is a recommended operation (here necessary to generate the documentation)."
]
},
{
Expand Down
Loading

0 comments on commit ad2b0dc

Please sign in to comment.