GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — Allow #[pyexception] on module attr by youknowone · Pull Request #6218 · RustPython/RustPython Conversation
|
WalkthroughIntroduces support for a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
810fc12 to
ded211d
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
stdlib/src/ssl.rs (2)
206-226: New SSL exception hierarchy (SSLError + subclasses) — well structured.
- Base SSLError derives from PyOSError (CPython parity).
- str prefers strerror then args — sensible default.
Minor: you could fallback to exc.str(vm) instead of str(args) for perfect parity, but current code is fine.
Also applies to: 230-236, 239-245, 248-254, 257-263, 266-272, 275-281
1982-2012: convert_openssl_error/convert_ssl_error are solid; add ZERO_RETURN mapping.Map ssl::ErrorCode::ZERO_RETURN to SSLZeroReturnError for better CPython parity (clean shutdown). Suggested patch:
@@ fn convert_ssl_error(vm: &VirtualMachine, e: impl std::borrow::Borrow<ssl::Error>) -> PyBaseExceptionRef { - let (cls, msg) = match e.code() { + let (cls, msg) = match e.code() { ssl::ErrorCode::WANT_READ => ( PySslWantReadError::class(&vm.ctx).to_owned(), "The operation did not complete (read)", ), ssl::ErrorCode::WANT_WRITE => ( PySslWantWriteError::class(&vm.ctx).to_owned(), "The operation did not complete (write)", ), + ssl::ErrorCode::ZERO_RETURN => ( + PySslZeroReturnError::class(&vm.ctx).to_owned(), + "TLS/SSL connection has been closed (EOF)", + ), ssl::ErrorCode::SYSCALL => match e.io_error() { Some(io_err) => return io_err.to_pyexception(vm), None => ( PySslSyscallError::class(&vm.ctx).to_owned(), "EOF occurred in violation of protocol", ), }, ssl::ErrorCode::SSL => match e.ssl_error() { Some(e) => return convert_openssl_error(vm, e.clone()), None => ( PySslError::class(&vm.ctx).to_owned(), "A failure in the SSL library occurred", ), }, _ => ( PySslError::class(&vm.ctx).to_owned(), "A failure in the SSL library occurred", ), };Run your SSL tests that exercise graceful close to verify behavior change.
Also applies to: 2034-2068
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
derive-impl/src/pyclass.rs (3 hunks)derive-impl/src/pymodule.rs (5 hunks)derive-impl/src/util.rs (1 hunks)stdlib/src/ssl.rs (11 hunks)vm/src/exceptions.rs (2 hunks)📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Format Rust code with the default rustfmt style (runcargo fmt)
Run clippy and fix any warnings or lints introduced by your changes
Follow Rust best practices for error handling and memory management
Files:
derive-impl/src/util.rsderive-impl/src/pymodule.rsderive-impl/src/pyclass.rsstdlib/src/ssl.rsvm/src/exceptions.rs📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use RustPython macros (
pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
stdlib/src/ssl.rsvm/src/exceptions.rsderive-impl/src/util.rs (1)
attr_name(106-108)
vm/src/exceptions.rs (12)
class(43-45)slot_new(1453-1465)slot_new(1468-1470)slot_init(1272-1279)slot_init(1314-1330)slot_init(1349-1369)slot_init(1473-1489)slot_init(1655-1687)slot_init(1749-1756)slot_init(1791-1805)slot_init(1842-1855)slot_init(1893-1905)vm/src/class.rs (1)
static_type(25-33)
derive/src/lib.rs (1)
pyexception(139-143)derive-impl/src/lib.rs (1)
pyexception(50-56)vm/src/exceptions.rs (10)
__str__(637-644)__str__(1405-1415)__str__(1492-1521)__str__(1690-1734)__str__(1808-1831)__str__(1858-1882)__str__(1908-1928)class(43-45)args(567-569)args(573-573)
vm/src/types/slot.rs (4)
slot_new(787-790)slot_new(810-812)slot_new(821-823)slot_init(836-840)
derive-impl/src/util.rs (1)
449-451: ALLOWED_NAMES now includes "module" — good alignment with pyclass metadata.This enables #[pyexception(module = ...)] parsing consistently. No issues.
derive-impl/src/pymodule.rs (3)
19-20: Add AttrName::Exception with Display/FromStr — looks correct.Enum wiring is complete and error strings remain coherent.
Also applies to: 28-29, 37-43
239-243: Treat pyexception like pyclass in module items.Correct: both define types. This keeps generation paths uniform.
309-316: Allow #[pyexception] to follow #[pyattr].The diagnostic string is updated accordingly. Good UX improvement.
derive-impl/src/pyclass.rs (3)
554-560: PyException PyPayload fallback via StaticType — good default.Removes ctx dependency for external exceptions. Ensure new_class initialization runs before first class() call, otherwise StaticType::static_type() panics. Please verify module init order.
622-629: Make generated slot_new public.Necessary for cross-crate calls like ::Base::slot_new when Base lives in vm. Good.
643-650: Make generated slot_init public.Same rationale as slot_new. Looks good.
vm/src/exceptions.rs (1)
1452-1469: Expose PyOSError slot_new/slot_init as public.Enables derive-generated calls from other crates. Safe and consistent with the new macro behavior.
Also applies to: 1473-1489
stdlib/src/ssl.rs (2)
41-44: Import AsObject/PyOSError — required for new exception plumbing.Imports are correct and used.
642-647: Consistent use of PySslError for module errors.Raised errors now consistently use the new SSL classes. Good consistency upgrade.
Also applies to: 771-782, 963-972, 1418-1421, 1451-1454, 1883-1886
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.