-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Inconsistent behavior between _io.text_encoding
and _pyio.text_encoding
#127611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Indeed, the C function signature is marked as positional-only: cpython/Modules/_io/_iomodule.c Lines 457 to 460 in e51da64
This was originally added when PEP 597 was implemented: However, I didn't find any comments in the PR explaining why this is so. In addition, the example implementation in the PEP also allows keyword arguments. cc @methane as the original author |
I just didn't care it well. The doc uses positional only argument. It is official specification than the PEP. Unless clear use case for keyword argument here, how about just prohibit keyword argument on |
Firstly, the documentation doesn't say anything about how to use the cpython/Modules/_io/_iomodule.c Lines 74 to 82 in e51da64
Secondly, if we remove I just suggest to consider |
@methane, oh sorry my bad. |
This is why I am proposing just remove it unless there is clear benefits. |
@methane, sounds good enough to me. I have no more objections to fixing the python implementation. |
_io.text_encoding
function_io.text_encoding
and _pyio.text_encoding
Requiring positional-only arguments in For one, it's not a breaking change, unlike changing |
FWIW, this function is not for regular users. This function is for almost only stdlib. 3rd party libraries may need it too, but it is rare. That is why I am reluctant to make API improvements that would require a what's new entry and |
Does PyPy uses the pure-python implementation |
No. PyPy has own builtin |
No consensus yet. I don't want to change this function. This function is almost only for stdlib. No need to improve usability for many users. |
We have a similar case for |
They are very different functions. It seems a foolish consistency.
|
They may be different but IMO the issue is the same. A publicly documented function that behaves differently with the C and the Python implementation. But if you don't want the parallel, I'm ok (and would therefore rather not change |
I agree with @picnixz. If we don't want to change the C implementation, I'd also prefer to not do anything since there seems to be very little benefit to restricting the Python implementation for the sake of consistency. |
I found another issue #89979 on a related topic, maybe it's worth moving this whole discussion here (but it's not progressing there) This problem is common but no one takes the initiative to solve it. |
In general, the Python implementation is aligned with the C implementation when the Python implementation is used by other implementations (e.g., functools for pypy). If it's not, we tend not to bother too much 1) if existing code that works with the C implementation works, or 2) if it is half public API or can be replaced by a more modern approach. So, indeed, the functools issue is different (because there is a downstream user using the Python implementation as its sole alternative); sorry for that, this was my bad. Note that in both cases, we document the API with positional-only, so whatever implementation we choose, it's actually ok if users follow the docs. Now, in the datetime case, the documentation does not put restrictions so people could assume that keyword arguments are allowed while they are not in some implementations (so following the docs could break their code on some Python implementations). It's again a slightly different issue compared to this one and the functools one.
Inada is a core dev, and likely the code owner of unicode-related stuff. So that "someone" would be them. |
Closing, as Inada-san clearly prefer status quo. |
Bug report
Bug description:
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
The text was updated successfully, but these errors were encountered: