From 0a2f94bb4941cf1907051a2f1ff1b04c03812bd1 Mon Sep 17 00:00:00 2001 From: Sanjay Sudagani <264130408+sanjaysudagani@users.noreply.github.com> Date: Tue, 3 Mar 2026 11:45:36 +0530 Subject: [PATCH] Add curried toolz compatibility module --- docs/eth_utils.curried.rst | 11 ++++ eth_utils/curried/toolz.py | 19 +++++++ newsfragments/136.bugfix.rst | 2 + .../core/curried-utils/test_curried_toolz.py | 52 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 eth_utils/curried/toolz.py create mode 100644 newsfragments/136.bugfix.rst create mode 100644 tests/core/curried-utils/test_curried_toolz.py diff --git a/docs/eth_utils.curried.rst b/docs/eth_utils.curried.rst index af10ff8f..bccc4585 100644 --- a/docs/eth_utils.curried.rst +++ b/docs/eth_utils.curried.rst @@ -1,6 +1,17 @@ eth\_utils.curried package ========================== +Submodules +---------- + +eth\_utils.curried.toolz module +------------------------------- + +.. automodule:: eth_utils.curried.toolz + :members: + :undoc-members: + :show-inheritance: + Module contents --------------- diff --git a/eth_utils/curried/toolz.py b/eth_utils/curried/toolz.py new file mode 100644 index 00000000..3204ca2d --- /dev/null +++ b/eth_utils/curried/toolz.py @@ -0,0 +1,19 @@ +""" +Compatibility wrappers for the curried toolz API. +""" + +try: + from cytoolz import ( + curried as _curried_toolz, + ) +except ImportError: + from toolz import ( + curried as _curried_toolz, + ) + + +globals().update( + {name: value for name, value in vars(_curried_toolz).items() if "__" not in name} +) + +del _curried_toolz diff --git a/newsfragments/136.bugfix.rst b/newsfragments/136.bugfix.rst new file mode 100644 index 00000000..83b10dfc --- /dev/null +++ b/newsfragments/136.bugfix.rst @@ -0,0 +1,2 @@ +Added the ``eth_utils.curried.toolz`` compatibility module so curried toolz +helpers can be imported through ``eth-utils``. diff --git a/tests/core/curried-utils/test_curried_toolz.py b/tests/core/curried-utils/test_curried_toolz.py new file mode 100644 index 00000000..b314c5c4 --- /dev/null +++ b/tests/core/curried-utils/test_curried_toolz.py @@ -0,0 +1,52 @@ +try: + from cytoolz import ( + curried as upstream_curried_toolz, + ) +except ImportError: + from toolz import curried as upstream_curried_toolz + +from eth_utils.curried import ( + toolz as imported_toolz_module, +) +import eth_utils.curried.toolz + + +def test_curried_toolz_module_is_importable_from_package(): + assert imported_toolz_module is eth_utils.curried.toolz + + +def test_curried_toolz_namespace_matches_upstream(): + expected = { + name: value + for name, value in vars(upstream_curried_toolz).items() + if "__" not in name + } + actual = { + name: value + for name, value in vars(eth_utils.curried.toolz).items() + if "__" not in name + } + + assert actual == expected + + +def test_curried_toolz_dicttoolz_smoke_test(): + assert eth_utils.curried.toolz.get("count")({"count": 3}) == 3 + + +def test_curried_toolz_functoolz_smoke_test(): + hexint = eth_utils.curried.toolz.compose(hex, int) + + assert hexint("10") == "0xa" + + +def test_curried_toolz_itertoolz_smoke_test(): + drop2 = eth_utils.curried.toolz.drop(2) + + assert list(drop2([4, 3, 2, 1])) == [2, 1] + + +def test_curried_toolz_recipe_smoke_test(): + windows = eth_utils.curried.toolz.sliding_window(2)([1, 2, 3, 4]) + + assert tuple(windows) == ((1, 2), (2, 3), (3, 4))