Skip to content

Commit 5dad506

Browse files
binascii: Improve bytes types (#7677)
Add missing arguments to b2a_hex()
1 parent 00f4031 commit 5dad506

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

stdlib/binascii.pyi

+26-18
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
11
import sys
2+
from _typeshed import ReadableBuffer
3+
from typing_extensions import TypeAlias
24

3-
def a2b_uu(__data: str | bytes) -> bytes: ...
5+
# Many functions in binascii accept buffer objects
6+
# or ASCII-only strings.
7+
_AsciiBuffer: TypeAlias = str | ReadableBuffer
8+
9+
def a2b_uu(__data: _AsciiBuffer) -> bytes: ...
410

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

814
else:
9-
def b2a_uu(__data: bytes) -> bytes: ...
15+
def b2a_uu(__data: ReadableBuffer) -> bytes: ...
1016

11-
def a2b_base64(__data: str | bytes) -> bytes: ...
12-
def b2a_base64(__data: bytes, *, newline: bool = ...) -> bytes: ...
13-
def a2b_qp(data: str | bytes, header: bool = ...) -> bytes: ...
14-
def b2a_qp(data: bytes, quotetabs: bool = ..., istext: bool = ..., header: bool = ...) -> bytes: ...
17+
def a2b_base64(__data: _AsciiBuffer) -> bytes: ...
18+
def b2a_base64(__data: ReadableBuffer, *, newline: bool = ...) -> bytes: ...
19+
def a2b_qp(data: _AsciiBuffer, header: bool = ...) -> bytes: ...
20+
def b2a_qp(data: ReadableBuffer, quotetabs: bool = ..., istext: bool = ..., header: bool = ...) -> bytes: ...
1521

1622
if sys.version_info < (3, 11):
17-
def a2b_hqx(__data: str | bytes) -> bytes: ...
18-
def rledecode_hqx(__data: bytes) -> bytes: ...
19-
def rlecode_hqx(__data: bytes) -> bytes: ...
20-
def b2a_hqx(__data: bytes) -> bytes: ...
23+
def a2b_hqx(__data: _AsciiBuffer) -> bytes: ...
24+
def rledecode_hqx(__data: ReadableBuffer) -> bytes: ...
25+
def rlecode_hqx(__data: ReadableBuffer) -> bytes: ...
26+
def b2a_hqx(__data: ReadableBuffer) -> bytes: ...
2127

22-
def crc_hqx(__data: bytes, __crc: int) -> int: ...
23-
def crc32(__data: bytes, __crc: int = ...) -> int: ...
24-
def b2a_hex(__data: bytes) -> bytes: ...
28+
def crc_hqx(__data: ReadableBuffer, __crc: int) -> int: ...
29+
def crc32(__data: ReadableBuffer, __crc: int = ...) -> int: ...
2530

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

2936
else:
30-
def hexlify(__data: bytes) -> bytes: ...
37+
def b2a_hex(__data: ReadableBuffer) -> bytes: ...
38+
def hexlify(__data: ReadableBuffer) -> bytes: ...
3139

32-
def a2b_hex(__hexstr: str | bytes) -> bytes: ...
33-
def unhexlify(__hexstr: str | bytes) -> bytes: ...
40+
def a2b_hex(__hexstr: _AsciiBuffer) -> bytes: ...
41+
def unhexlify(__hexstr: _AsciiBuffer) -> bytes: ...
3442

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

0 commit comments

Comments
 (0)