Implement more warnings by youknowone · Pull Request #7008 · RustPython/RustPython
📝 Walkthrough
Walkthrough
Refactors and expands the warnings subsystem: adds VM-level warning state and lock APIs, broadens warn/warn_explicit to accept PyObject messages, adds PYTHONWARNINGS parsing, simplifies frame traversal, and updates call sites to pass message.into() conversions; many changes affect warn routing, registry, and filter matching.
Changes
| Cohort / File(s) | Summary |
|---|---|
Warnings core & state crates/vm/src/warn.rs, crates/vm/src/stdlib/warnings.rs, crates/vm/src/vm/context.rs |
Introduce WarningsState public fields (filters, once_registry, default_action, filters_version, context_var), add lock APIs (acquire/release, filters_mutated), implement filter-matching and warn_with_skip, expose _warnings module accessors, and add const names for new keys. |
API surface & call sites crates/stdlib/src/_asyncio.rs, crates/stdlib/src/socket.rs, crates/vm/src/coroutine.rs, crates/vm/src/stdlib/ast/python.rs, crates/vm/src/stdlib/ast/string.rs |
Update warn call sites and deprecation message construction to pass messages as PyObject (.into()), reflow minor chains for readability; no behavioral changes. |
Frame traversal crates/vm/src/frame.rs, crates/vm/src/warn.rs |
Simplify next_external_frame traversal and add next_external_frame_with_skip / is_filename_to_skip to support skip_file_prefixes during stack walking. |
Settings / env parsing src/settings.rs |
Parse PYTHONWARNINGS environment variable and append entries to Settings.warnoptions before CLI processing. |
Misc (dictionary) .cspell.dict/python-more.txt |
Reorganized and de-duplicated dictionary tokens; minor insert/remove adjustments. |
Sequence Diagram(s)
sequenceDiagram
participant Env as Settings / Env
participant WarnAPI as warn() / warn_explicit
participant FrameWalk as Frame Walker
participant Filter as Filter Matcher
participant Registry as once_registry
participant Show as call_show_warning / _showwarnmsg
Env->>WarnAPI: provide message, category, skip_file_prefixes
WarnAPI->>FrameWalk: walk stack (skip internals/prefixes)
FrameWalk-->>WarnAPI: calling context (filename, lineno, module)
WarnAPI->>Filter: evaluate filters for category & message
Filter-->>WarnAPI: action (error/ignore/once/always/default/module)
alt error
WarnAPI->>Env: raise as exception
else once
WarnAPI->>Registry: check/record
Registry-->>WarnAPI: already_warned? / recorded
alt not recorded
WarnAPI->>Show: call_show_warning with text & instance
Show-->>Env: emit via _showwarnmsg
end
else emit
WarnAPI->>Show: call_show_warning
Show-->>Env: emit via _showwarnmsg
end
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
- Fix error / warning messages #6594: Touches the same
coroutine.warn_deprecated_throw_signaturecall sites and formatting changes. - Introduce PyConfig to implement Paths correctly #6461: Related to VM warning configuration and use of Settings.warnoptions / warning option plumbing.
Poem
🐰
I hopped through warnings, soft and bright,
Filters lined up, locks held tight,
Frames now skip the rabbit holes,
Messages flow as coherent goals,
A tidy burrow for each light. ✨
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | ❓ Inconclusive | The title 'Implement more warnings' is vague and does not clearly convey the specific nature of the changes in this pull request. | Consider a more descriptive title that reflects the main objective, such as 'Enhance warnings module with filter management and context support' or 'Add warning filters and lock management to stdlib'. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 87.18% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- 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.
Comment @coderabbitai help to get the list of available commands and usage tips.