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: Add optional source parameter to warnings.warn()
Type: enhancement Stage:
Components: Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: python-dev, vstinner
Priority: normal Keywords: patch

Created on 2016-03-21 16:18 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
warnings_warn_source.patch vstinner, 2016-03-21 16:18 review
Messages (3)
msg262137 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-03-21 16:18
Follow-up of the issue #26567 which added PyErr_ResourceWarning() (C API), attached patch adds a new source parameter to the warnings.warn() function (Python API).

source is the destroyed object which emits a ResourceWarning. The source is used to show the traceback where the object was created (allocated) when tracemalloc is used.

The patch also changes _pyio, asyncio and asyncore modules to set the source parameter.

Note: tempfile doesn't set source because it uses a class method:

    @classmethod
    def _cleanup(cls, name, warn_message):
        _shutil.rmtree(name)
        _warnings.warn(warn_message, ResourceWarning)
msg262138 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-03-21 16:20
For asyncio, it should help to fix the ResourceWarning warnings on AIX (which has a broken ssl module):

http://buildbot.python.org/all/builders/PPC64%20AIX%203.x/builds/4700/steps/test/logs/stdio

test_create_server_ssl_verify_failed (test.test_asyncio.test_events.PollEventLoopTests) ... FAIL
/home/shager/cpython-buildarea/3.x.edelsohn-aix-ppc64/build/Lib/unittest/case.py:628: ResourceWarning: unclosed <socket.socket fd=22, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 55439)>
  outcome.errors.clear()
msg262217 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-03-22 23:38
New changeset 3a57ced47459 by Victor Stinner in branch 'default':
Add a source parameter to warnings.warn()
https://hg.python.org/cpython/rev/3a57ced47459
History
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70791
2016-03-22 23:56:48vstinnersetstatus: open -> closed
resolution: fixed
2016-03-22 23:38:35python-devsetnosy: + python-dev
messages: + msg262217
2016-03-21 16:20:24vstinnersetmessages: + msg262138
2016-03-21 16:18:33vstinnercreate