]> granicus.if.org Git - python/commitdiff
Added descriptor for builtins.open.__doc__
authorChristian Heimes <christian@cheimes.de>
Sat, 8 Dec 2007 17:47:40 +0000 (17:47 +0000)
committerChristian Heimes <christian@cheimes.de>
Sat, 8 Dec 2007 17:47:40 +0000 (17:47 +0000)
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.

Lib/io.py

index 5066c49af303d4a500dc200f5d511bee56685cbe..05ea94bd426b322e050eedf08e89a42187dc31a2 100644 (file)
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -189,6 +189,14 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None,
     text.mode = mode
     return text
 
+class _DocDescriptor:
+    """Helper for builtins.open.__doc__
+    """
+    def __get__(self, obj, typ):
+        return (
+            "open(file, mode='r', buffering=None, encoding=None, "
+                 "errors=None, newline=None, closefd=True)\n\n" +
+            open.__doc__)
 
 class OpenWrapper:
     """Wrapper for builtins.open
@@ -198,6 +206,8 @@ class OpenWrapper:
 
     See initstdio() in Python/pythonrun.c.
     """
+    __doc__ = _DocDescriptor()
+
     def __new__(cls, *args, **kwargs):
         return open(*args, **kwargs)