dbm: fix bytes handling (#9030)

This commit is contained in:
Jelle Zijlstra
2022-11-01 02:10:37 -07:00
committed by GitHub
parent 39936cd18a
commit 3e46f9a9ee
4 changed files with 12 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ from typing_extensions import Literal, TypeAlias
__all__ = ["open", "whichdb", "error"]
_KeyType: TypeAlias = str | bytes
_ValueType: TypeAlias = str | bytes
_ValueType: TypeAlias = str | bytes | bytearray
_TFlags: TypeAlias = Literal[
"r",
"w",

View File

@@ -10,6 +10,9 @@ _ValueType: TypeAlias = str | bytes
error = OSError
# This class doesn't exist at runtime. open() can return an instance of
# any of the three implementations of dbm (dumb, gnu, ndbm), and this
# class is intended to represent the common interface supported by all three.
class _Database(MutableMapping[_KeyType, bytes]):
def __init__(self, filebasename: str, mode: str, flag: str = ...) -> None: ...
def sync(self) -> None: ...

View File

@@ -1,13 +1,13 @@
import sys
from _typeshed import Self
from _typeshed import ReadOnlyBuffer, Self
from types import TracebackType
from typing import TypeVar, overload
from typing_extensions import TypeAlias
if sys.platform != "win32":
_T = TypeVar("_T")
_KeyType: TypeAlias = str | bytes
_ValueType: TypeAlias = str | bytes
_KeyType: TypeAlias = str | ReadOnlyBuffer
_ValueType: TypeAlias = str | ReadOnlyBuffer
open_flags: str
@@ -31,7 +31,7 @@ if sys.platform != "win32":
@overload
def get(self, k: _KeyType) -> bytes | None: ...
@overload
def get(self, k: _KeyType, default: bytes | _T) -> bytes | _T: ...
def get(self, k: _KeyType, default: _T) -> bytes | _T: ...
def keys(self) -> list[bytes]: ...
def setdefault(self, k: _KeyType, default: _ValueType = ...) -> bytes: ...
# Don't exist at runtime

View File

@@ -1,13 +1,13 @@
import sys
from _typeshed import Self
from _typeshed import ReadOnlyBuffer, Self
from types import TracebackType
from typing import TypeVar, overload
from typing_extensions import TypeAlias
if sys.platform != "win32":
_T = TypeVar("_T")
_KeyType: TypeAlias = str | bytes
_ValueType: TypeAlias = str | bytes
_KeyType: TypeAlias = str | ReadOnlyBuffer
_ValueType: TypeAlias = str | ReadOnlyBuffer
class error(OSError): ...
library: str
@@ -27,7 +27,7 @@ if sys.platform != "win32":
@overload
def get(self, k: _KeyType) -> bytes | None: ...
@overload
def get(self, k: _KeyType, default: bytes | _T) -> bytes | _T: ...
def get(self, k: _KeyType, default: _T) -> bytes | _T: ...
def keys(self) -> list[bytes]: ...
def setdefault(self, k: _KeyType, default: _ValueType = ...) -> bytes: ...
# Don't exist at runtime