On 14/04/2021 2:20 am, Inada Naoki wrote:
Hi, all.
I am implementing PEP 597. During review, Victor suggested to
deprecate `OpenWrapper`. `OpenWrapper` is defined only for
compatibility between C function and Python function:
```
from _pyio import open as py_open
from _io import open as c_open
class C:
py_open = py_open
c_open = c_open
C().c_open("README.rst") # works
C().py_open("README.rst") # TypeError: expected str, bytes or
os.PathLike object, not C
```
So builtin open is not io.open, but io.OpenWrapper in Python 3.9.
Making staticfunction callable fixes this issue.
```
@staticfunction
def open(...): ...
```
Now open defined in Python behaves like C function. We don't need
OpenWrapper anymore.
This has already been committed by Guido's approval. staticmethod is
callable, and OpenWrapper is just an alias of open and deprecated in
master branch.
But Mark Shannon said we shouldn't make such a change without
discussing at python-dev.
I don't know we *should*, but I agree that it is *ideal*.
Then, does anyone oppose this change?
I do (although not strongly).
I think we are changing the wrong thing.
Sometimes code gets moved from C to Python and vice-versa.
The differences in descriptor behavior between builtin function and
Python functions trips people up. We agree on that.
However I don't think changing the behavior of static methods is the way
to fix that.
A staticmethod is not a function, builtin or otherwise. It is a method
that, when called, ignores the object it is attached to.
If we want Python functions to behave like a builtin function, then
marking them `@staticmethod` is misleading, IMO.
I'm also worried about corner cases where this change in behavior will
break code.
I'm all in favor of replacing C code with Python and don't want to make
it difficult.
So, why not add a new descriptor, that clearly describes the intent:
`@non_method` or just `@function`?
The decorator would make a new object that behaves like a
builtin-function, even though it is implemented in Python.
Cheers,
Mark.
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/WRHFP4FKWCCJWOU2JTRVFXB6LSFRATKG/
Code of Conduct: http://python.org/psf/codeofconduct/