Skip to content

[Chore/Refactor] Replace Optional[T] with T | None in Python type hints #25559

@laipz8200

Description

@laipz8200

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for refactoring, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Description

Add an ast-grep rule to the CI autofix workflow to automatically convert all Optional[T] type hints to the modern T | None syntax in Python files.

Motivation

The Optional[T] type hint from typing is considered deprecated in favor of the more concise and readable T | None syntax introduced in Python 3.10. This refactor will:

  • Modernize the codebase to use current Python type hinting best practices
  • Improve code readability with shorter, cleaner type annotations
  • Reduce imports from the typing module
  • Ensure consistency across the codebase with automated CI enforcement

Additional Context

This change adds an ast-grep rule to the existing autofix CI workflow that will automatically convert type hints during pull requests, ensuring all new and modified code uses the modern syntax.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions