This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: incompatible change to warnings.showwarning
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: barry, benjamin.peterson, brett.cannon, exarkun, glyph, pitrou
Priority: release blocker Keywords:

Created on 2008-04-27 19:08 by exarkun, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (10)
msg65894 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2008-04-27 19:08
In Python 2.5 and earlier, the `showwarning´ function in the `warnings´
module has this signature:

  def showwarning(message, category, filename, lineno, file=None):

In trunk (and presumably what will become Python 2.6), this has become:

  def showwarning(message, category, filename, lineno, file=None,
line=None):

`showwarning´ is documented as a hook which libraries or applications
may override in order to control how warnings are reported.  The
addition of a new parameter to the function and the change to related
code to call it with an argument for that new parameter means that
libraries and applications which replaced it will not work without
modification on Python 2.6.  Instead, a `TypeError´ will be raised when
a warning is emitted.

I suggest restoring the previous signature for `showwarning´ and adding
a new (perhaps preferred) API for showing a warning with the extra
information available.  It may also make sense to emit a deprecation
warning when an overridden old-style `showwarning´ is found.
msg65895 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-04-27 19:25
Well, all you have to do is to change the hook's signature to the new
one and, since the last parameter is optional, it should not cause any
backwards compatibility problems. That is, the new hook should work fine
on Python < 2.6 as well. Am I missing something?
msg65896 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-04-27 19:31
We should have an entry under "Porting to 2.6" in whatsnew.
msg65898 - (view) Author: Glyph Lefkowitz (glyph) (Python triager) Date: 2008-04-27 20:25
pitrou: You're missing a few steps.  If you are maintaining project X,
which depends on library Y, that adds a showwarning hook for some
reason, you need to:

 * check out a development version of library Y, which you do not
normally maintain
 * change the hook's signature to the new one
 * submit a patch to library Y
 * make a local fork of library Y so that you can verify the rest of
your code under 2.6
 * send out an email to your mailing list explaining that they cannot
run with python 2.6 without this patch (linking to the patch in library Y)
 * write a FAQ entry because 200 people show up asking why it does not
work on python 2.6
 * if library Y's development is slow, do a new release of project X
which includes monkeypatching to allow running project X on 2.6

These steps may be unavoidable if library Y has been unmaintained for a
long enough time, but it would be nice to be able to avoid this with a
single new Python release.
msg65899 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-04-27 20:38
Is it a theoretical case or are you thinking about a specific library Y? 

Also, seeing some things break when a new Python version is released is
not new as you certainly know : see
http://twistedmatrix.com/trac/ticket/1867
msg65900 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-04-27 20:41
I have emailed python-dev to try to decide how to handle this.
msg65901 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2008-04-27 20:51
By the way, I just noticed that Lib/idlelib/PyShell.py includes an
override of `showwarning´ which is defined with the old signature.

I ran idle from trunk and verified that is indeed breaks warning reporting.
msg66057 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-05-02 02:26
Fixed in r62626. I left in the optional arguments but they are just not 
called anymore by the 'warnings' machinery. I might add a 
PendingDeprecationWarning so that people start to add the argument, 
though, for future use.
msg66058 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-05-02 02:29
Why don't you add a Py3k warning and keep it in Py3k?
msg66059 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-05-02 02:33
On Thu, May 1, 2008 at 7:29 PM, Benjamin Peterson
<report@bugs.python.org> wrote:
>
>  Benjamin Peterson <musiccomposition@gmail.com> added the comment:
>
>  Why don't you add a Py3k warning and keep it in Py3k?

Just asked python-dev if they are okay with that. 2.6 could get a
PendingDeprecationWarning and 3.0 could get a DeprecationWarning. But
I don't want to do an API change between the two that breaks code like
that.
History
Date User Action Args
2022-04-11 14:56:33adminsetnosy: + barry
github: 46957
2008-05-02 02:33:51brett.cannonsetmessages: + msg66059
2008-05-02 02:29:24benjamin.petersonsetmessages: + msg66058
2008-05-02 02:27:04brett.cannonsetstatus: open -> closed
resolution: fixed
messages: + msg66057
2008-04-27 20:51:27exarkunsetmessages: + msg65901
2008-04-27 20:41:55brett.cannonsetpriority: critical -> release blocker
2008-04-27 20:41:45brett.cannonsetpriority: critical
assignee: brett.cannon
messages: + msg65900
nosy: + brett.cannon
2008-04-27 20:38:20pitrousetmessages: + msg65899
2008-04-27 20:25:30glyphsetnosy: + glyph
messages: + msg65898
2008-04-27 19:31:48benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg65896
2008-04-27 19:25:32pitrousetnosy: + pitrou
messages: + msg65895
2008-04-27 19:08:54exarkuncreate