Skip to content

[LINT][PYTHON] Modernize annotations with ruff UP rules#18830

Merged
tqchen merged 7 commits intoapache:mainfrom
tqchen:lint-improvements
Feb 28, 2026
Merged

[LINT][PYTHON] Modernize annotations with ruff UP rules#18830
tqchen merged 7 commits intoapache:mainfrom
tqchen:lint-improvements

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Feb 26, 2026

This PR enables ruff pyupgrade (UP) rules with py310 target, auto-fixing ~5600 annotation modernizations (PEP 585 generics, PEP 604 unions, deprecated typing imports).

Also removes from future import annotations from ir/module.py and rmsnorm.py, bumps requires-python to >=3.10, and removes absolute_import aliases from topi/contrib files.

@tqchen tqchen changed the title [REFACTOR][PYTHON] Modernize annotations with ruff UP rules [LINT][PYTHON] Modernize annotations with ruff UP rules Feb 26, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tqchen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on modernizing the codebase's Python annotations using ruff's pyupgrade rules, targeting Python 3.10. It also addresses technical debt by removing unnecessary future imports and streamlining import statements, resulting in a cleaner and more maintainable codebase.

Highlights

  • Ruff Pyupgrade Rules: Enabled ruff pyupgrade (UP) rules with py310 target, automatically fixing approximately 5600 annotation modernizations.
  • PEP Compliance: Modernized annotations to comply with PEP 585 (generics) and PEP 604 (unions).
  • Dependency Update: Bumped the minimum required Python version to 3.10.
  • Code Cleanup: Removed from __future__ import annotations from ir/module.py and rmsnorm.py, and eliminated absolute_import aliases from topi/contrib files.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Activity
  • This PR introduces automated code modernizations via ruff, enhancing code style and PEP compliance.
  • The changes include updating annotations, removing obsolete imports, and bumping the minimum Python version.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a large-scale modernization of Python type annotations across the codebase, leveraging ruff's pyupgrade rules for Python 3.10. The changes consistently replace legacy typing constructs like typing.List, typing.Dict, typing.Optional, and typing.Union with their modern, built-in counterparts (e.g., list, dict, | operator). The Python version requirement has been correctly bumped to >=3.10 in pyproject.toml to support these changes. The automated refactoring appears to have been applied correctly and thoroughly, improving code readability and maintainability by adopting modern Python features. I have reviewed a substantial sample of the changes and found them to be correct and consistent.

@tqchen tqchen force-pushed the lint-improvements branch 4 times, most recently from 39b30ef to 7c18bf7 Compare February 27, 2026 22:41
This PR enables ruff pyupgrade (UP) rules with py310 target,
auto-fixing ~5600 annotation modernizations (PEP 585 generics,
PEP 604 unions, deprecated typing imports). Also removes
from __future__ import annotations from ir/module.py and
rmsnorm.py, bumps requires-python to >=3.10, and removes
absolute_import aliases from topi/contrib files.
The ruff UP modernization converted typing.Union/Optional to PEP 604
syntax (X | Y, X | None), but the runtime type checker only recognized
typing.Union. When a PEP 604 union like tuple[str, int] | None reached
_type_check_atomic, isinstance() failed because it cannot handle
parameterized generics.

Fix: teach _Subtype.optional() and _Subtype.union() to also recognize
types.UnionType (Python 3.10+ PEP 604 unions), and restore Union[types]
in error reporting for _type_check_union.
`callable` (lowercase) is the builtin function, not a type —
it doesn't support the `|` operator. Use `Callable` from
`collections.abc` instead.
MSC code uses runtime-evaluated annotations with objects like
multiprocessing.Manager (a function, not a type) and callable
(builtin function), which break with PEP 604 X | None syntax.
Add per-file-ignore for UP rules on MSC files and restore
original annotations.
@tqchen tqchen merged commit 9a8320a into apache:main Feb 28, 2026
9 checks passed
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.

2 participants