[New-bugs-announce] [issue32089] In developer mode (-X dev), ResourceWarning is only emited once per line numbers

STINNER Victor report at bugs.python.org
Mon Nov 20 09:57:20 EST 2017


New submission from STINNER Victor <victor.stinner at gmail.com>:

The -X dev mode currently *hides* some ResourceWarning warnings:

$ cat x.py 
def func():
    open('/etc/issue')

func()
func()

$ ./python x.py 
x.py:2: ResourceWarning: unclosed file <_io.TextIOWrapper name='/etc/issue' mode='r' encoding='UTF-8'>
  open('/etc/issue')
x.py:2: ResourceWarning: unclosed file <_io.TextIOWrapper name='/etc/issue' mode='r' encoding='UTF-8'>
  open('/etc/issue')

haypo at selma$ ./python -X dev x.py 
x.py:2: ResourceWarning: unclosed file <_io.TextIOWrapper name='/etc/issue' mode='r' encoding='UTF-8'>
  open('/etc/issue')


The problem is that the "-W default" inserted by -X dev overrides the final filter on ResourceWarning:

$ ./python -X dev -c 'import warnings, pprint; pprint.pprint(warnings.filters)'
[('default',
  re.compile('', re.IGNORECASE),
  <class 'Warning'>,
  re.compile(''),
  0),
 ('ignore', None, <class 'BytesWarning'>, None, 0),
 ('always', None, <class 'ResourceWarning'>, None, 0)]

----------
messages: 306548
nosy: ncoghlan, serhiy.storchaka, vstinner
priority: normal
severity: normal
status: open
title: In developer mode (-X dev), ResourceWarning is only emited once per line numbers
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32089>
_______________________________________


More information about the New-bugs-announce mailing list