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: warnings.showwarning should allow any callable object
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, daniel.urban, lekma, ncoghlan, python-dev, r.david.murray
Priority: normal Keywords: patch

Created on 2010-10-31 18:53 by lekma, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Issue10271.diff lekma, 2011-02-02 13:19 patch against py3k review
Issue10271.33.fix.diff lekma, 2011-04-17 13:50 fix issue10271 review
Issue10271.33.test.diff lekma, 2011-04-17 13:51 test for issue10271 review
Messages (11)
msg120080 - (view) Author: (lekma) * Date: 2010-10-31 18:53
Overriding warnings.showwarning() with a c/python module function (from a c/python module) doesn't work because warn_explicit() only allow PyFunction or PyMethod objects to be called (unfortunately c/python module functions are of type PyCFunction).

Suggested changes in _warnings.c (from py3k) - not tested at all:

from:
412            if (!PyMethod_Check(show_fxn) && !PyFunction_Check(show_fxn)) {
413                PyErr_SetString(PyExc_TypeError,
414                                "warnings.showwarning() must be set to a "
415                                "function or method");

to:
412            if (!PyCallable_Check(show_fxn)) {
413                PyErr_SetString(PyExc_TypeError,
414                                "warnings.showwarning() must be set to a "
415                                "callable");
msg127883 - (view) Author: (lekma) * Date: 2011-02-04 10:46
brett,

is there any chance for this to make it in?
msg127936 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-02-04 20:20
Not for 3.2.0, no as it's such a minor "fix". Chance this can go into 3.2.1, though. Definitely for 3.3.
msg133927 - (view) Author: (lekma) * Date: 2011-04-17 13:50
- split the patch between the actual fix and the test
- rewrote the test a little bit (I'm not sure it's even needed, hence the split)
- rediff against 3.3 (should still apply cleanly on top of 3.2 (modulo offset))
msg136215 - (view) Author: (lekma) * Date: 2011-05-18 09:29
Is there anything else I should be doing?
msg136230 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-05-18 11:52
Brett's been very busy with real life.  Maybe someone else can commit this.
msg136420 - (view) Author: (lekma) * Date: 2011-05-21 06:14
how should we go about that?
msg140556 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-07-18 02:18
New changeset aaced3dcb858 by Brett Cannon in branch 'default':
Make warnings accept a callable for showwarnings instead of
http://hg.python.org/cpython/rev/aaced3dcb858
msg140557 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-07-18 02:19
Committed in 3.3. This cannot be backported as it widens the API and those could lead to subtle incompatibilities.
msg140558 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-07-18 02:26
New changeset eaefb34fc3a1 by Brett Cannon in branch 'default':
Add Misc/NEWS entry and relevant doc change for issue 10271.
http://hg.python.org/cpython/rev/eaefb34fc3a1
msg140788 - (view) Author: (lekma) * Date: 2011-07-21 06:07
Thank you very much for your help
History
Date User Action Args
2022-04-11 14:57:08adminsetgithub: 54480
2011-07-21 06:07:49lekmasetmessages: + msg140788
2011-07-18 02:26:00python-devsetmessages: + msg140558
2011-07-18 02:19:13brett.cannonsetstatus: open -> closed
resolution: fixed
messages: + msg140557
2011-07-18 02:18:11python-devsetnosy: + python-dev
messages: + msg140556
2011-07-16 09:49:04ncoghlansetnosy: + ncoghlan
2011-05-21 06:14:59lekmasetmessages: + msg136420
2011-05-18 11:52:46r.david.murraysetnosy: + r.david.murray
messages: + msg136230
2011-05-18 11:44:08daniel.urbansetnosy: + daniel.urban
2011-05-18 09:29:59lekmasetmessages: + msg136215
2011-04-17 13:51:15lekmasetfiles: + Issue10271.33.test.diff
2011-04-17 13:50:38lekmasetfiles: + Issue10271.33.fix.diff

messages: + msg133927
versions: + Python 3.3
2011-02-04 20:20:14brett.cannonsetnosy: brett.cannon, lekma
messages: + msg127936
2011-02-04 10:46:32lekmasetnosy: brett.cannon, lekma
messages: + msg127883
2011-02-02 13:19:06lekmasetfiles: + Issue10271.diff
nosy: brett.cannon, lekma
keywords: + patch
2010-10-31 19:03:29brett.cannonsetversions: - Python 2.6, Python 3.1, Python 2.7
2010-10-31 19:03:15brett.cannonsetassignee: brett.cannon

nosy: + brett.cannon
2010-10-31 18:53:34lekmacreate