◐ Shell
reader mode source ↗
Skip to content

Add symtable.py from 3.13.5#6048

Merged
youknowone merged 11 commits into
RustPython:mainfrom
ShaharNaveh:update-symtable
Aug 1, 2025
Merged

Add symtable.py from 3.13.5#6048
youknowone merged 11 commits into
RustPython:mainfrom
ShaharNaveh:update-symtable

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added a comprehensive set of symbol and scope constants to the symbol table module, now accessible as Python attributes.
  • Refactor

    • Simplified the PySymbolTable interface by replacing several explicit methods with Python-style properties.
    • Renamed and adjusted properties for easier access to attributes like name, type, line number, children, identifiers, symbols, nested status, and a new id property.
  • Chores

    • Updated the module registration name from "symtable" to "_symtable".

@coderabbitai

coderabbitai Bot commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update the symbol table module in the standard library. The module's registration key is renamed from "symtable" to "_symtable". The PySymbolTable class is refactored to use property getters instead of explicit methods, adds symbol table constants, and removes or renames several methods to align with Python conventions.

Changes

Cohort / File(s) Change Summary
Module Registration Key Update
vm/src/stdlib/mod.rs
Renamed the symbol table module registration key from "symtable" to "_symtable" in the standard library initialization map.
Symbol Table Refactor & Constants
vm/src/stdlib/symtable.rs
Added symbol and scope constants reflecting CPython internals; refactored PySymbolTable to use Python-style property getters instead of explicit methods; removed methods like lookup and has_children; added new properties including id, nested, children, identifiers, and symbols; changed method signatures and names for consistency.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

In the warren where symbols dwell,
A rabbit hops with tales to tell.
Properties bloom where methods once grew,
Constants abound, all shiny and new.
"_symtable" whispers with pride—
Refactored and tidy, with nothing to hide!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 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 generate unit tests to generate unit tests for 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.

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

Did we have test_symtable but no symtable.py? How did it work before?

@ShaharNaveh

Copy link
Copy Markdown
Contributor Author

Did we have test_symtable but no symtable.py?

Correct

How did it work before?

We had implemented symtable.py in rust:)

@ShaharNaveh ShaharNaveh marked this pull request as draft July 30, 2025 12:35
@ShaharNaveh ShaharNaveh marked this pull request as ready for review July 30, 2025 16:43

@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.

Hide comment

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 09a7fcf and 16f7737.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_symtable.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • vm/src/stdlib/symtable.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 (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/symtable.rs
🧠 Learnings (1)
vm/src/stdlib/symtable.rs (3)

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: 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/symtable.rs (4)

5-11: LGTM!

The import additions are appropriate for the new functionality - PyDictRef supports the symbols property and the explicit compiler import improves code clarity.


13-105: Excellent alignment with CPython's symtable constants.

The comprehensive set of constants mirrors CPython's internal symtable definitions, ensuring compatibility. The bit-shifting patterns and flag combinations are mathematically correct and follow established conventions.


144-184: Excellent refactoring to Python-style properties.

The conversion from explicit methods to properties using #[pygetset] aligns perfectly with Python conventions. The use of #[pygetset(name = "type")] properly handles Rust keyword conflicts.


186-194: Clean implementation of symbols property.

The new symbols property correctly creates a dictionary mapping symbol names to their flag bits, providing a proper Python-style interface to the symbol information.

@ShaharNaveh ShaharNaveh requested a review from youknowone July 31, 2025 15:15
@ShaharNaveh ShaharNaveh requested a review from youknowone August 1, 2025 09:37

@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.

Hide comment

Actionable comments posted: 2

♻️ Duplicate comments (1)
vm/src/stdlib/symtable.rs (1)

181-184: Security concern with id() method exposing raw memory addresses.

The id() method returns raw memory addresses, which could potentially be used for memory layout attacks or information disclosure in security-sensitive contexts.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 16f7737 and e66d264.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_symtable.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • vm/src/stdlib/symtable.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 (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/symtable.rs
🧠 Learnings (3)
📚 Learning: in rustpython's stat module implementation, platform-specific constants like sf_supported and sf_syn...
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.

Applied to files:

  • vm/src/stdlib/symtable.rs
📚 Learning: in rustpython's stat module implementation, platform-specific constants like sf_supported and sf_syn...
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.

Applied to files:

  • vm/src/stdlib/symtable.rs
📚 Learning: applies to **/*.rs : use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implement...
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

Applied to files:

  • vm/src/stdlib/symtable.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run tests under miri
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Ensure compilation on various targets
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Check Rust code with rustfmt and clippy
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Run rust tests (ubuntu-latest)
🔇 Additional comments (5)
vm/src/stdlib/symtable.rs (5)

149-152: LGTM! Method to property conversion aligns with feedback.

Converting get_name to a name property using #[pygetset] aligns well with the previous review feedback to use getset instead of deleting methods.


171-179: LGTM! Children property correctly replaces get_children method.

The children property properly converts sub-tables to Python objects and aligns with the goal of using properties instead of explicit methods.


186-195: LGTM! Identifiers property conversion is appropriate.

Converting get_identifiers to an identifiers property maintains the same functionality while following the property-based interface pattern.


207-210: LGTM! Nested property appropriately replaces is_nested method.

The nested property correctly exposes the symbol table's nested status, following the pattern established by other property conversions.


15-110: Constants section matches CPython internal definitions

The bit shifts and composite values (e.g. DEF_BOUND, SCOPE_MASK) exactly mirror those in CPython’s pycore_symtable.h. No changes needed here.

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

Thank you!

Hide details View details @youknowone youknowone merged commit 7f1fc36 into RustPython:main Aug 1, 2025
12 checks passed
@ShaharNaveh ShaharNaveh deleted the update-symtable branch October 19, 2025 13:31
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