Skip to content

Support type checking for launch arguments #68

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

Closed
apoorvkh opened this issue Sep 29, 2024 · 5 comments · Fixed by #86
Closed

Support type checking for launch arguments #68

apoorvkh opened this issue Sep 29, 2024 · 5 comments · Fixed by #86
Labels
enhancement New feature or request

Comments

@apoorvkh
Copy link
Owner

No description provided.

@apoorvkh apoorvkh added the enhancement New feature or request label Oct 19, 2024
@apoorvkh
Copy link
Owner Author

apoorvkh commented Nov 2, 2024

Don't think there is a solution here. This is similar to functools.partial, which needs/needed a custom patch in pyright/mypy.

@apoorvkh apoorvkh closed this as completed Nov 2, 2024
@apoorvkh
Copy link
Owner Author

Actually, maybe there are some ways to do this:

python/typeshed#8703
https://peps.python.org/pep-0612/
python/mypy#1484

@apoorvkh apoorvkh reopened this Nov 16, 2024
@apoorvkh
Copy link
Owner Author

apoorvkh commented Dec 29, 2024

Consider adding a decorator?

@torchrunx.launch(hostnames=[...])
def my_function(x: int):
   ...

my_function(x=10)  # this command is launched and is also statically type checked

https://github.com/chrisgrimm/better_partial

@apoorvkh
Copy link
Owner Author

See typing.ParamSpec

@apoorvkh
Copy link
Owner Author

ChatGPT suggestion

from typing import Callable, TypeVar, ParamSpec

P = ParamSpec("P")
R = TypeVar("R")

def call_func(func: Callable[P, R], args: P.args) -> R:
    return func(*args)

# Example usage
def add(a: int, b: int) -> int:
    return a + b

result = call_func(add, (1, 2))  # ✅ Correct usage
# result = call_func(add, (1, 2, 3))  # ❌ Type checker will flag this as an error
# result = call_func(add, ("one", "two"))  # ❌ Type checker will flag this as an error

print(result)  # Output: 3

@apoorvkh apoorvkh linked a pull request Feb 15, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant