Repository navigation
Allow errors keyword argument in codecs _Encoder, _Decoder, and stream protocols - #16697
hrithiksaini99 wants to merge 1 commit into
Conversation
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
left a comment
There was a problem hiding this comment.
Please remove the tests. In typeshed, we only add regression tests for functions and classes which are known to have caused complex problems in the past, or where stubs are difficult to get right. 100% test coverage for typeshed is neither necessary nor desirable, as it would lead to code duplication.
See tests/REGRESSION.md for more information.
|
Pretty sure this is wrong, see #16447. |
|
Thanks both. @JelleZijlstra is right: the #16447 takes the correct narrower approach by special-casing the UTF-8 codec info, so I'll close this PR rather than duplicate that work. |
Fixes #16441.
In
stdlib/codecs.pyi,_Encoder,_Decoder,_StreamReader, and_StreamWriterwere annotated with trailing/, making all parameters (includingerrors: str = ...) positional-only.However,
codecs.Codec.encode,codecs.Codec.decode, and encoder/decoder implementations accepterrorsby keyword (e.g.codecs.lookup('utf-8').decode(b'potato', errors='replace')). This caused mypy to issue false positive errors:By placing the
/afterinput/stream(def __call__(self, input: ReadableBuffer, /, errors: str = ...) -> tuple[str, int]: ...), the first argument remains positional-only for flexible parameter naming across implementations, whileerrorsis accessible both positionally and by keyword.Added type assertion tests in
stdlib/@tests/test_cases/check_codecs.pycovering keyworderrorscalls oninfo.decodeandinfo.encode.