Skip to content
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

gh-101400: Fix wrong lineno in exception message on continue/break which are not in a loop #101413

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Jan 30, 2023

@corona10 corona10 changed the title gh-101400: Restore continue/break loc for the non-loop case [WIP] gh-101400: Restore continue/break loc for the non-loop case Jan 30, 2023
@corona10 corona10 marked this pull request as ready for review Jan 30, 2023
@corona10 corona10 changed the title [WIP] gh-101400: Restore continue/break loc for the non-loop case gh-101400: Restore continue/break loc for the non-loop case Jan 30, 2023
@corona10
Copy link
Member Author

Without patch


======================================================================
FAIL: test_unloop_break_continue (test.test_compile.TestSpecifics.test_unloop_break_continue) (stmt='break')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/user/oss/cpython/Lib/test/test_compile.py", line 856, in test_unloop_break_continue
    self.assertEqual(exc.lineno, 2)
AssertionError: -1 != 2

======================================================================
FAIL: test_unloop_break_continue (test.test_compile.TestSpecifics.test_unloop_break_continue) (stmt='continue')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/user/oss/cpython/Lib/test/test_compile.py", line 856, in test_unloop_break_continue
    self.assertEqual(exc.lineno, 2)
AssertionError: -1 != 2

----------------------------------------------------------------------

@iritkatriel iritkatriel changed the title gh-101400: Restore continue/break loc for the non-loop case gh-101400: Fix wrong lineno in exception message on continue/break which are not in a loop Jan 30, 2023
source = f"with object() as obj:\n {stmt}"
compile(source, f"<unloop_{stmt}>", "exec")
exc = err_ctx.exception
self.assertEqual(exc.lineno, 2)
Copy link
Member

Choose a reason for hiding this comment

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

There are some tests for break and continue outside loops in Lib/test/test_syntax.py, I think the lineno check could be added there. For instance, test_break_outside_loop calls self._check_error() but doesn't pass an expected lineno, though it could. And a similar test for continue could be added next to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@corona10 corona10 requested a review from iritkatriel Jan 30, 2023
Lib/test/test_syntax.py Outdated Show resolved Hide resolved
@corona10 corona10 requested a review from iritkatriel Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants