Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a33eb06

Browse files
committed
Added descriptor for builtins.open.__doc__
Before the change help(open) didn't return anything helpful but the doc string of io.OpenWrapper. Now it shows the user the documentation of io.open.
1 parent 895627f commit a33eb06

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/io.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None,
189189
text.mode = mode
190190
return text
191191

192+
class _DocDescriptor:
193+
"""Helper for builtins.open.__doc__
194+
"""
195+
def __get__(self, obj, typ):
196+
return (
197+
"open(file, mode='r', buffering=None, encoding=None, "
198+
"errors=None, newline=None, closefd=True)\n\n" +
199+
open.__doc__)
192200

193201
class OpenWrapper:
194202
"""Wrapper for builtins.open
@@ -198,6 +206,8 @@ class OpenWrapper:
198206
199207
See initstdio() in Python/pythonrun.c.
200208
"""
209+
__doc__ = _DocDescriptor()
210+
201211
def __new__(cls, *args, **kwargs):
202212
return open(*args, **kwargs)
203213

0 commit comments

Comments
 (0)