On Wed., Mar. 31, 2021, 18:56 Inada Naoki, <songofaca...@gmail.com> wrote:
> Do we need _pyio at all? > Does PyPy or any other Python implementation use it? > https://www.python.org/dev/peps/pep-0399/ would suggest rolling back Python support is something to avoid. > On Wed, Mar 31, 2021 at 9:36 PM Victor Stinner <vstin...@python.org> > wrote: > > > > Hi, > > > > The io module provides an open() function. It also provides an > > OpenWrapper which only exists to be able to store open as a method > > (class or instance method). In the _pyio module, pure Python > > implementation of the io module, OpenWrapper is implemented as: > > > > class OpenWrapper: > > """Wrapper for builtins.open > > > > 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. > > """ > > def __new__(cls, *args, **kwargs): > > return open(*args, **kwargs) > > > > I would like to remove this class which is causing troubles in the PEP > > 597 implementation, but I don't know how. Simplified problem: > > --- > > def func(): > > print("my func") > > > > class MyClass: > > method = func > > > > func() # A > > MyClass.method() # B > > obj = MyClass() > > obj.method() # C > > --- > > > > With this syntax, A and B work, but C fails with TypeError: func() > > takes 0 positional arguments but 1 was given. > > > > If I decorate func() with @staticmethod, B and C work, but A fails > > with TypeError: 'staticmethod' object is not callable. > > > > Is OpenWrapper the only way to have a callable object which works in > > the 3 variants A, B and C? > > > > A, B and C work if MyClass is modified to use staticmethod: > > > > class MyClass: > > method = staticmethod(func) > > > > Victor > > -- > > Night gathers, and now my watch begins. It shall not end until my death. > > _______________________________________________ > > Python-Dev mailing list -- python-dev@python.org > > To unsubscribe send an email to python-dev-le...@python.org > > https://mail.python.org/mailman3/lists/python-dev.python.org/ > > Message archived at > https://mail.python.org/archives/list/python-dev@python.org/message/QZ7SFW3IW3S2C5RMRJZOOUFSHHUINNME/ > > Code of Conduct: http://python.org/psf/codeofconduct/ > > > > -- > Inada Naoki <songofaca...@gmail.com> > _______________________________________________ > Python-Dev mailing list -- python-dev@python.org > To unsubscribe send an email to python-dev-le...@python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at > https://mail.python.org/archives/list/python-dev@python.org/message/BOSZENKZRZCTIYWDRBRLWT4GKHWGDLWP/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/6WKW5LJKEFSRTZFXXCIS3UWI3YOSKP7L/ Code of Conduct: http://python.org/psf/codeofconduct/