Skip to content

Commit 3a51aef

Browse files
committed
break(MODIF) Forbid Implicit SFXEDs ...
hard to find a solid use-case that pure `sfx` would'nt solve. Also need some space for converting sfx-list -> implicits.
1 parent 39a9ecc commit 3a51aef

File tree

6 files changed

+18
-65
lines changed

6 files changed

+18
-65
lines changed

graphtik/modifier.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#: Arguments-presence patterns for :class:`_Modifier` constructor.
4848
#: Combinations missing raise errors.
4949
_modifier_cstor_matrix = {
50+
# TODO: Add `implicit` in the table, to augment REPR & forbid implicit sfxed.
5051
# (7, kw, opt, accessors, sfxed, sfx): (STR, REPR, FUNC) OR None
5152
700000: None,
5253
710000: ( "%(dep)s", "'%(dep)s'(%(acs)s>%(kw)s)", "keyword"),
@@ -248,7 +249,14 @@ def __new__(
248249
accessor.validate()
249250
if sideffected and is_sfx(sideffected):
250251
raise ValueError(
251-
f"`sideffected` cannot be sideffect, got {sideffected!r}"
252+
f"`sideffected` cannot be `sfx`, got {sideffected!r}"
253+
f"\n locals={locals()}"
254+
)
255+
256+
# TODO: Add `implicit` in the table, to augment REPR & forbid implicit sfxed.
257+
if sideffected and kw.get("_implicit"):
258+
raise ValueError(
259+
f"`sideffected` cannot be `implicit`, got {sideffected!r}"
252260
f"\n locals={locals()}"
253261
)
254262
double_sideffects = [
@@ -1080,14 +1088,13 @@ def sfxed(
10801088
optional: bool = None,
10811089
accessor: Accessor = None,
10821090
jsonp=None,
1083-
implicit=None,
10841091
) -> _Modifier:
10851092
r"""
10861093
Annotates a :term:`sideffected` dependency in the solution sustaining side-effects.
10871094
10881095
:param dependency:
10891096
the actual dependency receiving the sideffect, which will be fed into/out
1090-
of the function (unless marked as :term:`implicit`).
1097+
of the function.
10911098
:param sfx0:
10921099
the 1st (arbitrary object) sideffect marked as "acting" on the `dependency`.
10931100
:param sfx0:
@@ -1103,8 +1110,6 @@ def sfxed(
11031110
:param jsonp:
11041111
None (derrived from `name`), ``False``, str, collection of str/callable (last one)
11051112
See generic :func:`.modify` modifier.
1106-
:param implicit:
1107-
:term:`implicit` dependencies are not fed into/out of the function.
11081113
11091114
Like :func:`.sfx` but annotating a *real* :term:`dependency` in the solution,
11101115
allowing that dependency to be present both in :term:`needs` and :term:`provides`
@@ -1195,7 +1200,6 @@ def sfxed(
11951200
sfx_list=(sfx0, *sfx_list),
11961201
accessor=accessor,
11971202
jsonp=jsonp,
1198-
implicit=implicit,
11991203
)
12001204

12011205

test/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,15 @@ def test_jetsam_n_plot_with_DEBUG():
275275
"a",
276276
sfxed("b", "foo", keyword="bb"),
277277
implicit("c"),
278-
sfxed("d", "bar", implicit=1),
278+
sfxed("d", "bar"),
279279
vararg("e"),
280280
varargs("f"),
281281
],
282282
provides=[
283283
"A",
284284
sfxed("b", "FOO", keyword="bb"),
285285
implicit("C"),
286-
sfxed("d", "BAR", implicit=1),
286+
sfxed("d", "BAR", optional=True),
287287
sfx("FOOBAR"),
288288
],
289289
aliases={"A": "aaa", "b": "bbb", "d": "ddd"}, # FIXME: "D" is implicit!

test/test_graphtik.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from graphtik import (
1313
NO_RESULT,
1414
compose,
15+
implicit,
1516
modify,
1617
operation,
1718
optional,
@@ -136,22 +137,20 @@ def test_cycle_tip():
136137
pipe.compute()
137138

138139

139-
def test_aliases(exemethod):
140-
provides = ("a", sfxed("s1", "foo"), sfxed("s2", "foo", implicit=1))
140+
def test_aliases_pipeline(exemethod):
141+
provides = ("a", sfxed("s", "foo"))
141142
aliased = operation(
142143
lambda: ("A", "B"),
143144
name="op1",
144145
provides=provides,
145-
aliases={"a": "b", "s1": "S1", "s2": "S2"},
146+
aliases={"a": "b", "s": "S1"},
146147
)
147148
assert aliased._user_provides == provides
148149
assert tuple(aliased.provides) == (
149150
"a",
150-
sfxed("s1", "foo"),
151-
sfxed("s2", "foo"),
151+
sfxed("s", "foo"),
152152
"b",
153153
"S1",
154-
"S2",
155154
)
156155

157156
pipe = compose(
@@ -160,7 +159,7 @@ def test_aliases(exemethod):
160159
operation(lambda x: x * 2, name="op2", needs="b", provides="c"),
161160
parallel=exemethod,
162161
)
163-
assert pipe() == {"a": "A", "s1": "B", "b": "A", "S1": "B", "c": "AA"}
162+
assert pipe() == {"a": "A", "s": "B", "b": "A", "S1": "B", "c": "AA"}
164163
assert list(pipe.provides) == [*aliased.provides, "c"]
165164

166165

test/test_modifier.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,6 @@ def test_implicit(ser_method):
341341
assert is_implicit(m) is True
342342
m = optional("a", implicit=1)
343343
assert is_implicit(m) is 1
344-
m = sfxed("a", "b")
345-
assert is_implicit(m) is None
346-
m = sfxed("a", "b", implicit=1)
347-
assert is_implicit(m) == 1
348-
m = sfxed("a", "b", "c", implicit=0)
349-
assert is_implicit(m) == 0
350344

351345
assert dep_renamed(m, "R")._implicit == m._implicit
352346
assert ser_method(m)._implicit == m._implicit

test/test_op.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -402,30 +402,6 @@ def test_as_renames(inp, exp):
402402
(["i"], {"i": implicit("II")}),
403403
ValueError("must not contain `implicits"),
404404
),
405-
## Implicit SFXEDs
406-
(
407-
([sfxed("i", "1", implicit=1)], {sfxed("i", "1", implicit=1): "II"}),
408-
ValueError("must not contain `implicits"),
409-
),
410-
(
411-
([sfxed("i", "1")], {sfxed("i", "1", implicit=1): "II"}),
412-
ValueError("must not contain `implicits"),
413-
),
414-
(
415-
([sfxed("i", "1", implicit=1)], {sfxed("i", "1"): "II"}),
416-
ValueError("must not contain `implicits"),
417-
),
418-
pytest.param(
419-
([sfxed("i", "1", implicit=1)], {"i": "II"}),
420-
ValueError("must not contain `implicits"),
421-
marks=pytest.mark.xfail(
422-
reason="Would eliminate implicit sfxeds in the next commit"
423-
),
424-
),
425-
(
426-
(["i"], {"i": sfxed("II", "1", implicit=1)}),
427-
ValueError("must not contain `implicits"),
428-
),
429405
],
430406
)
431407
def test_func_op_validation_aliases_BAD(prov_aliases, ex):

test/test_sideffects.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -463,23 +463,3 @@ def test_implicit_out():
463463
assert got == {"A": ""}
464464

465465
assert "(implicit)" in str(op.plot())
466-
467-
468-
def test_sfxed_implicit_inp():
469-
op = operation(str, needs=["A", sfxed("a", "b", implicit=1)], provides="a")
470-
471-
pipe = compose(..., op)
472-
got = pipe.compute({"A": "val", sfxed("a", "b"): 1}, "a")
473-
assert got == {"a": "val"}
474-
475-
assert "(implicit)" in str(op.plot())
476-
477-
478-
def test_sfxed_implicit_out():
479-
op = operation(str, "hh", provides=["A", sfxed("a", "b", implicit=1)])
480-
481-
pipe = compose(..., op)
482-
got = pipe.compute()
483-
assert got == {"A": ""}
484-
485-
assert "(implicit)" in str(op.plot())

0 commit comments

Comments
 (0)