Skip to content

Update test_context.py to 3.14.4#7804

Merged
youknowone merged 3 commits into
RustPython:mainfrom
ShaharNaveh:update-test-context
May 9, 2026
Merged

Update test_context.py to 3.14.4#7804
youknowone merged 3 commits into
RustPython:mainfrom
ShaharNaveh:update-test-context

Conversation

@ShaharNaveh
Copy link
Copy Markdown
Contributor

@ShaharNaveh ShaharNaveh commented May 9, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved string representation of context variables: names are now quoted, the default value is shown only when present, and the object id is always included in hex — making debugging and logging clearer.

Review Change Stack

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 63cb4d3a-b06a-4dd0-9e96-9bbc472b15b8

📥 Commits

Reviewing files that changed from the base of the PR and between de8d167 and ec5d802.

📒 Files selected for processing (1)
  • crates/stdlib/src/contextvars.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/stdlib/src/contextvars.rs

📝 Walkthrough

Walkthrough

This PR removes redundant #[allow(dead_code)] annotations from ContextVarOptions and rewrites ContextVar::repr_str to quote the name, always include the object id in hex, and include default=... only when a default exists.

Changes

ContextVar Implementation Refinement

Layer / File(s) Summary
Annotation Cleanup
crates/stdlib/src/contextvars.rs
Removed #[allow(dead_code)] attributes from the ContextVarOptions positional name parameter and the default field while keeping #[pyarg(any, optional)] on name.
Repr String Implementation
crates/stdlib/src/contextvars.rs
Rewrote ContextVar::repr_str to introduce local name and id variables, quote name, always include the hex object id, and conditionally add default=... only when zelf.default is present.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I hopped through fields and cleared the clutter,
Quoted the name and left the id in glitter,
Defaults now whisper only when they're there,
Clean code, neat repr — a rabbit's small prayer. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title references updating 'test_context.py to 3.14.4', but the actual changes are in 'crates/stdlib/src/contextvars.rs' with modifications to ContextVar implementation, not a test file update. Update the title to accurately reflect the changes made to contextvars.rs, such as 'Fix ContextVar repr_str formatting and remove dead_code annotations' or similar.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] test: cpython/Lib/test/test_context.py (TODO: 7)

dependencies:

dependent tests: (11 tests)
- [ ] multiprocessing: test_asyncio test_compileall test_concurrent_futures test_fcntl test_genericalias test_logging test_memoryview test_multiprocessing_main_handling test_re test_socket
- [ ] concurrent.futures.process: test_concurrent_futures

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

Copy link
Copy Markdown
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.

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

537-539: 💤 Low value

Simplify the pattern matching.

The pattern if let Some(ref arg) = zelf.default.as_ref() is unnecessarily verbose and creates a double reference. Consider simplifying to if let Some(arg) = zelf.default.as_ref().

Additionally, the .ok() on line 538 silently discards any error from str(vm), which will cause default to be None if the conversion fails. This will print default=None in the repr, which could be misleading (it's not that the default is None, but that we failed to get its string representation). If this matches Python 3.14.4's behavior, this is fine; otherwise, consider handling the error explicitly or propagating it.

♻️ Simplified pattern matching
-            Ok(if let Some(ref arg) = zelf.default.as_ref() {
+            Ok(if let Some(arg) = zelf.default.as_ref() {
                 let default = arg.str(vm).ok();
-                format!("<ContextVar name='{name}' default={default:?} at {id:`#x`}>",)
+                format!("<ContextVar name='{name}' default={default:?} at {id:`#x`}>")
             } else {

Note: Also removed the unnecessary trailing comma in the format! macro.

🤖 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 `@crates/stdlib/src/contextvars.rs` around lines 537 - 539, Simplify the
pattern and stop silently dropping str(vm) errors: replace `if let Some(ref arg)
= zelf.default.as_ref()` with `if let Some(arg) = zelf.default.as_ref()` and
change the `.ok()` call on `arg.str(vm)` to explicitly handle the Result (e.g.,
`let default = match arg.str(vm) { Ok(s) => Some(s), Err(e) =>
Some(format!("<error: {}>", e)) };`) so the repr either shows the string or a
clear error placeholder before calling `format!` for the ContextVar repr.
🤖 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.

Nitpick comments:
In `@crates/stdlib/src/contextvars.rs`:
- Around line 537-539: Simplify the pattern and stop silently dropping str(vm)
errors: replace `if let Some(ref arg) = zelf.default.as_ref()` with `if let
Some(arg) = zelf.default.as_ref()` and change the `.ok()` call on `arg.str(vm)`
to explicitly handle the Result (e.g., `let default = match arg.str(vm) { Ok(s)
=> Some(s), Err(e) => Some(format!("<error: {}>", e)) };`) so the repr either
shows the string or a clear error placeholder before calling `format!` for the
ContextVar repr.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: b44272b6-1b0a-46ef-b6a3-697d1ba73cd1

📥 Commits

Reviewing files that changed from the base of the PR and between e10a27b and de8d167.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_context.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/stdlib/src/contextvars.rs

@youknowone youknowone merged commit 67630ff into RustPython:main May 9, 2026
26 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