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 type checking for launch arguments #68

Open
apoorvkh opened this issue Sep 29, 2024 · 5 comments
Open

Support type checking for launch arguments #68

apoorvkh opened this issue Sep 29, 2024 · 5 comments
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

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

No branches or pull requests

1 participant