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

Support for typing.Sequence[int] #27

Closed
ivantitov-zd opened this issue Aug 18, 2021 · 6 comments
Closed

Support for typing.Sequence[int] #27

ivantitov-zd opened this issue Aug 18, 2021 · 6 comments

Comments

@ivantitov-zd
Copy link

@dispatch
async def get_updates(version: Sequence[int]) -> List[Update]:

For the code above I got
NotImplementedError: There is currently no support for "typing.Sequence[int]". Please open an issue at https://github.com/wesselb/plum/issues

@wesselb
Copy link
Member

wesselb commented Aug 24, 2021

Hey @anvdev, just letting you know that I've seen this and that I'm working on this.

@wesselb
Copy link
Member

wesselb commented Aug 25, 2021

Hey @anvdev,

The latest release, v1.5.4, adds support for typing.Iterable and typing.Sequence:

from typing import Sequence

from plum import dispatch

@dispatch
def el_to_str(x: Sequence[int]) -> Sequence[str]:
    for i in range(len(x)):
        x[i] = str(x[i])
    return x
>>> el_to_str([1, 2, 3])
['1', '2', '3']

>>> el_to_str([1.0, 2, 3])
For function "el_to_str", signature Signature(List[Union[builtins.int, builtins.float]]) could not be resolved.

@wesselb wesselb closed this as completed Aug 25, 2021
@ivantitov-zd
Copy link
Author

Thanks for your work.

@ilan-gold
Copy link

ilan-gold commented Feb 5, 2024

I must be missing something but the following raises an AmbiguousLookupError

from collections.abc import Iterable
import plum

@plum.dispatch
def f(x: Iterable[int]): print("int!")

@plum.dispatch
def f(x: Iterable[str]): print("str!")

f(['first', 'second']) # AmbiguousLookupError: `f(['first', 'second'])` is ambiguous.

If not, happy to contribute a fix. Is there no support for checking Iterable and only list/tuple?

@PhilipVinc
Copy link
Collaborator

It's possibly a bug. Can you open a separate issue?

@ilan-gold
Copy link

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants