Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix traceback circular reference detection to pass test_raise.py#5995

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge3 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-553b69a0-a240-49f5-b496-d5e110c3f3cc

Conversation

Copilot
Copy link

@CopilotCopilotAI commentedJul 17, 2025
edited
Loading

Fixes the tracebacktb_next setter to properly detect and prevent circular references, enablingtest_raise.py::TestTracebackType.test_attrs to pass.

Problem

The testTestTracebackType.test_attrs intest_raise.py was marked with@unittest.expectedFailure because the traceback implementation was missing circular reference detection. The test expects:

# These should raise ValueError due to circular referencestb.tb_next=tb# Direct self-assignmenttb.tb_next.tb_next=tb# Indirect loop through chain

But the current implementation allowed these assignments without validation.

Solution

Added circular reference detection to theset_tb_next method invm/src/builtins/traceback.rs:

  1. Direct loop detection: Checks if the new traceback being assigned is the same object asself
  2. Indirect loop detection: Walks the traceback chain from the new object to ensureself doesn't appear anywhere in the chain
  3. Proper pointer comparison: Usesstd::ptr::eq with correct dereferencing to compare the underlyingPyTraceback objects

The implementation raisesValueError("circular reference in traceback chain") when a circular reference is detected, matching CPython's behavior.

Changes

  • Removed@unittest.expectedFailure decorator fromTestTracebackType.test_attrs
  • Added loop detection logic toPyTraceback::set_tb_next()
  • Addedstd::ops::Deref import for proper object dereferencing

Testing

  • TestTracebackType.test_attrs now passes
  • ✅ All 36 tests intest_raise.py continue to pass
  • ✅ No clippy warnings introduced

The fix is minimal and surgical, only adding the necessary validation without changing any existing working functionality.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
@CopilotCopilotAI changed the title[WIP] Remove@unittest.expectedFailure from test_raise.py 's TestTracebackType.test_attrs. Run the test and fix the errors by editingtraceback.rsFix traceback circular reference detection to pass test_raise.pyJul 17, 2025
@CopilotCopilotAI requested a review fromyouknowoneJuly 17, 2025 02:17
Copilot finished work on behalf ofyouknowoneJuly 17, 2025 02:17
Comment on lines 68 to 82
if let Some(ref new_tb) = value {
// Check for direct loop (tb.tb_next = tb)
if std::ptr::eq(self as *const _, new_tb.deref().deref() as *const _) {
return Err(vm.new_value_error("circular reference in traceback chain".to_owned()));
}

// Check for indirect loops by walking the chain
let mut current = new_tb.tb_next();
while let Some(ref tb) = current {
if std::ptr::eq(self as *const _, tb.deref().deref() as *const _) {
return Err(vm.new_value_error("circular reference in traceback chain".to_owned()));
}
current = tb.tb_next();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This is too ad-hoc. You must create a more general logic to detect circular reference in tb_next until the end.

Copy link
Author

Choose a reason for hiding this comment

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

Implemented a more general cycle detection algorithm using Floyd's cycle detection (tortoise and hare). The new approach simulates the assignment and detects any cycles in the resulting chain rather than only checking for specific patterns. See commitce5fe45.

Replace ad-hoc circular reference checking with Floyd's cycle detection algorithm for more comprehensive cycle detection.Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Copilot finished work on behalf ofyouknowoneJuly 17, 2025 05:10
@CopilotCopilotAI requested a review fromyouknowoneJuly 17, 2025 05:10
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@youknowoneyouknowoneAwaiting requested review from youknowone

At least 1 approving review is required to merge this pull request.

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Copilot@youknowone

[8]ページ先頭

©2009-2025 Movatter.jp