Skip to content

Conversation

@cyyever
Copy link
Contributor

@cyyever cyyever commented Apr 4, 2025

What does this PR do?

This PR adds Optional to remaining types and add RUF013 rule to enforce that.

RUFF rule RUF013 checks for the use of implicit Optional in type annotations when the default parameter value is None.

@cyyever cyyever changed the title Enable RUF013 for Optional typying Enable RUF013 for Optional typing Apr 4, 2025
@github-actions github-actions bot marked this pull request as draft April 4, 2025 02:33
@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2025

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@cyyever cyyever changed the title Enable RUF013 for Optional typing Enable RUF013 to enforce optional typing Apr 4, 2025
@cyyever cyyever marked this pull request as ready for review April 4, 2025 02:34
@github-actions github-actions bot requested review from ArthurZucker and qubvel April 4, 2025 02:34
@cyyever cyyever force-pushed the optional_ruff2 branch 2 times, most recently from fec79ae to 7320dcf Compare April 4, 2025 02:48
@Rocketknight1 Rocketknight1 removed the request for review from qubvel April 4, 2025 12:11
@Rocketknight1
Copy link
Member

LGTM! One issue, though: We generally don't enforce type hinting. I understand that this will only enforce Optional where there is already a type hint and the default value is None, which makes a lot of sense, but I still want to check with the core maintainers @ArthurZucker and @Cyrilvallez that they're okay with a type hint style check like this!

@cyyever
Copy link
Contributor Author

cyyever commented Apr 4, 2025

@Rocketknight1 And only when we write incomplete types that can default to None. If we don't write types for new code, the check doesn't force us to type them.

@cyyever cyyever force-pushed the optional_ruff2 branch 2 times, most recently from da774d9 to 4f27575 Compare April 12, 2025 00:40
@cyyever
Copy link
Contributor Author

cyyever commented May 2, 2025

@ArthurZucker This is useful for accurate typing.

@Rocketknight1
Copy link
Member

@cyyever can you check the failing files in check_code_quality? There may be a version mismatch or something that's causing your ruff formatting to differ from our CI's

Signed-off-by: cyy <[email protected]>
@cyyever
Copy link
Contributor Author

cyyever commented May 2, 2025

@Rocketknight1 Because of other packages, ruff was downgraded to 0.9 on my host..

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Rocketknight1
Copy link
Member

No probs @cyyever, it looks good now! cc @ArthurZucker @Cyrilvallez - let me know if you're okay with adding an extra Ruff rule here to enforce Optional or | None where there is already a type hint and the default value is None.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Sure! Thanks for the contrib

@ArthurZucker ArthurZucker merged commit 06c16de into huggingface:main May 8, 2025
15 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
* Enable RUF013 for Optional typing

Signed-off-by: cyy <[email protected]>

* Add Optional to types

* Format code

Signed-off-by: cyy <[email protected]>

---------

Signed-off-by: cyy <[email protected]>
@cyyever cyyever deleted the optional_ruff2 branch July 13, 2025 09:28
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.

4 participants