STINNER Victor added the comment: Ok, I now understand the problem better. They are two kinds of io objects:
(1) object which directly or indirectly owns a limited resource like file descriptor => must emit a ResourceWarning (2) object which don't own a limited resource => no ResourceWarning must be logged Examples of (1): FileIO, BufferedReader(FileIO), TextIOWrapper(BufferedReader(FileIO)) Examples of (2): BytesIO, BuffereadReader(BytesIO), TextIOWrapper(BuffereadReader(BytesIO)) The tricky part is to decide if an object owns a limited resource or not. Currently, the io module uses the _dealloc_warn() trick. A close() method tries to call _dealloc_warn(), but it ignores any exception when calling _dealloc_warn(). BufferedReader calls raw._dealloc_warn(). TextIOWrapper calls buffer._dealloc_warn(). For case (1), BufferedReader(FileIO).close() calls FileIO._dealloc_warn() => ResourceWarning is logged For case (2), BufferedReader(BytesIO).close() calls BytesIO._dealloc_warn() raises an AttributeError => no warning is logged Well, we can call this a hack, but it works :-) pyio_res_warn-3.patch implements the same hack in _pyio. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19829> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com