Skip to content

Commit

Permalink
fix: Use isinstance to support subclasses of values for deepmap
Browse files Browse the repository at this point in the history
For example this enables support for NamedTuples, making return types
more clear from pipedag tasks
  • Loading branch information
btat-qc committed Oct 3, 2024
1 parent 72107e4 commit 3a7e59f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/pydiverse/pipedag/util/deep_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Heavily inspired by the builtin copy module of python:
https://github.com/python/cpython/blob/main/Lib/copy.py
"""

from __future__ import annotations

from typing import Callable
Expand All @@ -19,13 +20,11 @@ def deep_map(x, fn: Callable, memo=None):
if y is not _nil:
return y

cls = type(x)

if cls == list:
if isinstance(x, list):
y = _deep_map_list(x, fn, memo)
elif cls == tuple:
elif isinstance(x, tuple):
y = _deep_map_tuple(x, fn, memo)
elif cls == dict:
elif isinstance(x, dict):
y = _deep_map_dict(x, fn, memo)
else:
y = fn(x)
Expand Down

0 comments on commit 3a7e59f

Please sign in to comment.