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

Broken type hints for functions decorated with high_level_function #3401

Open
chuyuanliu opened this issue Feb 18, 2025 · 1 comment
Open
Assignees
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged

Comments

@chuyuanliu
Copy link

Version of Awkward Array

2.7.4

Description and code to reproduce

When using functions like ak.ones_like, ak.almost_equal, the static type checkers (for reference I tested with pylance in vscode and pycharm) are not able to properly resolve the signatures of those functions. Instead, they will always give a (...) -> Any. It is likely because in the type hint for high_level_function the parameters are omitted and the TypeVar("T") is not binded to the decorator. A simple solution is to a ParamSpec in the following way:

from awkward._typing import Any, ParamSpec, TypeAlias, TypeVar

P = ParamSpec("P") # declare a ParamSpec
T = TypeVar("T")
DispatcherType: TypeAlias = "Callable[P, Generator[Collection[Any], None, T]]" # add P
HighLevelType: TypeAlias = "Callable[P, T]" # add P

def high_level_function(
    module: str = "ak", name: str | None = None
) -> Callable[[DispatcherType[P, T]], HighLevelType[P, T]]: # bind P and T to the decorator
@chuyuanliu chuyuanliu added the bug (unverified) The problem described would be a bug, but needs to be triaged label Feb 18, 2025
@pfackeldey pfackeldey self-assigned this Feb 27, 2025
@pfackeldey
Copy link
Collaborator

Thank @chuyuanliu for reporting this! I'll have a look at it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants