◐ Shell
clean mode source ↗

Message 306548 - Python tracker

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