Update ruff to 0.13.1 + target Python 3.10 + apply fixes
Author: cyyever
Pull request: yes

# What does this PR do?
Use ruff 0.13.0 and apply fixes.

Comments:
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.

cc @ydshieh @arthurzucker!

Hi @cyyever Thank you for the pull request 🤗 .

We tend to not update the patch version of ruff. In fact, we update it much less frequently when there is a need (fix some issues for example), like #36962.

Ruff is under very active development and there is no need to sync its version closely.

Is there any important reason to update to 0.11.7 at this moment?

A good timing would be 2025-10 when python 3.9 reach its EOL

https://devguide.python.org/versions/

But open to discuss if there is something new happening 

I would want to add `UP` rules before py3.9 ends, because they introduce a lot of changes. If that work begins with py3.10, the changes are more, and it's harder to review.

Up to you @ydshieh 

I will take a look this this week

Hi @cyyever 

Python 3.9 will end in 2 months (31 Oct 2025). In your opinion, if it would be better if we update directly with python 3.10 ..?

I can build a dev docker images for CI with python 3.10, and use those images in this PR. And once everything is ready and the day python 3.10 arrive, we could switch in one go ..?

Let me know what you think 🙏 

@ydshieh Let is good idea. FYI PyTorch is moving their CI to 3.10.

@ydshieh Thank you for your patience in this PR. I have updated to Py3.10 and applied another fix to move `typing.Callable` to `collections.abc`   

Thanks for the update 🙏 . I will build the dev CI docker images and use it for them.

I plan to drop python 3.9 support at the end of Oct, and in this case, so we (you) will have to perform/apply the changes on the repository at that time again before we can merge ..?





@ydshieh No problem. It's my honour.

Going to build new images and see how it works. Will update here once ready.

Let me fix the conflicts.

A PR https://github.com/huggingface/transformers/pull/41067 is opened.

I am waiting for approvals for core maintainers.

@ydshieh Let's try it

@ydshieh CI is green.

Hi @cyyever Great! I could see the quality job is already running with ruff 0.13.1.

Just want to be sure, is it normal that only 5 being changed in this PR? I thought it would be a lot many more files ..: 🤔 ?

@ydshieh Most upgrade changes have been absorbed in other merged PRs (many others are no longer needed due to removal of tf, flax,jax code). The remaining changes are typing, for example, change `Optional[int]` to `int |None`. These changes are disabled temporarily to make this PR easier to review. They are
```
# UP045: Use `X | None` for type annotations
# UP007: Use `X | Y` for type annotations
# UP035: temporarily disabled to minimize upgrade changes
```

Nice approach! Will take a look today and merge 🎉 ! Thank you for the work and the great patience 🙏 

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: metaclip_2

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_37809). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.