◐ Shell
reader mode source ↗
Skip to content

gh-123142: Fix too wide source locations in tracebacks of exceptions from broken iterables in comprehensions#123173

Merged
iritkatriel merged 3 commits into
python:mainfrom
iritkatriel:gh-123142
Aug 21, 2024
Merged

gh-123142: Fix too wide source locations in tracebacks of exceptions from broken iterables in comprehensions#123173
iritkatriel merged 3 commits into
python:mainfrom
iritkatriel:gh-123142

Conversation

@iritkatriel

@iritkatriel iritkatriel commented Aug 20, 2024

Copy link
Copy Markdown
Member

@iritkatriel iritkatriel added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Aug 20, 2024

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

The code change looks good.
At least class Iter and maybe some more of the tests could be shared

@bedevere-app

bedevere-app Bot commented Aug 21, 2024

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

…tions from broken iterables in comprehensions
@iritkatriel

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again.

@bedevere-app

bedevere-app Bot commented Aug 21, 2024

Copy link
Copy Markdown

Thanks for making the requested changes!

@markshannon: please review the changes made to this pull request.

@bedevere-app bedevere-app Bot requested a review from markshannon August 21, 2024 15:50

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

Looks good.

The code in the three with self.subTest(func) blocks look the same/very similar. I think they could be factored out, but that might just end up obscuring the intent. It's up to you if you want to factor it further.

@iritkatriel iritkatriel merged commit ec89620 into python:main Aug 21, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @iritkatriel for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @iritkatriel, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker ec89620e5e147ba028a46dd695ef073a72000b84 3.13

@miss-islington-app

Copy link
Copy Markdown

Sorry, @iritkatriel, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker ec89620e5e147ba028a46dd695ef073a72000b84 3.12

iritkatriel added a commit to iritkatriel/cpython that referenced this pull request Aug 21, 2024
…f exceptions from broken iterables in comprehensions (pythonGH-123173).

(cherry picked from commit ec89620)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
@bedevere-app

bedevere-app Bot commented Aug 21, 2024

Copy link
Copy Markdown

GH-123209 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Aug 21, 2024
iritkatriel added a commit to iritkatriel/cpython that referenced this pull request Aug 21, 2024
…f exceptions from broken iterables in comprehensions (pythonGH-123173).

(cherry picked from commit ec89620)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
@bedevere-app

bedevere-app Bot commented Aug 21, 2024

Copy link
Copy Markdown

GH-123210 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Aug 21, 2024
blhsing pushed a commit to blhsing/cpython that referenced this pull request Aug 22, 2024
iritkatriel added a commit that referenced this pull request Aug 22, 2024
…ptions from broken iterables in comprehensions (GH-123173). (#123209)

(cherry picked from commit ec89620)
iritkatriel added a commit that referenced this pull request Aug 22, 2024
…ptions from broken iterables in comprehensions (GH-123173). (#123210)

(cherry picked from commit ec89620)
@15r10nk

15r10nk commented Aug 26, 2024

Copy link
Copy Markdown
Contributor

@iritkatriel might it be that this fix changed the source range for exceptions in __init__ and __next__ but not for exceptions in __iter__.

class Foo:
    def __iter__(self):
        assert False

a = [x for x in Foo()]

output (Python 3.13.0rc1+):

Traceback (most recent call last):
  File "/home/frank/projects/cpython/codi.py", line 5, in <module>
    a = [x for x in Foo()]
        ^^^^^^^^^^^^^^^^^^
  File "/home/frank/projects/cpython/codi.py", line 3, in __iter__
    assert False
           ^^^^^
AssertionError

This is the example from the issue and I'm a little confused as to whether it was just forgotten or if I'm missing something here.

@iritkatriel

Copy link
Copy Markdown
Member Author

This is the example from the issue and I'm a little confused as to whether it was just forgotten or if I'm missing something here.

So it seems. The test doesn't check for this too. Thanks for reporting, I'll fix.

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.

3 participants