pytoolz / pytoolz/toolz

Bug in compose introduced in 0.10.0

Open
#481 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.2k
Forks
280
Avg merge
6d 17h
Merged PRs (30d)
4

Description

Consider a file temp.py :

import toolz
import functools

print("toolz:", toolz.__version__)

def g(x):
    return x

class A(object):

    def __call__(self):

        _fg = toolz.compose(lambda x:x, g)

        class Inner(object):
            fg = _fg
        return Inner()
    
a = A()()
print(a.fg(2))

with toolz 0.9.0:

$ python temp.py
toolz: 0.9.0
2

With toolz 0.10.0:

$ python temp.py
toolz: 0.10.0
Traceback (most recent call last):
  File "temp.py", line 21, in <module>
    print(a.fg(2))
  File "/Users/Thomas/.local/miniconda3/envs/mantik_dev/lib/python3.7/site-packages/toolz/functoolz.py", line 486, in __call__
    ret = self.first(*args, **kwargs)
TypeError: g() takes 1 positional argument but 2 were given

In the second example, g gets called with an additional <__main__.A.__call__.<locals>.Inner object as first argument.

If not a bug, it's at least a change of behavior breaking code using toolz.

The above example is very reduced and may look strange but is totally sensible in the usecase where it's actually used.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reduced reproduction in temp.py with the affected toolz versions, then inspect toolz/functoolz.py around line 486 where the traceback enters call. Done means the composition no longer passes the Inner instance as an extra argument and the reproduction prints 2 without an exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.