Skip to content

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

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

Merged
merged 3 commits into from
Aug 21, 2024

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Aug 20, 2024

@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
Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

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

@bedevere-app
Copy link

bedevere-app bot commented Aug 21, 2024

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
Member Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented Aug 21, 2024

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
Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

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
37 checks passed
@miss-islington-app
Copy link

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

@miss-islington-app
Copy link

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

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 <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Aug 21, 2024

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 <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Aug 21, 2024

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
Copy link
Contributor

15r10nk commented Aug 26, 2024

@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
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
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants