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 union types X | Y syntax for HfArgumentParser for Python 3.10+ #23126

Merged
merged 3 commits into from
May 3, 2023

Conversation

XuehaiPan
Copy link
Contributor

@XuehaiPan XuehaiPan commented May 3, 2023

What does this PR do?

Support union types X | Y syntax for HfArgumentParser for Python 3.10+. Allow users using Python 3.10+ to opt in new typing futures, such as union types X | Y (PEP 604). Note that typing.get_type_hints does not work for union types on Python 3.7-3.9.

Fixes #20249

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • 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? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Testing union types X | Y for Python 3.7-3.9 needs to add from __future__ import annotations at the top of the test script. I'm not sure should we need to create a separate test script or add new test cases directly in tests/utils/test_hf_argparser.py.

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented May 3, 2023

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 a lot for adding support and new tests! Left a couple of nits in the test file and we should be able to merge this.

tests/utils/test_hf_argparser.py Outdated Show resolved Hide resolved
tests/utils/test_hf_argparser.py Outdated Show resolved Hide resolved
@XuehaiPan XuehaiPan requested a review from sgugger May 3, 2023 14:38
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 iterating!

@sgugger sgugger merged commit ee4bc07 into huggingface:main May 3, 2023
@XuehaiPan XuehaiPan deleted the union-types branch May 3, 2023 14:50
gojiteji pushed a commit to gojiteji/transformers that referenced this pull request Jun 5, 2023
…3.10+ (huggingface#23126)

* Support union types `X | Y` syntax for `HfArgumentParser` for Python 3.10+

* Add tests for PEP 604 for `HfArgumentParser`

* Reorganize tests
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
…3.10+ (huggingface#23126)

* Support union types `X | Y` syntax for `HfArgumentParser` for Python 3.10+

* Add tests for PEP 604 for `HfArgumentParser`

* Reorganize tests
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.

Support X | Y syntax on HfArgumentParser
3 participants