From e088d13f2f0f41aa61ee814870bfb0f751ecc680 Mon Sep 17 00:00:00 2001 From: Lorenzo Bolla Date: Thu, 25 Feb 2016 09:41:32 +0000 Subject: [PATCH] Issue #87 Stub for shelve Py3's `shelve` is more restrictive, requiring keys to be `str`, whereas Py2 allows any hashable type. E.g.: s = Shelf({}) s[1] = 'one' # raises AttributeError in py3, but it's OK in Py2 --- stdlib/2.7/shelve.pyi | 33 +++++++++++++++++++++++++++++++++ stdlib/3/shelve.pyi | 31 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 stdlib/2.7/shelve.pyi create mode 100644 stdlib/3/shelve.pyi diff --git a/stdlib/2.7/shelve.pyi b/stdlib/2.7/shelve.pyi new file mode 100644 index 000000000..f5a92b9a2 --- /dev/null +++ b/stdlib/2.7/shelve.pyi @@ -0,0 +1,33 @@ +from typing import Any, Dict, Iterator, List, Optional, Tuple +import collections + + +class Shelf(collections.MutableMapping): + def __init__(self, dict: Dict[Any, Any], protocol: Optional[int] = None, writeback: bool = ..., keyencoding: str = 'utf-8') -> None: ... + def __iter__(self) -> Iterator[str]: ... + def keys(self) -> List[Any]: ... + def __len__(self) -> int: ... + def has_key(self, key: Any) -> bool: ... + def __contains__(self, key: Any) -> bool: ... + def get(self, key: Any, default: Any = None) -> Any: ... + def __getitem__(self, key: Any) -> Any: ... + def __setitem__(self, key: Any, value: Any) -> None: ... + def __delitem__(self, key: Any) -> None: ... + def __enter__(self) -> Shelf: ... + def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... + def close(self) -> None: ... + def __del__(self) -> None: ... + def sync(self) -> None: ... + +class BsdDbShelf(Shelf): + def __init__(self, dict: Dict[Any, Any], protocol: Optional[int] = None, writeback: bool = ..., keyencoding: str = 'utf-8') -> None: ... + def set_location(self, key: Any) -> Tuple[str, Any]: ... + def next(self) -> Tuple[str, Any]: ... + def previous(self) -> Tuple[str, Any]: ... + def first(self) -> Tuple[str, Any]: ... + def last(self) -> Tuple[str, Any]: ... + +class DbfilenameShelf(Shelf): + def __init__(self, filename: str, flag: str = 'c', protocol: Optional[int] = None, writeback: bool = ...) -> None: ... + +def open(filename: str, flag: str = 'c', protocol: Optional[int] = None, writeback: bool = ...) -> DbfilenameShelf: ... diff --git a/stdlib/3/shelve.pyi b/stdlib/3/shelve.pyi new file mode 100644 index 000000000..ab6b2d965 --- /dev/null +++ b/stdlib/3/shelve.pyi @@ -0,0 +1,31 @@ +from typing import Any, Dict, Iterator, Optional, Tuple +import collections + + +class Shelf(collections.MutableMapping): + def __init__(self, dict: Dict[bytes, Any], protocol: Optional[int] = None, writeback: bool = ..., keyencoding: str = 'utf-8') -> None: ... + def __iter__(self) -> Iterator[str]: ... + def __len__(self) -> int: ... + def __contains__(self, key: Any) -> bool: ... # key should be str, but it would conflict with superclass's type signature + def get(self, key: str, default: Any = None) -> Any: ... + def __getitem__(self, key: str) -> Any: ... + def __setitem__(self, key: str, value: Any) -> None: ... + def __delitem__(self, key: str) -> None: ... + def __enter__(self) -> Shelf: ... + def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... + def close(self) -> None: ... + def __del__(self) -> None: ... + def sync(self) -> None: ... + +class BsdDbShelf(Shelf): + def __init__(self, dict: Dict[bytes, Any], protocol: Optional[int] = None, writeback: bool = ..., keyencoding: str = 'utf-8') -> None: ... + def set_location(self, key: Any) -> Tuple[str, Any]: ... + def next(self) -> Tuple[str, Any]: ... + def previous(self) -> Tuple[str, Any]: ... + def first(self) -> Tuple[str, Any]: ... + def last(self) -> Tuple[str, Any]: ... + +class DbfilenameShelf(Shelf): + def __init__(self, filename: str, flag: str = 'c', protocol: Optional[int] = None, writeback: bool = ...) -> None: ... + +def open(filename: str, flag: str = 'c', protocol: Optional[int] = None, writeback: bool = ...) -> DbfilenameShelf: ...