Skip to content

Commit 3e46f9a

Browse files
dbm: fix bytes handling (#9030)
1 parent 39936cd commit 3e46f9a

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

stdlib/dbm/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from typing_extensions import Literal, TypeAlias
66
__all__ = ["open", "whichdb", "error"]
77

88
_KeyType: TypeAlias = str | bytes
9-
_ValueType: TypeAlias = str | bytes
9+
_ValueType: TypeAlias = str | bytes | bytearray
1010
_TFlags: TypeAlias = Literal[
1111
"r",
1212
"w",

stdlib/dbm/dumb.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ _ValueType: TypeAlias = str | bytes
1010

1111
error = OSError
1212

13+
# This class doesn't exist at runtime. open() can return an instance of
14+
# any of the three implementations of dbm (dumb, gnu, ndbm), and this
15+
# class is intended to represent the common interface supported by all three.
1316
class _Database(MutableMapping[_KeyType, bytes]):
1417
def __init__(self, filebasename: str, mode: str, flag: str = ...) -> None: ...
1518
def sync(self) -> None: ...

stdlib/dbm/gnu.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import sys
2-
from _typeshed import Self
2+
from _typeshed import ReadOnlyBuffer, Self
33
from types import TracebackType
44
from typing import TypeVar, overload
55
from typing_extensions import TypeAlias
66

77
if sys.platform != "win32":
88
_T = TypeVar("_T")
9-
_KeyType: TypeAlias = str | bytes
10-
_ValueType: TypeAlias = str | bytes
9+
_KeyType: TypeAlias = str | ReadOnlyBuffer
10+
_ValueType: TypeAlias = str | ReadOnlyBuffer
1111

1212
open_flags: str
1313

@@ -31,7 +31,7 @@ if sys.platform != "win32":
3131
@overload
3232
def get(self, k: _KeyType) -> bytes | None: ...
3333
@overload
34-
def get(self, k: _KeyType, default: bytes | _T) -> bytes | _T: ...
34+
def get(self, k: _KeyType, default: _T) -> bytes | _T: ...
3535
def keys(self) -> list[bytes]: ...
3636
def setdefault(self, k: _KeyType, default: _ValueType = ...) -> bytes: ...
3737
# Don't exist at runtime

stdlib/dbm/ndbm.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import sys
2-
from _typeshed import Self
2+
from _typeshed import ReadOnlyBuffer, Self
33
from types import TracebackType
44
from typing import TypeVar, overload
55
from typing_extensions import TypeAlias
66

77
if sys.platform != "win32":
88
_T = TypeVar("_T")
9-
_KeyType: TypeAlias = str | bytes
10-
_ValueType: TypeAlias = str | bytes
9+
_KeyType: TypeAlias = str | ReadOnlyBuffer
10+
_ValueType: TypeAlias = str | ReadOnlyBuffer
1111

1212
class error(OSError): ...
1313
library: str
@@ -27,7 +27,7 @@ if sys.platform != "win32":
2727
@overload
2828
def get(self, k: _KeyType) -> bytes | None: ...
2929
@overload
30-
def get(self, k: _KeyType, default: bytes | _T) -> bytes | _T: ...
30+
def get(self, k: _KeyType, default: _T) -> bytes | _T: ...
3131
def keys(self) -> list[bytes]: ...
3232
def setdefault(self, k: _KeyType, default: _ValueType = ...) -> bytes: ...
3333
# Don't exist at runtime

0 commit comments

Comments
 (0)