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

[HF Argparser] Fix parsing of optional boolean arguments #16946

Merged
merged 2 commits into from
Apr 27, 2022

Conversation

NielsRogge
Copy link
Contributor

What does this PR do?

This PR fixes a weird bug that made optional boolean arguments not being recognized properly in my virtual environment.

Replacing "is" by "==" fixed the issue.

@NielsRogge NielsRogge requested a review from sgugger April 26, 2022 14:11
@@ -103,7 +103,7 @@ def _parse_dataclass_field(parser: ArgumentParser, field: dataclasses.Field):
kwargs["default"] = field.default
else:
kwargs["required"] = True
elif field.type is bool or field.type is Optional[bool]:
elif field.type is bool or field.type == Optional[bool]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether we should use "==" everywhere for consistency, as we now have both "is" and "==".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me. You should also fix the test on line 143 of this file :-)

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 26, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing!

@NielsRogge NielsRogge merged commit 084c38c into huggingface:main Apr 27, 2022
chamidullinr pushed a commit to chamidullinr/transformers that referenced this pull request Apr 28, 2022
…#16946)

* Add fix

* Apply suggestion from code review

Co-authored-by: Niels Rogge <[email protected]>
elusenji pushed a commit to elusenji/transformers that referenced this pull request Jun 12, 2022
…#16946)

* Add fix

* Apply suggestion from code review

Co-authored-by: Niels Rogge <[email protected]>
JunnYu added a commit to JunnYu/PaddleNLP that referenced this pull request Aug 2, 2023
sijunhe pushed a commit to PaddlePaddle/PaddleNLP that referenced this pull request Aug 2, 2023
triple-Mu pushed a commit to triple-Mu/PaddleNLP that referenced this pull request Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants