[issue40235] confusing documentation for IOBase.__exit__

Daniel Holth report at bugs.python.org
Wed Apr 8 23:47:22 EDT 2020


New submission from Daniel Holth <dholth at fastmail.fm>:

The io documentation says:

IOBase is also a context manager and therefore supports the with statement. In this example, file is closed after the with statement’s suite is finished—even if an exception occurs:

with open('spam.txt', 'w') as file:
    file.write('Spam and eggs!')


I read this to mean that my own subclass of io.BufferedIOBase would call close() when used as a context manager.

Instead, it is necessary to provide an implementation of __exit__ that calls close() to get this behavior.

The documentation lists Mixin Methods, but I couldn't find a definition of the term "Mixin Methods" in the docs.

----------
components: IO
messages: 366032
nosy: dholth
priority: normal
severity: normal
status: open
title: confusing documentation for IOBase.__exit__
versions: Python 3.7

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


More information about the Python-bugs-list mailing list