-
Notifications
You must be signed in to change notification settings - Fork 1.4k
__doc__ handing in the right way #6390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughClass codegen no longer emits a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/vm/src/builtins/type.rs (1)
1181-1205: Overriding slots attributes via member descriptors makes sense; small perf nitAlways installing a
PyMemberDescriptorfor each__slots__member (even when an inherited attribute exists) is consistent with the idea that defining a slot should override MRO attributes for that name, including inherited descriptors.A small improvement: you can avoid an extra allocation when interning the attribute name by reusing the existing
PyStrRef:- let attr_name = vm.ctx.intern_str(member.to_string()); + let attr_name = vm.ctx.intern_str(member.as_str());This keeps behavior the same while avoiding a temporary
String.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Lib/test/test_typing.pyis excluded by!Lib/**
📒 Files selected for processing (3)
crates/codegen/src/compile.rs(1 hunks)crates/vm/src/builtins/type.rs(2 hunks)extra_tests/snippets/syntax_class.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by 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:
crates/codegen/src/compile.rscrates/vm/src/builtins/type.rs
**/*.py
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.py: In most cases, Python code should not be edited; bug fixes should be made through Rust code modifications only
Follow PEP 8 style for custom Python code
Use ruff for linting Python code
Files:
extra_tests/snippets/syntax_class.py
🧬 Code graph analysis (1)
extra_tests/snippets/syntax_class.py (1)
extra_tests/snippets/builtin_type.py (5)
A(76-77)A(159-160)A(209-210)A(240-241)A(605-606)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run tests under miri
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Check Rust code with clippy
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
🔇 Additional comments (3)
extra_tests/snippets/syntax_class.py (1)
189-189: Docstring assertion is now more idiomatic and debuggableUsing
is Noneavoids equality quirks, and includingA.__doc__as the assertion message will make failures easier to diagnose. Looks good.crates/codegen/src/compile.rs (1)
2667-2687: Class-body doc emission is now consistent and avoids redundant None assignmentsConditionally storing
__doc__only whensplit_docfinds an explicit docstring:
- Reduces bytecode for classes without docstrings.
- Aligns with the type-side behavior where absence of a
__doc__entry means__doc__should read asNone.- Preserves override semantics when the class body later reassigns
__doc__.Looks good.
crates/vm/src/builtins/type.rs (1)
1367-1393: The current implementation correctly matches CPython behavior —__doc__is not inherited via MROCPython's C-API explicitly documents that
PyTypeObject.tp_docis not inherited by subtypes. A subclass must supply its own docstring if one is desired; the base class's__doc__is not used. The code's restriction toget_direct_attr("__doc__")with no MRO traversal is correct and intentional per CPython's specification.Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/vm/src/builtins/type.rs (1)
1238-1246: LGTM! Correctly ensures every type has a__doc__entry.The implementation properly aligns with CPython's behavior by unconditionally adding a
__doc__entry to the type's dict during construction.Optional micro-optimization: Consider using
entry().or_insert()to avoid the check-then-set pattern:- { - let __doc__ = identifier!(vm, __doc__); - if !typ.attributes.read().contains_key(&__doc__) { - typ.attributes.write().insert(__doc__, vm.ctx.none()); - } - } + { + let __doc__ = identifier!(vm, __doc__); + typ.attributes.write().entry(__doc__).or_insert(vm.ctx.none()); + }This is a minor improvement and not critical since this code runs during type construction before the type is exposed to other threads.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
Lib/test/test_property.pyis excluded by!Lib/**Lib/test/test_typing.pyis excluded by!Lib/**
📒 Files selected for processing (3)
crates/codegen/src/compile.rs(1 hunks)crates/vm/src/builtins/type.rs(3 hunks)extra_tests/snippets/syntax_class.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- extra_tests/snippets/syntax_class.py
- crates/codegen/src/compile.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by 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:
crates/vm/src/builtins/type.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run tests under miri
- GitHub Check: Check Rust code with clippy
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
🔇 Additional comments (2)
crates/vm/src/builtins/type.rs (2)
1201-1204: LGTM! Clear slot descriptor override behavior.The implementation correctly ensures that
__slots__attributes always get a member descriptor that overrides any inherited attribute from the MRO. The explicit comment clarifies the intended behavior.
1389-1391: LGTM! Correct__doc__resolution behavior.The implementation correctly retrieves
__doc__from the type's own dict (not MRO) usingget_direct_attr, which aligns with CPython's behavior. The updated comments clearly explain the intended behavior and the distinction from MRO-based lookup.
Summary by CodeRabbit
Bug Fixes
Improvements
Tests
✏️ Tip: You can customize this high-level summary in your review settings.