-
Notifications
You must be signed in to change notification settings - Fork 31.3k
VSCode pylance auto-completion for HfArgumentParser (limited support)
#27275
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,13 +21,27 @@ | |
| from enum import Enum | ||
| from inspect import isclass | ||
| from pathlib import Path | ||
| from typing import Any, Callable, Dict, Iterable, List, Literal, NewType, Optional, Tuple, Union, get_type_hints | ||
| from typing import ( | ||
| Any, | ||
| Callable, | ||
| Dict, | ||
| Iterable, | ||
| List, | ||
| Literal, | ||
| NewType, | ||
| Optional, | ||
| Tuple, | ||
| TypeVar, | ||
| Union, | ||
| get_type_hints, | ||
| ) | ||
|
|
||
| import yaml | ||
|
|
||
|
|
||
| DataClass = NewType("DataClass", Any) | ||
| DataClassType = NewType("DataClassType", Any) | ||
| T = TypeVar("T") | ||
|
|
||
|
|
||
| # From https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse | ||
|
|
@@ -269,7 +283,7 @@ def parse_args_into_dataclasses( | |
| look_for_args_file=True, | ||
| args_filename=None, | ||
| args_file_flag=None, | ||
| ) -> Tuple[DataClass, ...]: | ||
| ) -> Tuple[T, ...]: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me this looks the same as annotating the return type to The usual use of I have some ideas for suggestions that I can leave in a comment!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks so much for the comment. I think the most ideal workflow is something like below working, but not sure if it's possible 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first option I listed below should do this exactly! The trick is that |
||
| """ | ||
| Parse command-line args into instances of the specified dataclass types. | ||
|
|
||
|
|
||
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.
Any idea why these
NewType()s were used originally instead of a simple alias? LikeDataClass = Any,DataclassType = Any.