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.

Author vstinner
Recipients vstinner
Date 2021-03-31.12:59:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The OpenWrapper function of io and _pyio is an undocumented hack allowing to use the builtin open() function as a method:

class MyClass:
    method = open

MyClass.method(...)    # class method
MyClass().method(...)  # instance method

It is only needed by the _pyio module: the pure Python implementation of the io module:
class DocDescriptor:
    """Helper for
    def __get__(self, obj, typ=None):
        return (
            "open(file, mode='r', buffering=-1, encoding=None, "
                 "errors=None, newline=None, closefd=True)\n\n" +

class OpenWrapper:
    """Wrapper for

    Trick so that open won't become a bound method when stored
    as a class variable (as dbm.dumb does).

    See initstdio() in Python/pylifecycle.c.
    __doc__ = DocDescriptor()

    def __new__(cls, *args, **kwargs):
        return open(*args, **kwargs)

The io module simply uses an alias to open:
OpenWrapper = # for compatibility with _pyio

No wrapper is needed since built-in functions can be used directly as methods. Example:
class MyClass:
    method = len  # built-in function


This example works as expected, it displays "3" two times.

I propose to simply remove io.OpenWrapper and force developers to explicitly use staticmethod:

class MyClass:
    method = staticmethod(open)

io.OpenWrapper is not documented.

I don't understand the remark about dbm.dumb: I fail to see where the built-in open() function is used as a method.
Date User Action Args
2021-03-31 12:59:21vstinnersetrecipients: + vstinner
2021-03-31 12:59:21vstinnersetmessageid: <>
2021-03-31 12:59:21vstinnerlinkissue43680 messages
2021-03-31 12:59:21vstinnercreate