Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Dec 8, 2025

Summary by CodeRabbit

Release Notes

  • New Features
    • Enhanced os.stat() to expose file attributes information. Windows systems now provide detailed file metadata through stat results, while other platforms include default values to maintain consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

A new public field st_file_attributes (u32) has been added to the StatResultData structure to store Windows-specific file attributes. The field is populated from stat.st_file_attributes on Windows and defaults to 0 on non-Windows platforms, mirroring the existing st_reparse_tag pattern.

Changes

Cohort / File(s) Change Summary
Windows file attributes support
crates/vm/src/stdlib/os.rs
Added public field st_file_attributes: u32 to StatResultData struct; initialized from Windows stat data or defaulted to 0 on non-Windows platforms within StatResultData::from_stat implementation

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

  • Single file modification with straightforward field addition and platform-specific initialization following established patterns

Possibly related PRs

Poem

🐰 A field hops in, so clean and small,
Windows attributes, stored for all,
Zero on Unix, the defaults align,
StatResultData grows just fine! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'st_file_attributes' is overly vague and generic, using a single technical term without context about what change is being made to it. Use a more descriptive title that explains the purpose, such as 'Add st_file_attributes field to StatResultData' or 'Extend os.stat with Windows file attributes support'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@youknowone youknowone marked this pull request as ready for review December 8, 2025 16:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
crates/vm/src/stdlib/os.rs (1)

818-822: Windows/non-Windows initialization pattern is consistent but check desired API semantics

The cfg-gated initialization:

  • Uses stat.st_file_attributes on Windows.
  • Falls back to 0 on non-Windows.

This mirrors the existing st_reparse_tag handling and is compile-time safe. The only open design question is whether you want the attribute to exist (with value 0) on non-Windows, or to follow CPython’s pattern of only exposing some stat-related items on platforms that support them. If closer CPython parity is desired, you might consider gating the attribute itself behind #[cfg(windows)] instead of defaulting to 0 elsewhere (similar to how platform-specific constants are conditionally exposed in stat.rs). Based on learnings, this is more of a design/alignment choice than a correctness issue.

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3d638a and 5a5944b.

⛔ Files ignored due to path filters (2)
  • Lib/test/test_os.py is excluded by !Lib/**
  • Lib/test/test_site.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/vm/src/stdlib/os.rs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style by running cargo fmt to format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

Files:

  • crates/vm/src/stdlib/os.rs
🧠 Learnings (3)
📓 Common learnings
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration rather than providing fallback values for other platforms.
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.

Applied to files:

  • crates/vm/src/stdlib/os.rs
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration rather than providing fallback values for other platforms.

Applied to files:

  • crates/vm/src/stdlib/os.rs
🧬 Code graph analysis (1)
crates/vm/src/stdlib/os.rs (2)
crates/derive-impl/src/lib.rs (1)
  • pystruct_sequence (61-63)
crates/derive/src/lib.rs (1)
  • pystruct_sequence (235-239)
🔇 Additional comments (2)
crates/vm/src/stdlib/os.rs (2)

781-783: StatResultData gains st_file_attributes with appropriate typing and defaults

Adding pub st_file_attributes: u32 with #[pyarg(any, default)] and #[pystruct_sequence(skip)] is consistent with how st_reparse_tag is modeled, and the u32 type matches the underlying Win32 file-attribute representation. I don’t see issues with this field definition.


841-842: Struct initialization correctly threads through st_file_attributes

Including st_file_attributes in the Self { ... } initializer ensures the new field is always populated from the cfg-gated local variable. This keeps StatResultData::from_stat self-contained and in sync with the struct definition.

@youknowone youknowone merged commit a484ba4 into RustPython:main Dec 8, 2025
13 checks passed
@youknowone youknowone deleted the st_file_attributes branch December 8, 2025 17:49
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.

1 participant