Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] __or__ in Partial wrong #115

Open
BlackHC opened this issue Jun 14, 2024 · 0 comments
Open

[Bug] __or__ in Partial wrong #115

BlackHC opened this issue Jun 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@BlackHC
Copy link

BlackHC commented Jun 14, 2024

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

@BlackHC BlackHC added the bug Something isn't working label Jun 14, 2024
@BlackHC BlackHC changed the title [Bug] Either __or__ in Partial wrong [Bug] __or__ in Partial wrong Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant