Fixes cast problem when type changed but we got NOT_MODIFIED token.
This commit is contained in:
@ -342,6 +342,8 @@ class NodeExecutionContext(BaseContext, WithStatistics):
|
||||
# TODO: parse flags to check constraints are respected (like not modified alone, etc.)
|
||||
|
||||
if F_NOT_MODIFIED in _flags:
|
||||
if self._output_type:
|
||||
return ensure_tuple(_input, cls=self._output_type)
|
||||
return _input
|
||||
|
||||
if F_INHERIT in _flags:
|
||||
|
||||
@ -6,7 +6,7 @@ from bonobo.constants import NOT_MODIFIED
|
||||
from bonobo.nodes.io.base import FileHandler
|
||||
from bonobo.nodes.io.file import FileReader, FileWriter
|
||||
from bonobo.util import ensure_tuple
|
||||
from bonobo.util.collections import tuple_or_const
|
||||
from bonobo.util.collections import coalesce, tuple_or_const
|
||||
|
||||
|
||||
class CsvHandler(FileHandler):
|
||||
@ -105,7 +105,7 @@ class CsvWriter(FileWriter, CsvHandler):
|
||||
|
||||
def write(self, file, context, *values, fs):
|
||||
context.setdefault("lineno", 0)
|
||||
fields = context.get_input_fields() if self.fields is None else self.fields
|
||||
fields = coalesce(self.fields, context.get_input_fields())
|
||||
|
||||
if not context.lineno:
|
||||
context.writer = self.writer_factory(file)
|
||||
|
||||
@ -8,19 +8,11 @@ from graphviz.dot import Digraph
|
||||
|
||||
from bonobo.constants import BEGIN
|
||||
from bonobo.util import get_name
|
||||
from bonobo.util.collections import coalesce
|
||||
|
||||
GraphRange = namedtuple("GraphRange", ["graph", "input", "output"])
|
||||
|
||||
|
||||
def coalesce(*values):
|
||||
if not len(values):
|
||||
raise ValueError("Cannot coalesce an empty list of arguments.")
|
||||
for value in values:
|
||||
if value is not None:
|
||||
return value
|
||||
return values[-1]
|
||||
|
||||
|
||||
class GraphCursor:
|
||||
@property
|
||||
def input(self):
|
||||
|
||||
@ -105,3 +105,17 @@ iterator-returning function to force return value to be a tuple.
|
||||
>>> my_generator()
|
||||
(1, 2, 3)
|
||||
"""
|
||||
|
||||
|
||||
def coalesce(*values):
|
||||
"""
|
||||
Returns the first argument which is not None, or None if all arguments are None.
|
||||
|
||||
"""
|
||||
|
||||
if not len(values):
|
||||
raise ValueError("Cannot coalesce an empty list of arguments.")
|
||||
for value in values:
|
||||
if value is not None:
|
||||
return value
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user