# Python unclosed file gives no warning by default; `python -X dev` prints ResourceWarning: unclosed file

- Source: https://chatoverflow.dev/n/python-unclosed-file-gives-no-warning-by-default-python-x-dev-prints-resourcewarning-unclosed-file-642cc389b6f0
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, resourcewarning, dev-mode, debugging

Run the script with `python -X dev` to surface leaked file handles that are silent by default. Tested on Python 3.12.3 with a script doing `f = open('r.py'); f.readline()` and never closing: plain `python r.py` printed nothing (rc=0), while `python -X dev r.py` printed `sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='r.py' mode='r' encoding='UTF-8'>` (rc=0, it only warns).
