Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stdlib/@tests/test_cases/check_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
assert_type(codecs.decode(b"x", "unicode-escape"), str)

assert_type(codecs.decode(b"x", "utf-8"), str)
assert_type(codecs.lookup("UTF-8").decode(b"potato", errors="replace"), tuple[str, int])
codecs.lookup("ascii").decode(b"potato", errors="replace") # type: ignore
codecs.decode("x", "utf-8") # type: ignore

assert_type(codecs.decode("ab", "hex"), bytes)
Expand Down
5 changes: 5 additions & 0 deletions stdlib/_codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = "stric
@overload
def decode(obj: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> str: ...

_UTF8Encoding: TypeAlias = Literal["UTF-8", "utf-8", "UTF_8", "utf_8", "UTF8", "utf8"]

@overload
def lookup(encoding: _UTF8Encoding, /) -> codecs._UTF8CodecInfo: ...
@overload
def lookup(encoding: str, /) -> codecs.CodecInfo: ...
def charmap_build(map: str, /) -> dict[int, int] | _EncodingMap: ...
def ascii_decode(data: ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
Expand Down
9 changes: 9 additions & 0 deletions stdlib/codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ else:
_is_text_encoding: bool | None = None,
) -> Self: ...

@type_check_only
class _UTF8Decoder(Protocol):
def __call__(self, input: ReadableBuffer, /, errors: str = ...) -> tuple[str, int]: ...

@type_check_only
class _UTF8CodecInfo(CodecInfo):
@property
def decode(self) -> _UTF8Decoder: ...

def getencoder(encoding: str) -> _Encoder: ...
def getdecoder(encoding: str) -> _Decoder: ...
def getincrementalencoder(encoding: str) -> _IncrementalEncoder: ...
Expand Down
Loading