Skip to content

Support Python 3.9#1287

Merged
sbryngelson merged 2 commits intoMFlowCode:masterfrom
sbryngelson:python39
Mar 3, 2026
Merged

Support Python 3.9#1287
sbryngelson merged 2 commits intoMFlowCode:masterfrom
sbryngelson:python39

Conversation

@sbryngelson
Copy link
Copy Markdown
Member

Summary

  • Add from __future__ import annotations to 4 files using PEP 604 union type syntax (X | Y), which requires Python 3.10+ at runtime but works on 3.7+ with deferred evaluation
  • Lower the bootstrap Python version gate from 3.10 to 3.9
  • Add Python 3.9 to the toolchain compatibility CI matrix

Test plan

  • ./mfc.sh lint passes on Python 3.9.21
  • ./mfc.sh precheck passes on Python 3.9.21
  • CI toolchain compat matrix (now includes 3.9)

sbryngelson and others added 2 commits March 2, 2026 18:40
Add `from __future__ import annotations` to three files that use
PEP 604 union type syntax (`X | Y`), which requires Python 3.10+
at runtime but works on 3.7+ with deferred evaluation. Also add
Python 3.9 to the toolchain compatibility CI matrix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…strap gate from 3.10 to 3.9

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

Claude Code Review

Head SHA: fe3fb26

Files changed: 6

  • .github/workflows/test-toolchain-compat.yml
  • docs/postprocess_citations.py
  • toolchain/bootstrap/python.sh
  • toolchain/mfc/gen_case_constraints_docs.py
  • toolchain/mfc/params/ast_analyzer.py
  • toolchain/mfc/params/generators/docs_gen.py

Summary

  • Adds Python 3.9 support by lowering the minimum version gate from 3.10 to 3.9
  • Uses from __future__ import annotations (PEP 563) to enable deferred annotation evaluation, allowing PEP 604 X | Y union syntax to work on Python 3.9
  • Adds Python 3.9 to the CI toolchain compatibility matrix
  • Small diff (10 additions, 2 deletions) with clear, well-scoped intent

Findings

1. Incomplete coverage of from __future__ import annotations

The PR adds the future import to 4 files, but there may be other files in the toolchain that also use X | Y union syntax or modern type hint features without this guard. For example, toolchain/mfc/params/generators/docs_gen.py already imports from typing import Any, Dict, List, Tuple (the older-style typing), but other files in the toolchain that use newer syntax may have been missed.

Recommend running a grep before merging to confirm no other files need the same treatment:

grep -rn '|' toolchain/ docs/ --include='*.py' | grep -E 'def |: ' | grep -v '__future__'

Or more precisely:

grep -rn ' | None\b\|: \w\+ | \w\+' toolchain/ docs/ --include='*.py'

2. Minor: docs_gen.py still uses legacy typing imports (low priority)

toolchain/mfc/params/generators/docs_gen.py imports from typing import Any, Dict, List, Tuple — the old pre-3.9 style. With Python 3.9+ as the new minimum and from __future__ import annotations now present, these could be modernized to dict, list, tuple builtins. This is not a correctness issue and is out of scope for this PR, but worth noting for a future cleanup.


No blocking issues found

The approach is correct: from __future__ import annotations is the standard, backwards-compatible way to enable PEP 604-style union syntax on Python 3.7–3.9. The bootstrap version gate change is consistent with the stated goal. CI matrix addition is appropriate.

@sbryngelson sbryngelson marked this pull request as ready for review March 3, 2026 02:27
Copilot AI review requested due to automatic review settings March 3, 2026 02:27
@sbryngelson sbryngelson merged commit 472a0de into MFlowCode:master Mar 3, 2026
30 of 35 checks passed
@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Support Python 3.9 with deferred annotation evaluation

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add from __future__ import annotations to 4 Python files for PEP 604 union syntax support
• Lower minimum Python version requirement from 3.10 to 3.9
• Add Python 3.9 to CI toolchain compatibility test matrix
Diagram
flowchart LR
  A["Python 3.9 Support"] --> B["Add future annotations<br/>to 4 files"]
  A --> C["Lower bootstrap<br/>gate to 3.9"]
  A --> D["Update CI matrix<br/>to include 3.9"]
  B --> E["Enable PEP 604<br/>union syntax"]
Loading

Grey Divider

File Changes

1. docs/postprocess_citations.py ✨ Enhancement +2/-0

Add future annotations import

• Add from __future__ import annotations import at module top
• Enables PEP 604 union type syntax on Python 3.9+

docs/postprocess_citations.py


2. toolchain/mfc/gen_case_constraints_docs.py ✨ Enhancement +2/-0

Add future annotations import

• Add from __future__ import annotations import at module top
• Enables PEP 604 union type syntax on Python 3.9+

toolchain/mfc/gen_case_constraints_docs.py


3. toolchain/mfc/params/ast_analyzer.py ✨ Enhancement +2/-0

Add future annotations import

• Add from __future__ import annotations import at module top
• Enables PEP 604 union type syntax on Python 3.9+

toolchain/mfc/params/ast_analyzer.py


View more (3)
4. toolchain/mfc/params/generators/docs_gen.py ✨ Enhancement +2/-0

Add future annotations import

• Add from __future__ import annotations import at module top
• Enables PEP 604 union type syntax on Python 3.9+

toolchain/mfc/params/generators/docs_gen.py


5. toolchain/bootstrap/python.sh ⚙️ Configuration changes +1/-1

Lower minimum Python version to 3.9

• Lower MFC_PYTHON_MIN_MINOR from 10 to 9
• Updates minimum Python version requirement to 3.9

toolchain/bootstrap/python.sh


6. .github/workflows/test-toolchain-compat.yml ⚙️ Configuration changes +1/-1

Add Python 3.9 to CI test matrix

• Add Python 3.9 to the start of test matrix versions
• CI now tests compatibility with Python 3.9 through 3.14

.github/workflows/test-toolchain-compat.yml


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Mar 3, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Automation docs still say 3.10+ 🐞 Bug ⛯ Reliability
Description
The PR lowers the bootstrap minimum Python version to 3.9, but repo automation/reviewer instruction
files still say the toolchain requires Python 3.10+ and explicitly discourage __future__ imports.
This inconsistency can confuse contributors and cause automated review tooling to give guidance that
conflicts with the new 3.9 compatibility approach.
Code

toolchain/bootstrap/python.sh[4]

+MFC_PYTHON_MIN_MINOR=9
Evidence
toolchain/bootstrap/python.sh is the user-facing gatekeeper for Python compatibility and now
allows Python 3.9+. However, .coderabbit.yaml and .pr_agent.toml still encode Python 3.10+ as
the minimum and instruct not to suggest __future__ imports—yet this PR uses exactly that technique
to support 3.9. Keeping these instructions stale increases the risk of contradictory automated
feedback during PR review.

toolchain/bootstrap/python.sh[3-6]
.coderabbit.yaml[53-56]
.pr_agent.toml[23-26]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The repo now supports Python 3.9 for the toolchain, but the automation/reviewer instruction configs still claim Python 3.10+ is required and explicitly discourage `__future__` imports. This conflicts with the PR’s compatibility approach.

### Issue Context
These instruction files guide automated review agents and can cause confusing or contradictory guidance during future PRs.

### Fix Focus Areas
- .coderabbit.yaml[53-56]
- .pr_agent.toml[21-26]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

Claude Code Review

Head SHA: fe3fb26

Files changed: 6

  • .github/workflows/test-toolchain-compat.yml
  • docs/postprocess_citations.py
  • toolchain/bootstrap/python.sh
  • toolchain/mfc/gen_case_constraints_docs.py
  • toolchain/mfc/params/ast_analyzer.py
  • toolchain/mfc/params/generators/docs_gen.py

Summary:

  • Adds Python 3.9 support by inserting from __future__ import annotations in 4 files that use PEP 604 union type syntax (X | Y), enabling deferred annotation evaluation on Python 3.7+
  • Lowers the bootstrap minimum Python version gate from 3.10 to 3.9
  • Adds Python 3.9 to the CI toolchain compatibility matrix

Findings:

No correctness issues found. The approach is sound: from __future__ import annotations (PEP 563) defers evaluation of type annotations, allowing X | Y union syntax to work on Python 3.9 even though runtime X | Y union types (types.UnionType) require Python 3.10+.

Improvement opportunities:

  1. toolchain/mfc/params/generators/docs_gen.py — redundant legacy imports: With from __future__ import annotations in place, the from typing import Any, Dict, List, Tuple imports may be replaceable with the built-in lowercase generics (dict, list, tuple) that work on 3.9+ when annotations are strings. This is a minor cleanup opportunity, not a blocker.

  2. Scan completeness: The PR targets 4 files with X | Y syntax, but it's worth confirming no other toolchain files use bare X | Y union types without the __future__ import. If all occurrences have been covered, this is fine.

  3. Python 3.9 EOL: Python 3.9 reached end-of-life on 2025-10-05. Supporting it broadens compatibility but the window of practical benefit is narrow. This is a policy question for the maintainers, not a code defect.

Overall: The changes are minimal, correct, and well-scoped. Approve.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 3, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c806be and fe3fb26.

📒 Files selected for processing (6)
  • .github/workflows/test-toolchain-compat.yml
  • docs/postprocess_citations.py
  • toolchain/bootstrap/python.sh
  • toolchain/mfc/gen_case_constraints_docs.py
  • toolchain/mfc/params/ast_analyzer.py
  • toolchain/mfc/params/generators/docs_gen.py

📝 Walkthrough

Walkthrough

This pull request extends Python 3.9 support across the codebase. The minimum Python version requirement is lowered from 3.10 to 3.9 in the bootstrap configuration, and the GitHub Actions test matrix is updated to include Python 3.9 testing alongside versions 3.10 through 3.14. Additionally, multiple Python source files are updated to include postponed evaluation of type annotations through future imports, ensuring consistency and forward compatibility with Python's typing system.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to extend the Python toolchain/aux scripts to run on Python 3.9 by adjusting version gating, updating CI, and attempting to address Python 3.10-only typing syntax usage.

Changes:

  • Add from __future__ import annotations to four Python modules/scripts.
  • Lower the bootstrap minimum Python version from 3.10 to 3.9.
  • Expand the toolchain compatibility CI matrix to include Python 3.9.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
toolchain/mfc/params/generators/docs_gen.py Adds postponed-annotations future import to support typing usage.
toolchain/mfc/params/ast_analyzer.py Adds postponed-annotations future import to support typing usage.
toolchain/mfc/gen_case_constraints_docs.py Adds postponed-annotations future import to support typing usage.
toolchain/bootstrap/python.sh Lowers the bootstrap Python version gate to 3.9.
docs/postprocess_citations.py Adds postponed-annotations future import to support typing usage.
.github/workflows/test-toolchain-compat.yml Adds Python 3.9 to the CI compatibility matrix.
Comments suppressed due to low confidence (2)

toolchain/mfc/params/ast_analyzer.py:16

  • Adding from __future__ import annotations does not make X | Y type annotations compatible with Python 3.9 (they are a 3.10 grammar feature). This file still uses str | None (e.g., self.current_method: str | None), which will be a SyntaxError on 3.9. Replace these with Optional[str] / Union[...] (or string-literal annotations) to truly support 3.9.
from __future__ import annotations

import ast
import re
from dataclasses import dataclass, field
from pathlib import Path
from typing import Dict, List, Optional, Set

toolchain/mfc/gen_case_constraints_docs.py:18

  • from __future__ import annotations does not allow PEP 604 union syntax (X | Y) on Python 3.9; the parser will still raise SyntaxError. This script still declares unions like int | None in type annotations, so lowering the minimum Python version won’t work until those are rewritten (e.g., Optional[int]).
from __future__ import annotations

import json
import sys
import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, List, Iterable, Any

Comment on lines +10 to 14
from __future__ import annotations

import re
import sys
from pathlib import Path
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

Python 3.9 cannot parse PEP 604 union type syntax (X | Y) even with from __future__ import annotations. This module still contains annotations like tuple[str, int, str | None], which will be a SyntaxError on 3.9. Replace these unions with Optional[...]/Union[...] (or quote the annotation expressions) if 3.9 support is intended.

Copilot uses AI. Check for mistakes.
Comment on lines 3 to 5
MFC_PYTHON_MIN_MAJOR=3
MFC_PYTHON_MIN_MINOR=10
MFC_PYTHON_MIN_MINOR=9
MFC_PYTHON_MIN_STR="$MFC_PYTHON_MIN_MAJOR.$MFC_PYTHON_MIN_MINOR"
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

Lowering the bootstrap minimum to Python 3.9 conflicts with the current codebase: several modules still contain PEP 604 union annotations (X | Y), which are a Python 3.10+ syntax feature and will raise SyntaxError on 3.9 regardless of from __future__ import annotations. Either keep the minimum at 3.10, or fully migrate those annotations to typing.Optional/typing.Union (and verify dependencies support 3.9) before lowering this gate.

Copilot uses AI. Check for mistakes.
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

Adding Python 3.9 to the CI matrix will currently fail because parts of the codebase still use Python 3.10-only syntax in type annotations (X | Y). Either land the annotation migration in the same PR (so the job passes), or keep 3.9 out of the matrix until the code is actually parseable on 3.9.

Suggested change
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +9
from __future__ import annotations

Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

from __future__ import annotations does not make PEP 604 union syntax (X | Y) parse on Python 3.9; it only changes annotation evaluation. This file still contains a Dict[str, list] | None annotation, which will raise SyntaxError on 3.9. To actually support 3.9, rewrite these unions using typing.Optional/typing.Union (or quote the annotation expressions), and then drop the future import if it’s no longer needed.

Suggested change
from __future__ import annotations

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.95%. Comparing base (7c806be) to head (fe3fb26).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1287   +/-   ##
=======================================
  Coverage   44.95%   44.95%           
=======================================
  Files          70       70           
  Lines       20503    20503           
  Branches     1946     1946           
=======================================
  Hits         9217     9217           
  Misses      10164    10164           
  Partials     1122     1122           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

sbryngelson pushed a commit to sbryngelson/MFC that referenced this pull request Mar 4, 2026
Extend AMD-only VLA guards to also cover CCE 19.0.0 in all four
locations in m_chemistry.fpp:
- s_compute_q_T_sf: add USING_CCE guard for Ys array
- s_compute_T_from_primitives: add USING_CCE guard for Ys array
- s_compute_chemistry_reaction_flux: extend AMD guard to include CCE
- s_compute_chemistry_diffusion_flux: extend AMD guard to include CCE

CCE 19.0.0 LLVM InstCombine (foldIntegerTypedPHI) crashes on VLAs
(dimension(num_species)) when num_species is not a compile-time
constant (e.g., case-optimized pre_process for non-chemistry cases).
Fixed by using dimension(10) when USING_CCE.

Also restore MFC_PYTHON_MIN_MINOR=9 in python.sh (was accidentally
set to 10 in 3d8cf31; PR MFlowCode#1287 merged to master adds Python 3.9 support).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sbryngelson sbryngelson deleted the python39 branch March 17, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants