This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: open builtin has no signature in docstring
Type: Stage:
Components: Library (Lib) Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pitrou Nosy List: englabenny, flox, georg.brandl, pitrou
Priority: normal Keywords: patch

Created on 2009-12-01 13:41 by englabenny, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue7417_py3k.diff flox, 2009-12-02 14:37 Patch against branches/py3k
issue7417_py3k_explicit.diff flox, 2009-12-02 16:11 Patch against branches/py3k (explicit signature)
Messages (13)
msg95856 - (view) Author: (englabenny) Date: 2009-12-01 13:41
Python 3.1.1's open has no signature in the docstring so the
documentation for this builtin function is unfortunately very confusing
(IMO is missing the most important part).

>>> help(open)

open(...)
    Open file and return a stream.  Raise IOError upon failure.
    
    ...

----

This must be a regression from the C port of the io module.

I'm keeping my eyes open for more issues like this. Python must be more
friendly to newcomers, but I have seen tendencies of confusing
documentation in Python 3.
msg95858 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-01 14:48
Proposed docstring patch.
msg95877 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-12-01 21:35
Looks good to me (module indentation).
msg95878 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-12-01 21:35
Make that "modulo."
msg95885 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-01 23:20
Indentation is not easy on this part.
The list of arguments overflow the 79 chars limit.
With the proposed patch, the generated output is something like:


open(file, mode='r', buffering=None, encoding=None,
           errors=None, newline=None, closefd=True) -> file object

Open file and return a stream.  Raise IOError upon failure.

...


Is it wrong?
msg95897 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-02 07:59
According to PEP257:
«Multi-line docstrings consist of a summary line just like a one-line
docstring, followed by a blank line, followed by a more elaborate
description.»

Maybe this second patch is more conventional?
msg95898 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-02 08:22
Actually the docstring of _pyio.open Python function should not change.

The patch is smaller.
msg95903 - (view) Author: (englabenny) Date: 2009-12-02 13:12
import builtins; help(builtins)

Looking around, the new suggestion is absolutely unconventional. The
signature must be on the first line. One builtin function even uses two
lines; min:

        min(iterable[, key=func]) -> value
        min(a, b, c, ...[, key=func]) -> value
        
        With a single iterable argument, return its smallest item.
        With two or more arguments, return the smallest argument.

I would ack a two-line signature at the start of the docstring, however
I will also suggest an alternative:

Aligning open's signature description with the builtins module, this is
the style that is most common:

open(file[, mode[, buffering[, encoding[, errors[, newline[,
closefd]]]]]]) -> file object

perhaps even an abbreviation is allowed at the end?

open(file[, mode[, buffering[, encoding[, errors[, newline[,
closefd]..]) -> file object

However that open has so many kwargs should almost be a bug in itself.
msg95908 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-02 14:37
Ulrik,

I agree that most builtins have the signature on first lines.
I will not apply this part of the PEP257.

But it seems that the "[...]" syntax is not enforced for all builtins.
See "help(print)", "help(sorted)" and "help(__import__)" examples:

>>> print(print.__doc__)
print(value, ..., sep=' ', end='\n', file=sys.stdout)

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep:  string inserted between values, default a space.
end:  string appended after the last value, default a newline.

>>> print(sorted.__doc__)
sorted(iterable, key=None, reverse=False) --> new sorted list

>>> print(__import__.__doc__)
__import__(name, globals={}, locals={}, fromlist=[], level=-1) -> module

Import a module.  The globals are only used to determine the context;
they are not modified...



Patch is updated.
msg95910 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-02 15:35
Or I suggest something more verbose...


>>> print(open.__doc__)
open(filename) -> file object for reading in text mode

open(filename, mode=binary[, buffering]) -> file object in binary mode
open(filename[, mode=text][, buffering][,encoding][,errors][,newline])
                                         -> file object in text mode

open(file_descriptor[, ...][, closefd]) -> file object

Open file and return a stream.  Raise IOError upon failure.

filename is either a text or byte string giving the name (and the path
if the file isn't in the current working directory) of the file to
be opened.

file_descriptor is an integer file descriptor of the file to be
wrapped. The file descriptor is closed when the returned I/O object is
closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file
is opened...
msg95911 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-02 16:06
(patch attached: explicit signature)

I vote +1 for something more explicit.
« Explicit is better than implicit. »

>>> help(open)
Help on built-in function open in module io:

open(...)
    open(file_name_or_path) -> file object for reading in text mode
    open(file_name_or_path, mode=binary_mode[, buffering]) -> file objec
    open(file_name_or_path[, mode=text_mode[, buffering[, encoding
                          [, errors[, newline]]]]]) -> file object
    open(file_descriptor[, ...[, closefd]]) -> file object
    
    Open file and return a stream.  Raise IOError upon failure.
    
    file_name_or_path is either a text or byte string giving the name
    (and the path if the file isn't in the current working directory)
    of the file to be opened.
    
    file_descriptor is an integer file descriptor of the file to be
    wrapped. The file descriptor is closed when the returned I/O object
    is closed, unless closefd is set to False.)
    
    mode is an optional string that specifies the mode in which the file
    is opened...
msg96582 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-12-18 20:00
Georg, I'm a bit lost in the different suggestions. Your take? Do you
have any preference? Or should we simply copy the docstring from _pyio's
open() function?
msg96835 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-12-23 10:31
Added signature from msg95885 in r77009.
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51666
2009-12-23 10:31:11georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg96835
2009-12-18 20:00:12pitrousetmessages: + msg96582
2009-12-02 16:11:28floxsetfiles: - issue7417_py3k_explicit.diff
2009-12-02 16:11:22floxsetfiles: + issue7417_py3k_explicit.diff
2009-12-02 16:06:29floxsetfiles: + issue7417_py3k_explicit.diff

messages: + msg95911
2009-12-02 15:35:29floxsetmessages: + msg95910
2009-12-02 14:37:47floxsetfiles: - issue7417_py3k.diff
2009-12-02 14:37:28floxsetfiles: + issue7417_py3k.diff

messages: + msg95908
2009-12-02 13:12:11englabennysetmessages: + msg95903
2009-12-02 08:22:41floxsetfiles: + issue7417_py3k.diff

messages: + msg95898
2009-12-02 08:21:18floxsetfiles: - issue7417_py3k.diff
2009-12-02 08:21:14floxsetfiles: - issue7417_py3k_pep257.diff
2009-12-02 07:59:39floxsetfiles: + issue7417_py3k_pep257.diff

messages: + msg95897
2009-12-01 23:20:31floxsetmessages: + msg95885
2009-12-01 21:35:32georg.brandlsetmessages: + msg95878
2009-12-01 21:35:22georg.brandlsetassignee: pitrou

messages: + msg95877
nosy: + georg.brandl, pitrou
2009-12-01 14:48:44floxsetfiles: + issue7417_py3k.diff
versions: + Python 3.2
nosy: + flox

messages: + msg95858

keywords: + patch
2009-12-01 13:41:41englabennycreate