-
Notifications
You must be signed in to change notification settings - Fork 431
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
nit: Fix/add some type annotations #1982
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/1982
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 2e21126 with merge base ac4f88e (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! Out of curiosity, is there a "correct" typing for *args
and **kwargs
? I thought they actually should be untyped. The updated return types look good to me, though.
You can type them, but there is a bit of nuance: def foo(*args: Any, **kwargs: Any) -> None:
args # inferred type here is tuple[Any, ...]
kwargs # inferred type here is dict[str, Any]
def bar(*args: tuple[Any, ...], **kwargs: dict[str, Any]) -> None:
args # inferred type here would be tuple[tuple[Any, ...], ...]
kwargs # inferred type here would be dict[str, dict[str, Any]] You can see that the type annotations are for the members of You can leave def foobar(*strings: str, **ints: int) -> None:
strings # inferred type is tuple[str, ...]
ints # inferred type is dict[str, int]
foobar("hello", a=10, b=3) # okay
foobar(10, c="world") # not okay, args are expected to be strings and kwargs are expected to be integers |
@bradhilton just need to fix lint and I can stamp it |
I think lint passed @RdoubleA |
Test failing, need to revert some changes. |
@bradhilton , thanks for the PR! Would you mind making it consistent in the other places that we have typing for args, kwargs? |
uv.lock
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably unintentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! 🤦♂️
will merge after tests pass. Thanks! |
Context
What is the purpose of this PR? Is it to
Changelog
What are the changes made in this PR?