diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-23 00:28:08 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-23 00:28:08 +0100 |
commit | e19558af1b6979edf27f7a05a6e47a8b5d113390 (patch) | |
tree | f901801a0684eba2f662670a178c43d96918c4db /Lib | |
parent | Fix macros in hashtable.h (diff) | |
download | cpython-e19558af1b6979edf27f7a05a6e47a8b5d113390.tar.gz cpython-e19558af1b6979edf27f7a05a6e47a8b5d113390.tar.bz2 cpython-e19558af1b6979edf27f7a05a6e47a8b5d113390.zip |
Add a source parameter to warnings.warn()
Issue #26604:
* Add a new optional source parameter to _warnings.warn() and warnings.warn()
* Modify asyncore, asyncio and _pyio modules to set the source parameter when
logging a ResourceWarning warning
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/_pyio.py | 2 | ||||
-rw-r--r-- | Lib/asyncio/base_events.py | 3 | ||||
-rw-r--r-- | Lib/asyncio/base_subprocess.py | 3 | ||||
-rw-r--r-- | Lib/asyncio/proactor_events.py | 3 | ||||
-rw-r--r-- | Lib/asyncio/selector_events.py | 3 | ||||
-rw-r--r-- | Lib/asyncio/sslproto.py | 3 | ||||
-rw-r--r-- | Lib/asyncio/unix_events.py | 6 | ||||
-rw-r--r-- | Lib/asyncio/windows_utils.py | 3 | ||||
-rw-r--r-- | Lib/asyncore.py | 3 | ||||
-rw-r--r-- | Lib/tempfile.py | 1 | ||||
-rw-r--r-- | Lib/warnings.py | 4 |
11 files changed, 21 insertions, 13 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index c3ad81e6db7..972c082803d 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1514,7 +1514,7 @@ class FileIO(RawIOBase): if self._fd >= 0 and self._closefd and not self.closed: import warnings warnings.warn('unclosed file %r' % (self,), ResourceWarning, - stacklevel=2) + stacklevel=2, source=self) self.close() def __getstate__(self): diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 9d07673fbad..3a42b10cb1b 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -412,7 +412,8 @@ class BaseEventLoop(events.AbstractEventLoop): if compat.PY34: def __del__(self): if not self.is_closed(): - warnings.warn("unclosed event loop %r" % self, ResourceWarning) + warnings.warn("unclosed event loop %r" % self, ResourceWarning, + source=self) if not self.is_running(): self.close() diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py index 73425d9bbcc..efe08313e7a 100644 --- a/Lib/asyncio/base_subprocess.py +++ b/Lib/asyncio/base_subprocess.py @@ -122,7 +122,8 @@ class BaseSubprocessTransport(transports.SubprocessTransport): if compat.PY34: def __del__(self): if not self._closed: - warnings.warn("unclosed transport %r" % self, ResourceWarning) + warnings.warn("unclosed transport %r" % self, ResourceWarning, + source=self) self.close() def get_pid(self): diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index 14c0659ddee..2671a94d55a 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -86,7 +86,8 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin, if compat.PY34: def __del__(self): if self._sock is not None: - warnings.warn("unclosed transport %r" % self, ResourceWarning) + warnings.warn("unclosed transport %r" % self, ResourceWarning, + source=self) self.close() def _fatal_error(self, exc, message='Fatal error on pipe transport'): diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 812fac19f86..cbb36250c96 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -573,7 +573,8 @@ class _SelectorTransport(transports._FlowControlMixin, if compat.PY34: def __del__(self): if self._sock is not None: - warnings.warn("unclosed transport %r" % self, ResourceWarning) + warnings.warn("unclosed transport %r" % self, ResourceWarning, + source=self) self._sock.close() def _fatal_error(self, exc, message='Fatal error on transport'): diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index dde980b68f8..1cea850475d 100644 --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -324,7 +324,8 @@ class _SSLProtocolTransport(transports._FlowControlMixin, if compat.PY34: def __del__(self): if not self._closed: - warnings.warn("unclosed transport %r" % self, ResourceWarning) + warnings.warn("unclosed transport %r" % self, ResourceWarning, + source=self) self.close() def pause_reading(self): diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 7747ff41bb8..2beba3e3abc 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -378,7 +378,8 @@ class _UnixReadPipeTransport(transports.ReadTransport): if compat.PY34: def __del__(self): if self._pipe is not None: - warnings.warn("unclosed transport %r" % self, ResourceWarning) + warnings.warn("unclosed transport %r" % self, ResourceWarning, + source=self) self._pipe.close() def _fatal_error(self, exc, message='Fatal error on pipe transport'): @@ -567,7 +568,8 @@ class _UnixWritePipeTransport(transports._FlowControlMixin, if compat.PY34: def __del__(self): if self._pipe is not None: - warnings.warn("unclosed transport %r" % self, ResourceWarning) + warnings.warn("unclosed transport %r" % self, ResourceWarning, + source=self) self._pipe.close() def abort(self): diff --git a/Lib/asyncio/windows_utils.py b/Lib/asyncio/windows_utils.py index 870cd13abe6..7c63fb904b3 100644 --- a/Lib/asyncio/windows_utils.py +++ b/Lib/asyncio/windows_utils.py @@ -159,7 +159,8 @@ class PipeHandle: def __del__(self): if self._handle is not None: - warnings.warn("unclosed %r" % self, ResourceWarning) + warnings.warn("unclosed %r" % self, ResourceWarning, + source=self) self.close() def __enter__(self): diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 3b51f0f337f..4b046d67e39 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -595,7 +595,8 @@ if os.name == 'posix': def __del__(self): if self.fd >= 0: - warnings.warn("unclosed file %r" % self, ResourceWarning) + warnings.warn("unclosed file %r" % self, ResourceWarning, + source=self) self.close() def recv(self, *args): diff --git a/Lib/tempfile.py b/Lib/tempfile.py index ad687b9a03d..61462357c72 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -797,7 +797,6 @@ class TemporaryDirectory(object): _shutil.rmtree(name) _warnings.warn(warn_message, ResourceWarning) - def __repr__(self): return "<{} {!r}>".format(self.__class__.__name__, self.name) diff --git a/Lib/warnings.py b/Lib/warnings.py index 9fb21a87825..d4f591ee71d 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -233,7 +233,7 @@ def _next_external_frame(frame): # Code typically replaced by _warnings -def warn(message, category=None, stacklevel=1): +def warn(message, category=None, stacklevel=1, source=None): """Issue a warning, or maybe ignore it or raise an exception.""" # Check if message is already a Warning object if isinstance(message, Warning): @@ -283,7 +283,7 @@ def warn(message, category=None, stacklevel=1): filename = module registry = globals.setdefault("__warningregistry__", {}) warn_explicit(message, category, filename, lineno, module, registry, - globals) + globals, source) def warn_explicit(message, category, filename, lineno, module=None, registry=None, module_globals=None, |