Skip to content

Conversation

ever0de
Copy link
Contributor

@ever0de ever0de commented Aug 5, 2025

ref

Summary by CodeRabbit

  • New Features
    • Improved error messages for unsupported numeric and sequence operations on Blob objects in the SQLite module. Attempting to use addition, multiplication, or containment checks with Blob objects now provides clear type errors indicating these operations are not supported.

Copy link
Contributor

coderabbitai bot commented Aug 5, 2025

Walkthrough

The change adds implementations of the AsNumber and AsSequence traits for the Blob type in the SQLite module. These implementations explicitly disable numeric and sequence operations on Blob objects by returning type errors, and update the #[pyclass] attribute accordingly. Imports are adjusted to support these changes.

Changes

Cohort / File(s) Change Summary
Blob Trait Implementations
stdlib/src/sqlite.rs
Added AsNumber and AsSequence trait implementations for Blob, updated #[pyclass] attributes, and adjusted imports. Numeric and sequence operations now return type errors or are marked as not implemented.

Sequence Diagram(s)

sequenceDiagram
    participant Python
    participant Blob
    Python->>Blob: Attempt numeric or sequence operation (e.g., +, *, in)
    Blob-->>Python: Return TypeError ("unsupported operand type" or "not iterable")
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • youknowone

Poem

A Blob in the database, round and discreet,
Now resists your math—no plus, no repeat!
Try to add or to check if it's in,
You'll get a TypeError, not a win.
This bunny says: "Blobs are for bytes, not for sums—
So hop along, coder, and mind your thumbs!" 🐇

Note

⚡️ Unit Test Generation is now available in beta!

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


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c4a8051 and 0db8e3f.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_sqlite3/test_dbapi.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • stdlib/src/sqlite.rs (4 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:

  • stdlib/src/sqlite.rs
🧠 Learnings (1)
📚 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:

  • stdlib/src/sqlite.rs
🔇 Additional comments (4)
stdlib/src/sqlite.rs (4)

71-73: LGTM! Import additions are necessary and well-organized.

The added imports for PyNumberMethods, PySequenceMethods, AsNumber, and AsSequence are required for the new trait implementations and follow the existing code organization patterns.

Also applies to: 77-78


2065-2065: LGTM! Trait additions to pyclass attribute are correct.

The update properly adds AsNumber and AsSequence traits to the existing AsMapping and Unconstructible traits, following the established pattern in the codebase.


2356-2377: LGTM! AsNumber implementation correctly disables arithmetic operations.

The implementation properly returns TypeError with descriptive messages for unsupported arithmetic operations (+ and *) on Blob objects, which matches CPython's behavior. Using PyNumberMethods::NOT_IMPLEMENTED for other operations is the correct approach.


2379-2398: LGTM! AsSequence implementation correctly disables sequence operations.

The implementation properly disables all sequence operations by setting them to None, while the contains operation correctly returns a TypeError indicating that Blob objects are not iterable. This matches CPython's sqlite3.Blob behavior and follows the established patterns in the codebase.

✨ 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.
  • 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.

Support

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

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.

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

👍

@youknowone youknowone merged commit a58d582 into RustPython:main Aug 5, 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