Skip to content

Ruff rules S, SIM, SLOT#126

Open
cclauss wants to merge 1 commit into
davidlatwe:masterfrom
cclauss:ruff-rules-S-SIM-SLOT
Open

Ruff rules S, SIM, SLOT#126
cclauss wants to merge 1 commit into
davidlatwe:masterfrom
cclauss:ruff-rules-S-SIM-SLOT

Conversation

@cclauss

@cclauss cclauss commented May 14, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Restore process now ignores duplicate-key conflicts to complete imports more reliably.
  • Refactor

    • Simplified query, projection and update internals for more consistent matching and slicing behavior.
    • Minor optimization to internal tuple-based structures.
  • Tests

    • Cleaned and clarified test assertions and helpers.
  • Chores

    • Expanded lint configuration to enforce additional code-quality rules.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c2add9b-3a8d-4d8f-b2cb-0077239a40d8

📥 Commits

Reviewing files that changed from the base of the PR and between 83a7209 and 5323011.

📒 Files selected for processing (13)
  • montydb/engine/field_walker.py
  • montydb/engine/project.py
  • montydb/engine/queries.py
  • montydb/engine/update.py
  • montydb/engine/weighted.py
  • montydb/types/objectid.py
  • montydb/utils/io.py
  • pyproject.toml
  • tests/test_client.py
  • tests/test_database.py
  • tests/test_engine/conftest.py
  • tests/test_engine/test_fieldwalker/test_fieldwalker_set.py
  • tests/test_packaging.py
✅ Files skipped from review due to trivial changes (4)
  • tests/test_engine/conftest.py
  • montydb/engine/field_walker.py
  • montydb/engine/weighted.py
  • pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (9)
  • tests/test_packaging.py
  • tests/test_database.py
  • montydb/engine/update.py
  • montydb/utils/io.py
  • tests/test_engine/test_fieldwalker/test_fieldwalker_set.py
  • montydb/types/objectid.py
  • tests/test_client.py
  • montydb/engine/project.py
  • montydb/engine/queries.py

📝 Walkthrough

Walkthrough

Refactors simplify conditional and membership expressions across engine, utilities, and tests, add a document-type guard before document comparisons, replace a try/except with contextlib.suppress, and expand Ruff lint rules; behavior and public interfaces are unchanged.

Changes

Code Simplification and Quality Improvements

Layer / File(s) Summary
Ruff linting rule expansion
pyproject.toml
Enables Ruff rule families S, SIM, and SLOT; adds ignores for S101 and SIM102 and a per-file SIM117 suppression for montydb/storage/sqlite.py.
Core query and update logic simplification
montydb/engine/queries.py, montydb/engine/update.py
Uses != instead of not ==, adds an is_duckument_type guard before compare_documents in _eq_match, refactors decimal128 NaN checks to direct membership tests, consolidates $all containment to all(...), and unifies $slice handling in pushers.
Field walker and projection handling
montydb/engine/field_walker.py, montydb/engine/project.py
FieldNode.is_missing() returns a single boolean expression; _is_include, $slice, and $elemMatch assignments are simplified to conditional expressions.
Type and utility updates
montydb/engine/weighted.py, montydb/types/objectid.py, montydb/utils/io.py
Adds # noqa: SLOT001 to Weighted, simplifies ObjectId.__setstate__ with a ternary expression, and replaces a try/except DuplicateKeyError with contextlib.suppress.
Test code improvements and compliance
tests/*
Tests use explicit != assertions, add # noqa: S603 to subprocess lines, consolidate nested context managers, switch to context-managed file reads, and discard unused subprocess output variables.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble at conditionals, tidy every nest,
Ternaries hop in, making logic rest,
Suppressing duplicates with a gentle paw,
Lint rules sharpen teeth without a flaw,
A small clean hop — MontyDB is blessed!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.13% 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 directly and concisely summarizes the main changeset: enabling three Ruff rule groups (S, SIM, SLOT) and refactoring code throughout the repository to comply with these rules.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
montydb/engine/weighted.py (1)

87-93: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Fix __slots__ incompatibility that prevents Weighted instantiation.

The __slots__ = () declaration on the tuple subclass prevents the self.value = value assignment in __init__. When Weighted(v) is instantiated (line 567 in collection.py), it will raise AttributeError: 'Weighted' object has no attribute 'value'. This breaks the distinct() method which depends on accessing .value at line 583.

Either remove the __slots__ = () declaration or remove the self.value = value assignment. If the value storage is necessary, consider an alternative approach that doesn't conflict with the empty slots.

🤖 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 `@montydb/engine/weighted.py` around lines 87 - 93, The Weighted tuple subclass
currently sets __slots__ = () which prevents assigning an instance attribute in
__init__ and causes AttributeError when instantiating Weighted(value); fix by
removing or altering the __slots__ declaration so instance attribute storage is
allowed, or by eliminating self.value and instead rely on the tuple contents
(e.g., access the stored value via tuple indexing) — update the class Weighted
(its __slots__, __new__, and __init__ methods and usages of .value) and ensure
callers (e.g., distinct()) read the value from the adjusted representation
(either instance attribute or tuple element) consistently.
🧹 Nitpick comments (1)
pyproject.toml (1)

71-71: ⚡ Quick win

Consider scoping S101 to test files only.

S101 warns against using assert statements because they can be optimized away with python -O. Currently, it's globally ignored, which means assert statements are allowed throughout the codebase, including production code.

Consider moving S101 to per-file-ignores to allow asserts only in test files:

🔒 Suggested configuration to scope S101 to tests
 ignore = [
-  "S101",
   "SIM102",
   "UP015",
 ]
 per-file-ignores = {
   "montydb/storage/sqlite.py" = [ "SIM117" ],
+  "tests/**/*.py" = [ "S101" ],
 }
🤖 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 `@pyproject.toml` at line 71, The project currently ignores the S101 Flake8
rule globally in pyproject.toml (entry "S101"), which allows use of assert in
production; update pyproject.toml to remove "S101" from the global ignores and
instead add it under per-file-ignores scoped to your test files (e.g., add an
entry under [tool.flake8].per-file-ignores mapping test/* or tests/* to "S101")
so asserts remain allowed only in test modules; ensure the per-file-ignores key
and the exact pattern (tests/* or test_*.py) match your test layout and keep
other existing ignores intact.
🤖 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.

Outside diff comments:
In `@montydb/engine/weighted.py`:
- Around line 87-93: The Weighted tuple subclass currently sets __slots__ = ()
which prevents assigning an instance attribute in __init__ and causes
AttributeError when instantiating Weighted(value); fix by removing or altering
the __slots__ declaration so instance attribute storage is allowed, or by
eliminating self.value and instead rely on the tuple contents (e.g., access the
stored value via tuple indexing) — update the class Weighted (its __slots__,
__new__, and __init__ methods and usages of .value) and ensure callers (e.g.,
distinct()) read the value from the adjusted representation (either instance
attribute or tuple element) consistently.

---

Nitpick comments:
In `@pyproject.toml`:
- Line 71: The project currently ignores the S101 Flake8 rule globally in
pyproject.toml (entry "S101"), which allows use of assert in production; update
pyproject.toml to remove "S101" from the global ignores and instead add it under
per-file-ignores scoped to your test files (e.g., add an entry under
[tool.flake8].per-file-ignores mapping test/* or tests/* to "S101") so asserts
remain allowed only in test modules; ensure the per-file-ignores key and the
exact pattern (tests/* or test_*.py) match your test layout and keep other
existing ignores intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8debbaa1-0f8e-4d7e-b8f5-01c778aaab23

📥 Commits

Reviewing files that changed from the base of the PR and between ece1935 and f164f21.

📒 Files selected for processing (13)
  • montydb/engine/field_walker.py
  • montydb/engine/project.py
  • montydb/engine/queries.py
  • montydb/engine/update.py
  • montydb/engine/weighted.py
  • montydb/types/objectid.py
  • montydb/utils/io.py
  • pyproject.toml
  • tests/test_client.py
  • tests/test_database.py
  • tests/test_engine/conftest.py
  • tests/test_engine/test_fieldwalker/test_fieldwalker_set.py
  • tests/test_packaging.py

@cclauss cclauss force-pushed the ruff-rules-S-SIM-SLOT branch from f164f21 to 83a7209 Compare May 14, 2026 04:41
@cclauss cclauss marked this pull request as draft May 14, 2026 04:46
@cclauss cclauss force-pushed the ruff-rules-S-SIM-SLOT branch from 83a7209 to 5323011 Compare May 16, 2026 03:04
@cclauss cclauss marked this pull request as ready for review May 16, 2026 03:13
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