Skip to content

bpo-33224: PEP 479 fix for difflib.mdiff()#6381

Merged
rhettinger merged 2 commits into
python:masterfrom
rhettinger:mdiff-stop-iteration
Apr 5, 2018
Merged

bpo-33224: PEP 479 fix for difflib.mdiff()#6381
rhettinger merged 2 commits into
python:masterfrom
rhettinger:mdiff-stop-iteration

Conversation

@rhettinger

@rhettinger rhettinger commented Apr 5, 2018

Copy link
Copy Markdown
Contributor

Comment thread Lib/difflib.py
lines_to_write -= 1
yield from_line, to_line, found_diff
except StopIteration:
# Catch exception from next() and return normally

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.

It also catches exception from "yield". Is this intentionally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How does yield raise an exception? Also, my understanding is that any uncaught StopIteration in a generator is an error.

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.

yield can raise an exception passed by throw().

But I agree that in this case the generator is not leaked outside, and internally it is used only for iteration.

Comment thread Lib/difflib.py
lines_to_write -= 1
yield from_line, to_line, found_diff
except StopIteration:
# Catch exception from next() and return normally

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.

yield can raise an exception passed by throw().

But I agree that in this case the generator is not leaked outside, and internally it is used only for iteration.

@rhettinger rhettinger merged commit 01b731f into python:master Apr 5, 2018
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @rhettinger for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-6390 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 5, 2018
(cherry picked from commit 01b731f)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 5, 2018
(cherry picked from commit 01b731f)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
@bedevere-bot

Copy link
Copy Markdown

GH-6391 is a backport of this pull request to the 3.6 branch.

rhettinger added a commit that referenced this pull request Apr 5, 2018
(cherry picked from commit 01b731f)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants