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.

Author graingert
Recipients graingert
Date 2019-06-20.16:16:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1561047387.04.0.201074176939.issue37350@roundup.psfhosted.org>
In-reply-to
Content
Current behaviour 

$ cat foo.py
def foo():
    open('foo', 'wb')


foo()
$ python3.8 -W all::ResourceWarning -X tracemalloc=5 foo.py
foo.py:2: ResourceWarning: unclosed file <_io.BufferedWriter name='foo'>
  open('foo', 'wb')
Object allocated at (most recent call last):
  File "foo.py", lineno 5
    foo()
  File "foo.py", lineno 2
    open('foo', 'wb')
$ python3.8 -W error -X tracemalloc=5 foo.py
Exception ignored in: <_io.FileIO name='foo' mode='wb' closefd=True>
ResourceWarning: unclosed file <_io.BufferedWriter name='foo'>

Expected behaviour

# Pastebin Eu0gvZ5Z
$ cat foo.py
def foo():
    open('foo', 'wb')


foo()
$ python3.8 -W all::ResourceWarning -X tracemalloc=5 foo.py
foo.py:2: ResourceWarning: unclosed file <_io.BufferedWriter name='foo'>
  open('foo', 'wb')
Object allocated at (most recent call last):
  File "foo.py", lineno 5
    foo()
  File "foo.py", lineno 2
    open('foo', 'wb')
$ python3.8 -W error -X tracemalloc=5 foo.py
Exception ignored in: <_io.FileIO name='foo' mode='wb' closefd=True>
ResourceWarning: unclosed file <_io.BufferedWriter name='foo'>
  open('foo', 'wb')
Object allocated at (most recent call last):
  File "foo.py", lineno 5
    foo()
  File "foo.py", lineno 2
    open('foo', 'wb')
History
Date User Action Args
2019-06-20 16:16:27graingertsetrecipients: + graingert
2019-06-20 16:16:27graingertsetmessageid: <1561047387.04.0.201074176939.issue37350@roundup.psfhosted.org>
2019-06-20 16:16:27graingertlinkissue37350 messages
2019-06-20 16:16:26graingertcreate