Skip to content

Move to Python 3.12.#88

Merged
BoxiangW merged 5 commits intomainfrom
skyw/python_312
Jan 20, 2026
Merged

Move to Python 3.12.#88
BoxiangW merged 5 commits intomainfrom
skyw/python_312

Conversation

@skyw
Copy link
Contributor

@skyw skyw commented Jan 20, 2026

Update type annotation to remove old syntax and fallback paths.

Update document to reflect required python version.

No functional change.

Python 3.12 is default version for ubuntu 24.04 LTS. Next release tag close to 26.04 time frame will move to Python 3.12. Release v0.1.0 will be the last support for python 3.10.

skyw added 3 commits January 20, 2026 10:39
Signed-off-by: Hao Wu <skyw@nvidia.com>
Signed-off-by: Hao Wu <skyw@nvidia.com>
Signed-off-by: Hao Wu <skyw@nvidia.com>
@skyw skyw requested a review from BoxiangW January 20, 2026 18:58
@copy-pr-bot
Copy link

copy-pr-bot bot commented Jan 20, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps
Copy link

greptile-apps bot commented Jan 20, 2026

Greptile Summary

This PR completes the migration to Python 3.12 by removing all compatibility fallbacks and updating the codebase to use modern Python 3.10+ type annotation syntax. The changes include:

Type System Updates:

  • Removed all try/except fallbacks for importing override decorator from typing_extensions; now imports directly from typing module
  • Removed typing_extensions dependency from pyproject.toml
  • Migrated from old-style type annotations to modern generic syntax:
    • Optional[X]X | None (union operator)
    • List[X]list[X] (lowercase generics)
    • Tuple[X, Y]tuple[X, Y] (lowercase generics)
  • Removed unused imports (Optional, Tuple, List) from 5 files
  • Added TypeAlias for cleaner type definitions in soap_utils.py

Configuration Updates:

  • Updated pyproject.toml: requires-python = ">=3.12" and ruff target-version = "py312"
  • Updated all documentation to reflect Python 3.12 requirement (README.md, docs/index.md)
  • Updated Python badge from 3.10+ to 3.12+ in README

Documentation Updates:

  • Simplified docstring return type descriptions by removing type annotation syntax (e.g., List[torch.Tensor]: → "List of...")
  • Added clarity note in README: "Release v0.1.0 is the last version supports Python 3.10"

No functional changes are introduced. The migration is clean, consistent across all files, and aligns with the project's stated goal of dropping Python 3.10 support. All changes are backward-compatible with Python 3.12+.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk. It is a straightforward Python 3.12 migration with no functional changes.
  • Score reflects a clean, well-executed migration with zero functional changes. All modifications are mechanical refactoring: removing compatibility code, updating type annotations to modern syntax, and cleaning up imports. The changes are consistent across all 18 files, properly tested by existing test suite, and align with the project's stated requirements. No backward-compatibility concerns exist since the minimum Python version is now 3.12. The strict mypy configuration ensures all type annotations are correct and complete.
  • No files require special attention. All changes are straightforward refactoring with no risk of introducing bugs.

Important Files Changed

Filename Overview
README.md Updated Python version requirement from 3.10+ to 3.12 (recommended to required), badge updated, and added note about v0.1.0 being the last version to support Python 3.10. Changes are accurate and clearly communicate the new requirement.
pyproject.toml Updated requires-python from ">=3.10" to ">=3.12", removed "typing-extensions" dependency, and updated ruff target-version from "py310" to "py312". All changes are correct and necessary for Python 3.12 requirement.
emerging_optimizers/utils/modules.py Removed try/except fallback for importing override from typing_extensions. Now imports directly from typing module, which is available in Python 3.12+. Change is correct.
emerging_optimizers/scalar_optimizers/ademamix.py Removed unused Optional, Tuple imports. Updated type annotations from Optional[int] to `int
emerging_optimizers/orthogonalized_optimizers/mop.py Removed unused Optional import. Updated return type annotation from Optional[torch.Tensor] to `torch.Tensor
emerging_optimizers/soap/soap_utils.py Added TypeAlias import and created type alias TensorList = list[torch.Tensor]. Simplified docstring return type descriptions (removed List[torch.Tensor]: notation). Changes improve code readability and use modern Python features.

Sequence Diagram

sequenceDiagram
    participant Old as Old Approach<br/>(Python 3.10 Support)
    participant New as New Approach<br/>(Python 3.12 Only)
    
    Note over Old: Try/Except Import Pattern
    Old->>Old: try: from typing import override
    Old->>Old: except ImportError: <br/>from typing_extensions import override
    Note over Old: Module loads compatible version
    
    Note over New: Direct Import Pattern
    New->>New: from typing import override
    Note over New: Guaranteed availability in 3.12+
    
    Note over Old: Type Annotations (Old Style)
    Old->>Old: from typing import List, Tuple, Optional
    Old->>Old: param: List[str]
    Old->>Old: param: Tuple[int, int]
    Old->>Old: param: Optional[int]
    
    Note over New: Type Annotations (Modern Style)
    New->>New: from typing import override
    New->>New: param: list[str]
    New->>New: param: tuple[int, int]
    New->>New: param: int | None
    
    Note over Old: Dependencies
    Old->>Old: torch, absl-py, typing-extensions
    
    Note over New: Dependencies
    New->>New: torch, absl-py
    Note over New: (typing-extensions removed)
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (1)

  1. README.md, line 12 (link)

    logic: Badge still shows Python 3.10+ but documentation now requires Python 3.12

15 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Signed-off-by: Hao Wu <skyw@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (3)

  1. pyproject.toml, line 23 (link)

    logic: Python version requirement should be updated to >=3.12 to match the PR's goal of migrating to Python 3.12. The README and docs now state Python 3.12 is required, but this hasn't been updated here.

  2. pyproject.toml, line 109 (link)

    logic: Ruff target version should be updated from py310 to py312 to reflect the new minimum Python version.

  3. pyproject.toml, line 60 (link)

    logic: typing-extensions is no longer needed as a dependency since the code now requires Python 3.12, which has all the needed typing features built-in (like override). This should be removed.

16 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Hao Wu <skyw@nvidia.com>
@skyw skyw requested a review from a team as a code owner January 20, 2026 19:14
@skyw
Copy link
Contributor Author

skyw commented Jan 20, 2026

/ok to test 6953c88

Copy link
Contributor

@BoxiangW BoxiangW left a comment

Choose a reason for hiding this comment

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

LGTM

@BoxiangW BoxiangW merged commit f77cf31 into main Jan 20, 2026
15 checks passed
@BoxiangW BoxiangW deleted the skyw/python_312 branch January 20, 2026 23:51
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.

3 participants