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
This commit is contained in:
Victor Stinner 2016-03-23 00:28:08 +01:00
parent 060f9bb602
commit e19558af1b
13 changed files with 34 additions and 19 deletions

View file

@ -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):