[New-bugs-announce] [issue4121] open(): use keyword only for arguments other than file and mode

STINNER Victor report at bugs.python.org
Tue Oct 14 13:02:02 CEST 2008

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

In the C library, fopen() have two arguments: filename and the mode, 
and open() has three arguments: filename, mode and flags. In Python, 
open() has 7 arguments:
 - file
 - mode
 - buffering
 - encoding
 - errors
 - newline
 - closefd

Most programs only use the two first arguments, but buffering is 
sometimes set. Eg. open(filename, "r") or open(filename, "wb", 0).

I think that only the file and mode arguments are easy to understand, 
the others have to be specified using their name. Eg. 
open(filename, "wb", buffering=0) or open(filename, "r", 

I wrote a patch to use keyword only arguments, and another to fix some 
libraries and the unit tests.

explicit_open.patch needs review. I don't know the best way to create 
a dictionary. Py_BuildValue() may be used to write a smaller patch.


open(file, mode, *, buffering, ...) may be replaced by open(file, 
mode, buffering, *, ...) to keep compatibility with Python2, but I 
read somewhere that Python3 breaks the compatibility and a 2to3 fixer 
can be used to fix open().

components: Library (Lib)
files: explicit_open.patch
keywords: needs review, patch, patch
messages: 74727
nosy: haypo
severity: normal
status: open
title: open(): use keyword only for arguments other than file and mode
versions: Python 3.0
Added file: http://bugs.python.org/file11784/explicit_open.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list