Skip to content

cytoolz.curried.valmap suppresses errors in the mapping function call #135

Open
@kevinheavey

Description

@kevinheavey

Here is how valmap works when it runs into an error inside the mapping function like below:

In [1]: import cytoolz

In [2]: cytoolz.curried.valmap(lambda x: x + 'a')({'key': 1})
Out[2]: <cyfunction valmap at 0x7f7791339b90>

Meanwhile here's how toolz works (raises an error as expected):

In [3]: import toolz

In [4]: toolz.curried.valmap(lambda x: x + 'a')({'key': 1})
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-9d36150f91b0> in <module>
----> 1 toolz.curried.valmap(lambda x: x + 'a')({'key': 1})

/tmp/envs/my_env/lib/python3.7/site-packages/toolz/functoolz.py in __call__(self, *args, **kwargs)
    301     def __call__(self, *args, **kwargs):
    302         try:
--> 303             return self._partial(*args, **kwargs)
    304         except TypeError as exc:
    305             if self._should_curry(args, kwargs, exc):

/tmp/envs/my_env/lib/python3.7/site-packages/toolz/dicttoolz.py in valmap(func, d, factory)
     82     rv = factory()
---> 83     rv.update(zip(iterkeys(d), map(func, itervalues(d))))
     84     return rv
     85

<ipython-input-4-9d36150f91b0> in <lambda>(x)
----> 1 toolz.curried.valmap(lambda x: x + 'a')({'key': 1})

TypeError: unsupported operand type(s) for +: 'int' and 'str'

Package versions:

In [5]: cytoolz.__version__
Out[5]: '0.10.0'

In [6]: toolz.__version__
Out[6]: '0.10.0'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions