Commit b18ad976 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

refactor: force_string -> force_string_and_int

parent d27a7df3
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ from astropy import table, time

from ._dispatcher import Dispatcher
from ..dag_utils import (
    force_string,
    force_string_and_int,
    override_common_keys,
    generate_sha1_from_time,
)
@@ -72,8 +72,8 @@ class BaseDAG:
        )

    @staticmethod
    def force_string(d: dict):
        return force_string(d)
    def force_string_and_int(d: dict):
        return force_string_and_int(d)


class Level2DAG(BaseDAG):
@@ -364,5 +364,5 @@ class Level1DAG(BaseDAG):
        # It seems that the dag_run_template is already stringified,
        # so we don't need to force_string here.
        # force values to be string
        dag_run = self.force_string(dag_run)
        dag_run = self.force_string_and_int(dag_run)
        return dag_run
+5 −3
Original line number Diff line number Diff line
@@ -68,14 +68,16 @@ def generate_uuid():
    return str(uuid.uuid4())


def force_string(d):
def force_string_and_int(d):
    """更通用的递归字符串转换"""
    if isinstance(d, dict):
        return {k: force_string(v) for k, v in d.items()}
        return {k: force_string_and_int(v) for k, v in d.items()}
    elif isinstance(d, Iterable) and not isinstance(d, (str, bytes)):
        return [force_string(item) for item in d]
        return [force_string_and_int(item) for item in d]
    elif isinstance(d, (str, bytes)):
        return str(d)
    elif type(d) in (np.int32, np.int64):
        return int(d)
    else:
        return d