Skip to content

Commit a67117d

Browse files
committed
REFACT(modif) privatize all attrs ...
besides being uncanny for str to have more stuff, pandalone Pstep break :-(
1 parent 42d4ff5 commit a67117d

File tree

3 files changed

+54
-50
lines changed

3 files changed

+54
-50
lines changed

graphtik/fnop.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,9 @@ def _match_inputs_with_fn_needs(self, named_inputs) -> Tuple[list, list, dict]:
636636
else:
637637
inp_value = named_inputs[n]
638638

639-
if get_keyword(n):
640-
kwargs[n.keyword] = inp_value
639+
keyword = get_keyword(n)
640+
if keyword:
641+
kwargs[keyword] = inp_value
641642

642643
elif is_vararg(n):
643644
vararg_vals.append(inp_value)

graphtik/modifier.py

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,25 @@ class _Modifier(str):
175175
_func: str
176176
#: Map my name in `needs` into this kw-argument of the function.
177177
#: :func:`get_keyword()` returns it.
178-
keyword: str = None
178+
_keyword: str = None
179179
#: required is None, regular optional or varargish?
180180
#: :func:`is_optional()` returns it.
181181
#: All regulars are `keyword`.
182-
optional: _Optionals = None
182+
_optional: _Optionals = None
183183
#: An :term:`accessor` with getter/setter functions to read/write solution values.
184184
#: Any sequence of 2-callables will do.
185-
accessor: Accessor = None
185+
_accessor: Accessor = None
186186
#: Has value only for sideffects: the pure-sideffect string or
187187
#: the existing :term:`sideffected` dependency.
188-
sideffected: str = None
188+
_sideffected: str = None
189189
#: At least one name(s) denoting the :term:`sideffects` modification(s) on
190190
#: the :term:`sideffected`, performed/required by the operation.
191191
#:
192192
#: - If it is an empty tuple`, it is an abstract sideffect,
193193
#: and :func:`is_pure_optional()` returns True.
194194
#: - If not empty :func:`is_sfxed()` returns true
195195
#: (the :attr:`sideffected`).
196-
sfx_list: Tuple[Union[str, None]] = ()
196+
_sfx_list: Tuple[Union[str, None]] = ()
197197

198198
def __new__(
199199
cls,
@@ -236,15 +236,15 @@ def __new__(
236236
obj._repr = _repr
237237
obj._func = _func
238238
if keyword:
239-
obj.keyword = keyword
239+
obj._keyword = keyword
240240
if optional:
241-
obj.optional = optional
241+
obj._optional = optional
242242
if accessor:
243-
obj.accessor = accessor
243+
obj._accessor = accessor
244244
if sideffected:
245-
obj.sideffected = sideffected
245+
obj._sideffected = sideffected
246246
if sfx_list:
247-
obj.sfx_list = sfx_list
247+
obj._sfx_list = sfx_list
248248
vars(obj).update(kw)
249249
return obj
250250

@@ -255,29 +255,29 @@ def __repr__(self):
255255
@property
256256
def cmd(self):
257257
"""the code to reproduce it"""
258-
dep = self.sideffected or str(self)
258+
dep = self._sideffected or str(self)
259259
items = [f"'{dep}'"]
260-
if self.sfx_list:
261-
items.append(", ".join(f"'{i}'" for i in self.sfx_list))
262-
if self.keyword and self.keyword != dep:
263-
keyword = f"'{self.keyword}'"
264-
items.append(f"keyword={keyword}" if self.sfx_list else keyword)
265-
if self.optional == _Optionals.keyword and self._func != "optional":
266-
items.append("optional=1" if self.sfx_list else "1")
267-
if self.accessor:
268-
items.append(f"accessor={self.accessor!r}")
260+
if self._sfx_list:
261+
items.append(", ".join(f"'{i}'" for i in self._sfx_list))
262+
if self._keyword and self._keyword != dep:
263+
keyword = f"'{self._keyword}'"
264+
items.append(f"keyword={keyword}" if self._sfx_list else keyword)
265+
if self._optional == _Optionals.keyword and self._func != "optional":
266+
items.append("optional=1" if self._sfx_list else "1")
267+
if self._accessor:
268+
items.append(f"accessor={self._accessor!r}")
269269
return f"{self._func}({', '.join(items)})"
270270

271271
def __getnewargs__(self):
272272
return (
273273
str(self),
274274
self._repr,
275275
self._func,
276-
self.keyword,
277-
self.optional,
278-
self.accessor,
279-
self.sideffected,
280-
self.sfx_list,
276+
self._keyword,
277+
self._optional,
278+
self._accessor,
279+
self._sideffected,
280+
self._sfx_list,
281281
)
282282

283283

@@ -367,9 +367,9 @@ def modifier_withset(
367367
if isinstance(dep, _Modifier):
368368
kw = {
369369
**{
370-
k: v
370+
k.lstrip("_"): v
371371
for k, v in vars(dep).items()
372-
# Regenerate cached, truthy-only, jsnop-parts.
372+
# Regenerate cached, truthy-only, jsonp-parts.
373373
if k != "_jsonp" or not v
374374
},
375375
**{k: v for k, v in locals().items() if v is not ...},
@@ -378,10 +378,10 @@ def modifier_withset(
378378
kw = {
379379
k: v
380380
for k, v in kw.items()
381-
if k not in ("dep", "name", "kw", "_repr", "_func")
381+
if k not in set(["dep", "name", "kw", "repr", "func"])
382382
}
383383
if name is ...:
384-
name = dep.sideffected or str(dep)
384+
name = dep._sideffected or str(dep)
385385
else:
386386
name = dep
387387

@@ -1017,7 +1017,7 @@ def get_keyword(dep) -> Optional[str]:
10171017
:return:
10181018
the :attr:`.keyword`
10191019
"""
1020-
return getattr(dep, "keyword", None)
1020+
return getattr(dep, "_keyword", None)
10211021

10221022

10231023
def is_optional(dep) -> Optional[_Optionals]:
@@ -1029,22 +1029,22 @@ def is_optional(dep) -> Optional[_Optionals]:
10291029
:return:
10301030
the :attr:`.optional`
10311031
"""
1032-
return getattr(dep, "optional", None)
1032+
return getattr(dep, "_optional", None)
10331033

10341034

10351035
def is_vararg(dep) -> bool:
10361036
"""Check if an :term:`optionals` dependency is `vararg`."""
1037-
return getattr(dep, "optional", None) == _Optionals.vararg
1037+
return getattr(dep, "_optional", None) == _Optionals.vararg
10381038

10391039

10401040
def is_varargs(dep) -> bool:
10411041
"""Check if an :term:`optionals` dependency is `varargs`."""
1042-
return getattr(dep, "optional", None) == _Optionals.varargs
1042+
return getattr(dep, "_optional", None) == _Optionals.varargs
10431043

10441044

10451045
def is_varargish(dep) -> bool:
10461046
"""Check if an :term:`optionals` dependency is :term:`varargish`."""
1047-
return dep.optional in (_Optionals.vararg, _Optionals.vararg)
1047+
return dep._optional in (_Optionals.vararg, _Optionals.vararg)
10481048

10491049

10501050
def get_jsonp(dep) -> Union[List[str], None]:
@@ -1059,17 +1059,17 @@ def is_sfx(dep) -> Optional[str]:
10591059
:return:
10601060
the :attr:`.sideffected`
10611061
"""
1062-
return getattr(dep, "sideffected", None)
1062+
return getattr(dep, "_sideffected", None)
10631063

10641064

10651065
def is_pure_sfx(dep) -> bool:
10661066
"""Check if it is :term:`sideffects` but not a :term:`sideffected`."""
1067-
return getattr(dep, "sideffected", None) and not getattr(dep, "sfx_list", None)
1067+
return getattr(dep, "_sideffected", None) and not getattr(dep, "_sfx_list", None)
10681068

10691069

10701070
def is_sfxed(dep) -> bool:
10711071
"""Check if it is :term:`sideffected`."""
1072-
return getattr(dep, "sideffected", None) and getattr(dep, "sfx_list", None)
1072+
return getattr(dep, "_sideffected", None) and getattr(dep, "_sfx_list", None)
10731073

10741074

10751075
def get_accessor(dep) -> bool:
@@ -1079,38 +1079,38 @@ def get_accessor(dep) -> bool:
10791079
:return:
10801080
the :attr:`accessor`
10811081
"""
1082-
return getattr(dep, "accessor", None)
1082+
return getattr(dep, "_accessor", None)
10831083

10841084

10851085
def acc_contains(dep) -> Callable[[Collection, str], Any]:
10861086
"""
10871087
A fn like :func:`operator.contains` for any `dep` (with-or-without :term:`accessor`)
10881088
"""
1089-
acc = getattr(dep, "accessor", None)
1089+
acc = getattr(dep, "_accessor", None)
10901090
return acc.contains if acc else operator.contains
10911091

10921092

10931093
def acc_getitem(dep) -> Callable[[Collection, str], Any]:
10941094
"""
10951095
A fn like :func:`operator.getitem` for any `dep` (with-or-without :term:`accessor`)
10961096
"""
1097-
acc = getattr(dep, "accessor", None)
1097+
acc = getattr(dep, "_accessor", None)
10981098
return acc.getitem if acc else operator.getitem
10991099

11001100

11011101
def acc_setitem(dep) -> Callable[[Collection, str, Any], None]:
11021102
"""
11031103
A fn like :func:`operator.setitem` for any `dep` (with-or-without :term:`accessor`)
11041104
"""
1105-
acc = getattr(dep, "accessor", None)
1105+
acc = getattr(dep, "_accessor", None)
11061106
return acc.setitem if acc else operator.setitem
11071107

11081108

11091109
def acc_delitem(dep) -> Callable[[Collection, str], None]:
11101110
"""
11111111
A fn like :func:`operator.delitem` for any `dep` (with-or-without :term:`accessor`)
11121112
"""
1113-
acc = getattr(dep, "accessor", None)
1113+
acc = getattr(dep, "_accessor", None)
11141114
return acc.delitem if acc else operator.delitem
11151115

11161116

@@ -1122,7 +1122,7 @@ def dependency(dep) -> str:
11221122
the the pure-sideffect string or the existing :term:`sideffected` dependency
11231123
stored in :attr:`sideffected`.
11241124
"""
1125-
return str(dep) if is_sfx(dep) else dep.sideffected
1125+
return str(dep) if is_sfx(dep) else dep._sideffected
11261126

11271127

11281128
def dep_renamed(dep, ren) -> Union[_Modifier, str]:
@@ -1142,7 +1142,7 @@ def dep_renamed(dep, ren) -> Union[_Modifier, str]:
11421142

11431143
if isinstance(dep, _Modifier):
11441144
if is_sfx(dep):
1145-
new_name = renamer(dep.sideffected)
1145+
new_name = renamer(dep._sideffected)
11461146
dep = modifier_withset(dep, name=new_name, sideffected=new_name)
11471147
else:
11481148
dep = modifier_withset(dep, name=renamer(str(dep)))
@@ -1157,7 +1157,7 @@ def dep_singularized(dep) -> Iterable[Union[str, _Modifier]]:
11571157
Yield one sideffected for each sfx in :attr:`.sfx_list`, or iterate `dep` in other cases.
11581158
"""
11591159
return (
1160-
(modifier_withset(dep, sfx_list=(s,)) for s in dep.sfx_list)
1160+
(modifier_withset(dep, sfx_list=(s,)) for s in dep._sfx_list)
11611161
if is_sfxed(dep)
11621162
else (dep,)
11631163
)
@@ -1170,5 +1170,7 @@ def dep_stripped(dep) -> Union[str, _Modifier]:
11701170
conveying all other properties of the original modifier to the stripped dependency.
11711171
"""
11721172
if is_sfxed(dep):
1173-
dep = modifier_withset(dep, name=dep.sideffected, sideffected=None, sfx_list=())
1173+
dep = modifier_withset(
1174+
dep, name=dep._sideffected, sideffected=None, sfx_list=()
1175+
)
11741176
return dep

graphtik/planning.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,9 @@ def append_subdoc_chain(doc_parts):
395395
ekw["optional"] = True
396396
if is_sfx(n):
397397
ekw["sideffect"] = nkw["sideffect"] = True
398-
if get_keyword(n):
399-
ekw["keyword"] = n.keyword
398+
keyword = get_keyword(n)
399+
if keyword:
400+
ekw["keyword"] = keyword
400401
needs.append((n, nkw))
401402
needs_edges.append((n, operation, ekw))
402403
graph.add_nodes_from(needs)

0 commit comments

Comments
 (0)