Skip to content

Commit 5f4d510

Browse files
committed
refactors put better
1 parent 82029b0 commit 5f4d510

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

refinery/lib/types.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,13 @@ def __iter__(self):
252252

253253
def __next__(self):
254254
return self
255+
256+
257+
class _NoDefault(metaclass=Singleton):
258+
pass
259+
260+
261+
NoDefault = _NoDefault()
262+
"""
263+
A sentinel singleton that can be used as a no-default marker when "None" is a valid option.
264+
"""

refinery/units/meta/put.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
from refinery.lib.meta import check_variable_name
66
from refinery.lib.tools import isbuffer, typename
7-
from refinery.lib.types import Param, isq
7+
from refinery.lib.types import NoDefault, Param, isq
88
from refinery.units import Arg, Chunk, Unit
99

10-
_EMPTY = object()
11-
1210

1311
class put(Unit):
1412
"""
@@ -18,15 +16,15 @@ class put(Unit):
1816
def __init__(
1917
self,
2018
name: Param[str, Arg.String(help='The name of the variable to be used.')],
21-
value: Param[isq, Arg.NumSeq(check=False, help=(
19+
value: Param[isq | NoDefault, Arg.NumSeq(check=False, help=(
2220
'The value for the variable. If no value is given, the entire current chunk is stored.'
23-
))] = _EMPTY
21+
))] = NoDefault
2422
):
2523
super().__init__(name=check_variable_name(name), value=value)
2624

2725
def process(self, data: Chunk):
2826
value = self.args.value
29-
if value is _EMPTY:
27+
if value is NoDefault:
3028
value = data
3129
if not isinstance(value, (int, float)) and not isbuffer(value):
3230
try:

0 commit comments

Comments
 (0)