classification
Title: PEP 479: missing DeprecationWarning when generator_stop is not used
Type: Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: 22906 Superseder:
Assigned To: Nosy List: berker.peksag, gvanrossum, ncoghlan, python-dev, yselivanov
Priority: release blocker Keywords: patch

Created on 2015-05-19 11:16 by ncoghlan, last changed 2015-05-22 15:20 by yselivanov. This issue is now closed.

Files
File name Uploaded Description Edit
gen_stop_warn.patch yselivanov, 2015-05-21 03:59 review
gen_stop_warn.patch yselivanov, 2015-05-21 16:23 review
gen_stop_warn.patch yselivanov, 2015-05-21 18:29 review
Messages (12)
msg243576 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2015-05-19 11:16
From the StopIteration-in-generators handling transition plan (https://www.python.org/dev/peps/pep-0479/#transition-plan):

* Python 3.5: Enable new semantics under __future__ import; silent deprecation warning if StopIteration bubbles out of a generator not under __future__ import. 

The first half of that was implemented in issue 22906, but we missed the second half.

The reason the latter is needed is so that people can turn the DeprecationWarning into an error to test for compatibility with the future default behaviour without needing to add the new future flag to their code (which would break compatibility with older Python versions). Ram Rachum pointed out the absence on python-ideas: https://mail.python.org/pipermail/python-ideas/2015-May/033580.html
msg243723 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-05-21 03:33
Nick, please review the patch.

BTW, we will have *a lot* of warnings now when running tests with -Wall. Are we going to employ "from __future__ import generator_stop" everywhere in 3.5?
msg243724 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2015-05-21 03:55
Given the two-release deprecation cycle, would it be worth using PendingDeprecationWarning here? That way folks that only turned on DeprecationWarning (rather than -Wall) wouldn't need to worry about this until 3.6.

As far as our own test suite goes, when ResourceWarning was introduced, dealing with those in the test suite became an ongoing cleanup task. Are there really all that many warnings triggered for PEP 479?
msg243725 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-05-21 03:59
Had to regenerate the patch. Fixed some typos + now I use PyErr_WriteUnraisable if PyErr_WarnFormat returns non-zero.

And yeah, PendingDeprecationWarning is a better choice.
msg243727 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-05-21 04:07
> Are there really all that many warnings triggered for PEP 479?

Actually, with the attached patch the number of warnings is pretty low, we can definitely fix/silence them where necessary.  (I think I had a bug in one of my first patches that triggered some false-positives).

- test_difflib - will have to fix difflib;

- test_contextlib - tests StopIteration propagation on purpose; will silence the warning;

- test_with

- test_generators
msg243738 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2015-05-21 07:13
Why the switch to WriteUnraisable? Unlike __del__ methods and similar operations that may be invoked at arbitrary points, there's nothing stopping us from emitting an exception here - indeed, we're *already* handling an exception.

Getting a hard failure on deprecations is one of the expected consequences of using "-Wall" rather than the default settings.
msg243761 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-05-21 16:23
> Why the switch to WriteUnraisable?

After adding a unittest for the patch it became clear that it was indeed unnecessary ;)  Please see the new patch.
msg243773 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-05-21 18:29
Nick, I've updated the patch to address all PendingDeprecationWarnings related to the PEP 479 in the test suite.
msg243811 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2015-05-22 06:46
The patch mostly looks good to me, but I suggest using "test.support.check_warnings" for the cases where you're checking that the warning is raised as expected: https://docs.python.org/3/library/test.html#test.support.check_warnings

It's slightly simpler than constructing the same logic yourself using warnings.catch_warnings.
msg243827 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-05-22 14:35
Another alternative is using assertWarnsRegex.
msg243829 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-05-22 15:16
New changeset 2771a0ac806b by Yury Selivanov in branch 'default':
Issue 24237: Raise PendingDeprecationWarning per PEP 479
https://hg.python.org/cpython/rev/2771a0ac806b
msg243831 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-05-22 15:20
Nick, I updated the code to use assertWarnsRegex (thanks for suggestion, Berker!)

Closing the issue.
History
Date User Action Args
2015-05-22 15:20:29yselivanovsetstatus: open -> closed
resolution: fixed
messages: + msg243831

stage: patch review -> resolved
2015-05-22 15:16:57python-devsetnosy: + python-dev
messages: + msg243829
2015-05-22 14:35:04berker.peksagsetnosy: + berker.peksag
messages: + msg243827
2015-05-22 06:46:56ncoghlansetmessages: + msg243811
2015-05-21 18:29:33yselivanovsetfiles: + gen_stop_warn.patch

messages: + msg243773
2015-05-21 16:23:43yselivanovsetfiles: + gen_stop_warn.patch

messages: + msg243761
2015-05-21 07:13:28ncoghlansetmessages: + msg243738
2015-05-21 04:07:10yselivanovsetmessages: + msg243727
2015-05-21 03:59:14yselivanovsetfiles: + gen_stop_warn.patch

messages: + msg243725
2015-05-21 03:55:48ncoghlansetmessages: + msg243724
2015-05-21 03:51:50yselivanovsetfiles: - gen_stop_warn.patch
2015-05-21 03:51:22yselivanovsetfiles: + gen_stop_warn.patch
2015-05-21 03:51:10yselivanovsetfiles: - gen_stop_warn.patch
2015-05-21 03:34:38yselivanovsetnosy: + gvanrossum
2015-05-21 03:33:31yselivanovsetfiles: + gen_stop_warn.patch
priority: normal -> release blocker

versions: + Python 3.5
keywords: + patch
nosy: + yselivanov

messages: + msg243723
stage: patch review
2015-05-19 11:16:33ncoghlansetdependencies: + PEP 479: Change StopIteration handling inside generators
2015-05-19 11:16:20ncoghlancreate