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

TYP: annotate curry #516

Closed
wants to merge 7 commits into from
Closed

TYP: annotate curry #516

wants to merge 7 commits into from

Conversation

twoertwein
Copy link

This mirrors the type annotations of functools.partial.

@twoertwein
Copy link
Author

I'm currently using / which requires python 3.8+ to avoid parameter name collisions (curry(some_function, func=some_keyword)). Name collisions could also be "avoided" by using a random name for func.

One big difference to functools.partial is that curry can either return another curry object or the return value of the wrapped function. I'm not sure whether typing this function makes sense: __call__ has to return Union[_T, curry[_T]] which does not make it particularly useful.

@eriknw

@eriknw
Copy link
Member

eriknw commented Jul 4, 2021

Thanks for this! I'm eager to get type annotations in toolz.

I also look forward to only supporting Python 3.8+, and am eager to use the / syntax in function signatures. This will need to wait until the end of the year. Many dependents of toolz follow NEP 29, which suggests which Python versions should be supported.

@mrocklin
Copy link
Member

mrocklin commented Jul 4, 2021

My preference would be for toolz to be more conservative than NEP 29. It tries to be more core in the stack than most projects. My hope is that we can still get a lot of typing done without /

@eriknw
Copy link
Member

eriknw commented Jul 4, 2021

Agreed, and historically it has cost us little to support older versions of Python.

@twoertwein
Copy link
Author

I think I found an ugly way to avoid /. Let's see what the CI says about older python versions.

With python 3.9.5

from toolz.functoolz import curry

def fun(test: str) -> int:
    return 1

reveal_type(curry(fun))

mypy: note: Revealed type is "toolz.functoolz.curry[builtins.int*]"
pyright: info: Type of "curry(fun)" is "curry[int]"

@twoertwein
Copy link
Author

The current version should work on python>=3.5. The second overload is just used to silence mypy.

Is it possible to run the CI again?

@twoertwein twoertwein closed this May 14, 2022
@getzze getzze mentioned this pull request Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants