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 PEP 563 for HfArgumentParser #15795

Merged
merged 8 commits into from
Mar 17, 2022

Conversation

function2-llx
Copy link
Contributor

@function2-llx function2-llx commented Feb 23, 2022

What does this PR do?

Fixes #15739, support for PEP 563 is added, making it possible to write from __future__ import annotations in the file of dataclasses for HfArgumentParser. But this will not be available for Python with a version lower than 3.7, thus adding from __future__ import annotations in the test is currently infeasible because __future__ imports should always occur at the beginning of the file. Instead, I write a test case with string literal annotations.

Before submitting

  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

@LysandreJik

@HuggingFaceDocBuilder
Copy link

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

kwargs["nargs"] = "?"
# This is the value that will get picked if we do --field_name (without value)
kwargs["const"] = True
elif isclass(origin_type) and issubclass(origin_type, list):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative implementation without regular expression for #15951

@function2-llx
Copy link
Contributor Author

@LysandreJik Hello, would be great if you could help or ask someone to give any feedback on this, thanks!
Seems #15951 updated the parser as well (just resolved the conflict), I've done the same work, and added a comment at the corresponding changing line.

@function2-llx
Copy link
Contributor Author

Looking forward to any feedback.

@LysandreJik
Copy link
Member

Thanks for the ping! @sgugger could you give this a quick look? It's similar to the work merged in #15951

@sgugger
Copy link
Collaborator

sgugger commented Mar 17, 2022

It looks like you did a rebase on your PR that GitHub did not appreciate (the diff shows 292 files). Could you close this PR and open a fresh one?

@function2-llx
Copy link
Contributor Author

@sgugger Github encountered some internal error a little while ago, it seems to be fine now.

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 a lot for working on this! The diff is indeed more readable now.
I just have one comment to make the code more readable, otherwise LGTM!

src/transformers/hf_argparser.py Outdated Show resolved Hide resolved
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Mar 17, 2022

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

function2-llx and others added 2 commits March 18, 2022 00:23
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
@function2-llx
Copy link
Contributor Author

@sgugger Thanks so much for the feedback! I've adopted that. In addition, I've replaced ... != type(None) with isinstance to pass the quality check.

@sgugger sgugger merged commit 81643ed into huggingface:master Mar 17, 2022
@sgugger
Copy link
Collaborator

sgugger commented Mar 17, 2022

Cool, thanks again for your contribution!

FrancescoSaverioZuppichini pushed a commit that referenced this pull request Mar 21, 2022
* Support PEP 563 for HfArgumentParser

* Fix issues for Python 3.6

* Add test for string literal annotation for HfArgumentParser

* Remove wrong comment

* Fix typo

* Improve code readability

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>

* Use `isinstance` to compare types to pass quality check

* Fix style

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
FrancescoSaverioZuppichini pushed a commit that referenced this pull request Mar 24, 2022
* Support PEP 563 for HfArgumentParser

* Fix issues for Python 3.6

* Add test for string literal annotation for HfArgumentParser

* Remove wrong comment

* Fix typo

* Improve code readability

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>

* Use `isinstance` to compare types to pass quality check

* Fix style

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
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.

Add compatibility for Postponed Evaluation of Annotations (PEP 563)
5 participants