-
-
Notifications
You must be signed in to change notification settings - Fork 53
Fix/type action restriction #687
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
Conversation
Additional infoWhen creating remote branch, the git hook fired and I got this mypy................................................................................Failed
- hook id: mypy
- duration: 0.98s
- exit code: 1
jsonargparse/_stubs_resolver.py:51: error: No overload variant of "Assign" matches argument types "list[Name | Attribute | Subscript]", "expr | None", "list[Never]", "int", "int" [call-overload]
jsonargparse/_stubs_resolver.py:51: note: Possible overload variants:
jsonargparse/_stubs_resolver.py:51: note: def Assign(self, targets: list[expr], value: expr, type_comment: str | None = ..., *, lineno: int = ..., col_offset: int = ..., end_lineno: int | None = ..., end_col_offset: int | None = ...) -> Assign
jsonargparse/_stubs_resolver.py:51: note: def Assign(self, targets: list[expr] = ..., *, value: expr, type_comment: str | None = ..., lineno: int = ..., col_offset: int = ..., end_lineno: int | None = ..., end_col_offset: int | None = ...) -> Assign
jsonargparse/_stubs_resolver.py:53: error: Unused "type: ignore" comment [unused-ignore]
jsonargparse/_stubs_resolver.py:54: error: Unused "type: ignore" comment [unused-ignore]
Found 3 errors in 1 file (checked 3 source files) Since I didn't edit these files, I used Also, I didn't have mypy/ruff installed (which made. Maybe we can consider adding them to the contributing guideline? I saw them in |
not sure where to put the test:
|
Also I find another problem: we pass in jsonargparse/jsonargparse/_core.py Line 142 in c3d3df7
Should I create another PR on this? |
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.
Issue #685 also mentioned the case type=None
so I was expecting a test for this.
How does it work differently? I think it could be part of this pull request. |
I see. I think I need to specify in the pre-commit config which python version to run mypy with. No problem that you skipped it.
mypy/ruff don't need to be installed. It is pre-commit run -a ruff to only run pre-commit run -a --hook-stage pre-push mypy |
Co-authored-by: Mauricio Villegas <[email protected]>
Co-authored-by: Mauricio Villegas <[email protected]>
Co-authored-by: Mauricio Villegas <[email protected]>
When I meant to create a new issue but I have not read the document nor have I tested it yet. Do you think this worths a shot? |
Without them, I cannot format the code effectively. The suggestion was to add a part to mentioning the toolkit we are using in this project for more consistent code style. |
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.
Please add an entry to the changelog. After that, this would be good to merge.
With type=None and action=None, there's no problem with the old code. Should we still add the test?
Okay, fine. Then lets leave it like that.
When action is not None, passing choices=None, there will be similar problem with type=None.
But I have more doubts about choices: I'm creating a parser with dataclass where some fields are Enum type, and only a part of the Enum should be used. (Enum CLI args are matched by the name instead of value.)
In this case, jsonargparse will check if the parsed value is in choices, not the user input. However, the help test is only showing the parsed option, not what user should input.I meant to create a new issue but I have not read the document nor have I tested it yet. Do you think this worths a shot?
Okay, it does sound like this needs a specific issue to address.
Can you explain what you mean by "I cannot format the code effectively"? The code will be automatically formatted when pre-commit runs. And even if pre-commit is skipped, a github action will format it. |
I added the change log and I think it's ready to merge.
I wanted to say that I avoided formatting the code intentionally because my line length was set to 80 instead of 120 on my local environment because I didn't know about the GitHub action. And Pylance was reporting this everywhere
And about the Union type deprecation "This type is deprecated as of Python 3.10" etc. I guess our env was very different and I didn't change my python interpreter version (I'm exactly suffering for "mac313"). Anyway, thanks for your patience and guidance in this PR. I'll create another issue on the "choices" args. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #687 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 6688 6688
=========================================
Hits 6688 6688 ☔ View full report in Codecov by Sentry. |
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.
Thank you for contributing!
Thanks for the info! I will do some changes and probably ping you for review. |
What does this PR do?
Fix #685
Now in
add_argument
, passingaction=None
behaves like call without argumentaction
.Before submitting