cgarciae / pypeln

Concurrent data pipelines in Python >>>
https://cgarciae.github.io/pypeln
MIT License
1.55k stars 98 forks source link

[Bug] __or__ in Partial wrong #115

Open BlackHC opened 3 months ago

BlackHC commented 3 months ago

Describe the bug

Partial implements both or and ror the same way:

class Partial(tp.Generic[T]):
    def __init__(self, f):
        self.f = f

    def __or__(self, stage) -> T:
        return self.f(stage)

    def __ror__(self, stage) -> T:
        return self.f(stage)

    def __call__(self, stage) -> T:
        return self.f(stage)

Both cannot be correct at the same time; ror is correct and or ought to be removed.

Minimal code to reproduce Small snippet that contains a minimal amount of code.

import pypeln

async def inc(x):
    return x+1

assert list(range(1,11)) == await (range(10) | pypeln.task.map(inc))
assert list(range(1,11)) == await (pypeln.task.map(inc) | range(10))

The first pipe range(10) | pypeln.task.map(inc) is correct according to the API.

The second pipe pypeln.task.map(inc) | range(10) is definitely not valid (and should not be).

Expected behavior

pypeln.task.map(inc) | range(10) should lead to an error.

Deleting or indeed fixes it.

del pypeln.utils.Partial.__or__
await (pypeln.task.map(inc) | range(10))

leads to

TypeError: unsupported operand type(s) for |: 'Partial' and 'range'

Library Info Please provide os info and elegy version.

import pypeln
print(pypeln.__version__)

returns 0.4.9