Skip to content

Cleanup vm/src/stdlib/stat.rs #6018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 25, 2025
Merged

Conversation

ShaharNaveh
Copy link
Contributor

@ShaharNaveh ShaharNaveh commented Jul 22, 2025

Summary by CodeRabbit

  • Refactor
    • Enhanced platform compatibility by unifying file mode and attribute constants across Unix, macOS, and Windows.
    • Grouped Windows file attribute constants for streamlined access and consistency.
    • No changes affecting user-facing features or behavior.

Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

Walkthrough

This change refactors the platform-specific constant definitions in the stat module. It consolidates duplicated Unix and macOS constants using macros, re-exports Windows file attribute constants collectively, and simplifies conditional compilation logic. No functions or control flow are changed; only the way constants are defined and exposed is updated.

Changes

File(s) Change Summary
vm/src/stdlib/stat.rs Refactored platform-specific constant definitions using a libc_const! macro and conditional expressions for Unix/macOS constants; replaced individual Windows constant declarations with a single re-export block; removed duplicated conditional blocks; no changes to logic or function signatures.

Sequence Diagram(s)

No sequence diagram generated as the changes are limited to constant definitions and do not affect control flow or introduce new features.

Estimated code review effort

3 (~45 minutes)

Possibly related PRs

Poem

In the meadow of macros, I hop with glee,
Constants now tidy, as neat as can be.
No more tangled branches, just one simple view,
Whether Unix or Windows, the code feels like new.
With a twitch of my nose and a soft bunny cheer,
Refactoring’s done—let’s celebrate here! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

#[pyattr]
pub const S_IFREG: Mode = 0o100000;
pub const S_IFDIR: Mode = unix_libc_get!(S_IFDIR, 0o040000);
Copy link
Member

Choose a reason for hiding this comment

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

This is a good idea! Looks a lot better than before.

I have a suggestion for the macro interface. How about this?

Suggested change
pub const S_IFDIR: Mode = unix_libc_get!(S_IFDIR, 0o040000);
pub const S_IFDIR: Mode = libc_const!(#[cfg(unix)] S_IFDIR, 0o040000);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm on the fence about this one, as it is clear. but will require to put it for every const definition, I tried to make it less verbose overall as there's no reason to do it imo.

That's why I defined two macros that are the same except the condition inside the cfg_if::cfg_if macro.


I tried to do this cleanup using couple of ways such as:

#[cfg(unix)]
mod maybe_unix {
  pub use libc::{A, B, C};
}

#[cfg(not(unix))]
mod maybe_unix {
  pub const A:Mode = 1;
  ...
}

mod stat {
  #[pyattr]
  pub use maybe_unix::{A, B, C};
}

But I decided to drop it as it would require to sync between 3 places (2 modules, and the stat module).


I also tried to have the cfg condition to be passed as an optional argument to the macro, but then I encountered some weird issues with #[pyattr].


At the end this is the best compromise that I found, unless you have a better idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried to implement the macro based on the suggested interface. I'm unsure how this would work. can you help me out here how do you envision the macro to look like?

Copy link
Member

Choose a reason for hiding this comment

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

Does current version make sense?

I also tried libc_const!(@unix S_IFDIR, 0o040000); and libc_const!(@macos UF_NODUMP, 0x00000001);, to make a balance of concise forms, but not confident about readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current version looks way better than mine, clearly you have more experience 😆

#[pyattr]
pub const S_IEXEC: Mode = 0o0100;
pub const UF_NODUMP: u32 = macos_libc_get!(UF_NODUMP, 0x00000001);
Copy link
Member

Choose a reason for hiding this comment

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

Then this one also will have the same pattern

Suggested change
pub const UF_NODUMP: u32 = macos_libc_get!(UF_NODUMP, 0x00000001);
pub const UF_NODUMP: u32 = libc_const!(#[cfg(target_os = "macos")] UF_NODUMP, 0x00000001);

@ShaharNaveh ShaharNaveh marked this pull request as ready for review July 22, 2025 12:08
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)
vm/src/stdlib/stat.rs (1)

13-46: Consider consolidating the two macros to reduce duplication.

While this refactoring improves upon the previous approach, both unix_libc_get! and macos_libc_get! have identical implementations. I understand from the past discussion that you encountered issues with #[pyattr] when trying to pass the cfg condition as a parameter.

As an alternative to the current approach or the inline cfg attribute suggestion, consider using a single macro with a naming convention:

-    // unix_libc_get
-    cfg_if::cfg_if! {
-        if #[cfg(unix)] {
-            macro_rules! unix_libc_get {
-                ($name:ident, $val:expr) => {
-                    libc::$name
-                };
-            }
-        } else {
-            macro_rules! unix_libc_get {
-                ($name:ident, $val:expr) => {
-                    $val
-                };
-            }
-        }
-
-    }
-
-    // macos_libc_get
-    cfg_if::cfg_if! {
-        if #[cfg(target_os = "macos")] {
-            macro_rules! macos_libc_get {
-                ($name:ident, $val:expr) => {
-                    libc::$name
-                };
-            }
-        } else {
-            macro_rules! macos_libc_get {
-                ($name:ident, $val:expr) => {
-                    $val
-                };
-            }
-        }
-    }
+    macro_rules! platform_const {
+        (unix $name:ident, $val:expr) => {
+            {
+                #[cfg(unix)]
+                let value = libc::$name;
+                #[cfg(not(unix))]
+                let value = $val;
+                value
+            }
+        };
+        (macos $name:ident, $val:expr) => {
+            {
+                #[cfg(target_os = "macos")]
+                let value = libc::$name;
+                #[cfg(not(target_os = "macos"))]
+                let value = $val;
+                value
+            }
+        };
+    }

This would allow usage like: pub const S_IFDIR: Mode = platform_const!(unix S_IFDIR, 0o040000);

However, if this approach also has issues with #[pyattr], the current solution is acceptable.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57bdf35 and 116beaa.

📒 Files selected for processing (1)
  • vm/src/stdlib/stat.rs (1 hunks)
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your 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:

  • vm/src/stdlib/stat.rs
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Follow Rust best practices for error handling and memory management
Learnt from: moreal
PR: RustPython/RustPython#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
PR: RustPython/RustPython#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.
vm/src/stdlib/stat.rs (5)

Learnt from: moreal
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
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.

Learnt from: arihant2math
PR: #5790
File: build.rs:2-2
Timestamp: 2025-06-28T16:31:03.991Z
Learning: In Cargo build scripts (build.rs), the environment variable CARGO_CFG_TARGET_OS is guaranteed to exist and is automatically set by Cargo during the build process, making unwrap() safe to use when accessing this variable.

Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Follow Rust best practices for error handling and memory management

Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your 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:

  • vm/src/stdlib/stat.rs
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Follow Rust best practices for error handling and memory management
Learnt from: moreal
PR: RustPython/RustPython#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
PR: RustPython/RustPython#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.
vm/src/stdlib/stat.rs (5)

Learnt from: moreal
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
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.

Learnt from: arihant2math
PR: #5790
File: build.rs:2-2
Timestamp: 2025-06-28T16:31:03.991Z
Learning: In Cargo build scripts (build.rs), the environment variable CARGO_CFG_TARGET_OS is guaranteed to exist and is automatically set by Cargo during the build process, making unwrap() safe to use when accessing this variable.

Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Follow Rust best practices for error handling and memory management

Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

🔇 Additional comments (4)
vm/src/stdlib/stat.rs (4)

48-137: Clean consolidation of Unix mode constants!

The refactoring successfully eliminates the duplicate #[cfg(unix)] and #[cfg(not(unix))] declarations while maintaining the correct constant values. The approach is consistent and improves maintainability.


139-158: Appropriate use of inline cfg_if! for complex platform conditions.

The inline cfg_if! blocks are the right choice here since these constants require more specific platform checks (excluding Android and Redox) that don't fit the simple unix_libc_get! pattern.


162-171: Excellent simplification of Windows constants!

Re-exporting the constants directly from windows_sys is a much cleaner approach than individually declaring each constant. This ensures the values stay in sync with the Windows API definitions.


175-232: Well-structured platform-specific constant definitions.

The implementation correctly:

  • Uses macos_libc_get! for macOS-preferring constants
  • Applies platform-specific values for SF_SETTABLE
  • Follows the learning about conditionally declaring SF_SUPPORTED and SF_SYNTHETIC only for macOS
  • Defines cross-platform constants directly when they have fixed values

This approach aligns with CPython's platform-specific constant handling.

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 (2)
vm/src/stdlib/stat.rs (2)

86-90: Consider using libc_const! macro for consistency.

For consistency with other constants, consider using the libc_const! macro pattern:

-pub const S_IFWHT: Mode = if cfg!(target_os = "macos") {
-    0o160000
-} else {
-    0
-};
+pub const S_IFWHT: Mode = libc_const!(
+    #[cfg(target_os = "macos")]
+    S_IFWHT,
+    0
+);

306-310: Consider using libc_const! macro for consistency.

Similar to S_IFWHT, SF_SETTABLE could use the macro pattern for consistency:

-pub const SF_SETTABLE: u32 = if cfg!(target_os = "macos") {
-    0x3fff0000
-} else {
-    0xffff0000
-};
+pub const SF_SETTABLE: u32 = libc_const!(
+    #[cfg(target_os = "macos")]
+    SF_SETTABLE,
+    0xffff0000
+);
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 116beaa and 8842db8.

📒 Files selected for processing (1)
  • vm/src/stdlib/stat.rs (1 hunks)
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your 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:

  • vm/src/stdlib/stat.rs
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Follow Rust best practices for error handling and memory management
Learnt from: moreal
PR: RustPython/RustPython#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
PR: RustPython/RustPython#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.
vm/src/stdlib/stat.rs (5)

Learnt from: moreal
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
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.

Learnt from: arihant2math
PR: #5790
File: build.rs:2-2
Timestamp: 2025-06-28T16:31:03.991Z
Learning: In Cargo build scripts (build.rs), the environment variable CARGO_CFG_TARGET_OS is guaranteed to exist and is automatically set by Cargo during the build process, making unwrap() safe to use when accessing this variable.

Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Follow Rust best practices for error handling and memory management

Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your 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:

  • vm/src/stdlib/stat.rs
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Follow Rust best practices for error handling and memory management
Learnt from: moreal
PR: RustPython/RustPython#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
PR: RustPython/RustPython#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.
vm/src/stdlib/stat.rs (5)

Learnt from: moreal
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
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.

Learnt from: arihant2math
PR: #5790
File: build.rs:2-2
Timestamp: 2025-06-28T16:31:03.991Z
Learning: In Cargo build scripts (build.rs), the environment variable CARGO_CFG_TARGET_OS is guaranteed to exist and is automatically set by Cargo during the build process, making unwrap() safe to use when accessing this variable.

Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Follow Rust best practices for error handling and memory management

Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

🔇 Additional comments (3)
vm/src/stdlib/stat.rs (3)

14-25: LGTM!

The libc_const! macro implementation is clean and follows the pattern discussed in previous reviews. It properly handles conditional compilation with appropriate fallbacks.


229-238: Excellent refactoring of Windows constants!

Re-exporting Windows file attributes collectively is much cleaner than individual declarations. This reduces code duplication and improves maintainability.


329-335: Correct implementation of platform-specific constants!

The macOS-specific constants SF_SUPPORTED and SF_SYNTHETIC are properly conditionally declared only for macOS, following CPython's approach as mentioned in the retrieved learnings. This is the correct pattern for platform-specific constants.

Copy link
Contributor Author

@ShaharNaveh ShaharNaveh left a comment

Choose a reason for hiding this comment

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

LGTM:)

@youknowone youknowone merged commit 6bce5e1 into RustPython:main Jul 25, 2025
12 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