Skip to content
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

binascii: Improve bytes types #7677

Merged
merged 3 commits into from
Apr 23, 2022
Merged
Changes from all 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
44 changes: 26 additions & 18 deletions stdlib/binascii.pyi
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
import sys
from _typeshed import ReadableBuffer
from typing_extensions import TypeAlias

def a2b_uu(__data: str | bytes) -> bytes: ...
# Many functions in binascii accept buffer objects
# or ASCII-only strings.
_AsciiBuffer: TypeAlias = str | ReadableBuffer

def a2b_uu(__data: _AsciiBuffer) -> bytes: ...

if sys.version_info >= (3, 7):
def b2a_uu(__data: bytes, *, backtick: bool = ...) -> bytes: ...
def b2a_uu(__data: ReadableBuffer, *, backtick: bool = ...) -> bytes: ...

else:
def b2a_uu(__data: bytes) -> bytes: ...
def b2a_uu(__data: ReadableBuffer) -> bytes: ...

def a2b_base64(__data: str | bytes) -> bytes: ...
def b2a_base64(__data: bytes, *, newline: bool = ...) -> bytes: ...
def a2b_qp(data: str | bytes, header: bool = ...) -> bytes: ...
def b2a_qp(data: bytes, quotetabs: bool = ..., istext: bool = ..., header: bool = ...) -> bytes: ...
def a2b_base64(__data: _AsciiBuffer) -> bytes: ...
def b2a_base64(__data: ReadableBuffer, *, newline: bool = ...) -> bytes: ...
def a2b_qp(data: _AsciiBuffer, header: bool = ...) -> bytes: ...
def b2a_qp(data: ReadableBuffer, quotetabs: bool = ..., istext: bool = ..., header: bool = ...) -> bytes: ...

if sys.version_info < (3, 11):
def a2b_hqx(__data: str | bytes) -> bytes: ...
def rledecode_hqx(__data: bytes) -> bytes: ...
def rlecode_hqx(__data: bytes) -> bytes: ...
def b2a_hqx(__data: bytes) -> bytes: ...
def a2b_hqx(__data: _AsciiBuffer) -> bytes: ...
def rledecode_hqx(__data: ReadableBuffer) -> bytes: ...
def rlecode_hqx(__data: ReadableBuffer) -> bytes: ...
def b2a_hqx(__data: ReadableBuffer) -> bytes: ...

def crc_hqx(__data: bytes, __crc: int) -> int: ...
def crc32(__data: bytes, __crc: int = ...) -> int: ...
def b2a_hex(__data: bytes) -> bytes: ...
def crc_hqx(__data: ReadableBuffer, __crc: int) -> int: ...
def crc32(__data: ReadableBuffer, __crc: int = ...) -> int: ...

if sys.version_info >= (3, 8):
def hexlify(data: bytes, sep: str | bytes = ..., bytes_per_sep: int = ...) -> bytes: ...
# sep must be str or bytes, not bytearray or any other buffer
def b2a_hex(data: ReadableBuffer, sep: str | bytes = ..., bytes_per_sep: int = ...) -> bytes: ...
def hexlify(data: ReadableBuffer, sep: str | bytes = ..., bytes_per_sep: int = ...) -> bytes: ...

else:
def hexlify(__data: bytes) -> bytes: ...
def b2a_hex(__data: ReadableBuffer) -> bytes: ...
def hexlify(__data: ReadableBuffer) -> bytes: ...

def a2b_hex(__hexstr: str | bytes) -> bytes: ...
def unhexlify(__hexstr: str | bytes) -> bytes: ...
def a2b_hex(__hexstr: _AsciiBuffer) -> bytes: ...
def unhexlify(__hexstr: _AsciiBuffer) -> bytes: ...

class Error(ValueError): ...
class Incomplete(Exception): ...