Skip to content

FutureFeature enum - #8185

Merged
youknowone merged 3 commits into
RustPython:mainfrom
ShaharNaveh:codegen-future-feature-enum
Jun 30, 2026
Merged

FutureFeature enum#8185
youknowone merged 3 commits into
RustPython:mainfrom
ShaharNaveh:codegen-future-feature-enum

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Summary by CodeRabbit

  • New Features
    • More robust handling of from __future__ import ... by reliably recognizing supported feature names.
  • Bug Fixes
    • Invalid future-feature names now produce clearer errors, including the exact location of the problematic import.
    • Preserved existing special-case behavior (including braces) and ensured previously-supported flags continue to behave the same.
  • Refactor
    • Centralized future-feature parsing/validation into a consistent internal representation for preprocessing.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 1f1ae9db-5ae1-4cf7-94d6-2b2502b39ab5

📥 Commits

Reviewing files that changed from the base of the PR and between b68f0e2 and 1bb8fa9.

📒 Files selected for processing (1)
  • crates/codegen/src/preprocess.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/codegen/src/preprocess.rs

📝 Walkthrough

Walkthrough

A shared FutureFeature enum is added for known __future__ names, and compile-time and preprocess-time handling now parse feature strings through it. Unknown names are reported through the new conversion path.

Changes

FutureFeature parsing and preprocessing

Layer / File(s) Summary
FutureFeature enum and TryFrom
crates/codegen/src/compile.rs
Defines the public FutureFeature enum with variants for known __future__ feature names and a TryFrom<&str> impl returning Err(name) for unknown names.
Compile uses FutureFeature
crates/codegen/src/compile.rs
Converts compile-time future-feature handling from raw string matching to FutureFeature::try_from() and enum matching, while preserving the existing handling for recognized features and reporting unknown names with source ranges.
Preprocess uses FutureFeature
crates/codegen/src/preprocess.rs
Imports FutureFeature, parses imported __future__ names through try_into(), maps invalid names and braces to the existing preprocess errors, and updates AstPreprocessor derives and visit_astfold_body ownership.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hops through future flags with glee,
New names are sorted cleanly, one-two-three.
try_into() hums through the warren bright,
And errors land where they should light.
The code now sniffs the future with a grin 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly describes the main addition introduced by the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/codegen/src/compile.rs (1)

204-287: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse FutureFeature in preprocess.rs as well.

crates/codegen/src/preprocess.rs:196-258 still hardcodes the same __future__ names. Keeping two independent lists means the precheck and codegen paths can drift the next time a feature is added or renamed. Consider moving that path to the enum too so there is a single source of truth.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/codegen/src/compile.rs` around lines 204 - 287, `FutureFeature` is now
the single source of truth for `__future__` names, but `preprocess.rs` still
maintains a separate hardcoded list. Update the `preprocess` path to use
`FutureFeature::try_from` (or otherwise reference `FutureFeature` directly)
instead of duplicating the feature names, so both preprocessing and codegen stay
aligned when `FutureFeature` changes. Keep the existing behavior in the
preprocessing logic, but route name validation/matching through the enum and its
variants rather than a second list.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/codegen/src/compile.rs`:
- Around line 204-287: `FutureFeature` is now the single source of truth for
`__future__` names, but `preprocess.rs` still maintains a separate hardcoded
list. Update the `preprocess` path to use `FutureFeature::try_from` (or
otherwise reference `FutureFeature` directly) instead of duplicating the feature
names, so both preprocessing and codegen stay aligned when `FutureFeature`
changes. Keep the existing behavior in the preprocessing logic, but route name
validation/matching through the enum and its variants rather than a second list.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 86ae9578-dc47-408c-b911-5ebf302e01d2

📥 Commits

Reviewing files that changed from the base of the PR and between 0009dd6 and b7bcf43.

📒 Files selected for processing (1)
  • crates/codegen/src/compile.rs

@ShaharNaveh
ShaharNaveh force-pushed the codegen-future-feature-enum branch from b7bcf43 to a97f0fe Compare June 28, 2026 09:57
@youknowone
youknowone merged commit eae567f into RustPython:main Jun 30, 2026
26 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