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

Fix mypy issues #14

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[mypy]
disallow_untyped_defs = True
check_untyped_defs = True
warn_return_any = True
python_version = 3.8
mypy_path = $MYPY_CONFIG_FILE_DIR/src
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ requires = [
"setuptools >= 42",
"wheel",
"cython >= 3.0.0a11",
"versioneer",
]
build-backend = "setuptools.build_meta"
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ packages = find_namespace:
package_dir =
= src
zip_safe = False
python_requires = ~=3.6
python_requires = ~=3.8

[options.packages.find]
where = src
Expand All @@ -37,7 +37,8 @@ docs =
dev =
black>=22.3
pre_commit>=1.11.1
cython >= 3.0.0a9
cython ~= 3.0
mypy


# See the docstring in versioneer.py for instructions. Note that you must
Expand Down
57 changes: 29 additions & 28 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

sys.path.append(os.path.dirname(__file__))
import versioneer

sys.path.remove(os.path.dirname(__file__))

define_macros = []
Expand All @@ -16,36 +17,41 @@
extra_sources = []

if sys.platform == "win32":
define_macros.extend([
("WIN32", None),
("_WIN32_WINNT", "0x0601"),
("LEVELDB_PLATFORM_WINDOWS", None),
("DLLX", "__declspec(dllexport)")
])
extra_sources.extend([
"./leveldb-mcpe/port/port_win.cc",
"./leveldb-mcpe/util/env_win.cc",
"./leveldb-mcpe/util/win_logger.cc",
])
if sys.maxsize > 2 ** 32: # 64 bit python
define_macros.extend(
[
("WIN32", None),
("_WIN32_WINNT", "0x0601"),
("LEVELDB_PLATFORM_WINDOWS", None),
("DLLX", "__declspec(dllexport)"),
]
)
extra_sources.extend(
[
"./leveldb-mcpe/port/port_win.cc",
"./leveldb-mcpe/util/env_win.cc",
"./leveldb-mcpe/util/win_logger.cc",
]
)
if sys.maxsize > 2**32: # 64 bit python
extra_objects.append("bin/zlib/win64/zlibstatic.lib")
else: # 32 bit python
extra_objects.append("bin/zlib/win32/zlibstatic.lib")
elif sys.platform in ["linux", "darwin"]:
define_macros.extend([
("LEVELDB_PLATFORM_POSIX", None),
("DLLX", "")
])
extra_sources.extend([
"./leveldb-mcpe/port/port_posix.cc",
"./leveldb-mcpe/util/env_posix.cc",
])
define_macros.extend([("LEVELDB_PLATFORM_POSIX", None), ("DLLX", "")])
extra_sources.extend(
[
"./leveldb-mcpe/port/port_posix.cc",
"./leveldb-mcpe/util/env_posix.cc",
]
)
libraries.append("z")

if sys.platform == "darwin":
define_macros.append(("OS_MACOSX", None))
# shared_mutex needs MacOS 10.12+
extra_compile_args.extend(["-mmacosx-version-min=10.12", "-Werror=partial-availability"])
extra_compile_args.extend(
["-mmacosx-version-min=10.12", "-Werror=partial-availability"]
)
extra_link_args.extend(["-Wl,-no_weak_imports"])
else:
raise Exception("Unsupported platform")
Expand Down Expand Up @@ -73,8 +79,6 @@
"./leveldb-mcpe/db/version_edit.cc",
"./leveldb-mcpe/db/version_set.cc",
"./leveldb-mcpe/db/write_batch.cc",


"./leveldb-mcpe/table/block.cc",
"./leveldb-mcpe/table/block_builder.cc",
"./leveldb-mcpe/table/filter_block.cc",
Expand All @@ -84,7 +88,6 @@
"./leveldb-mcpe/table/table.cc",
"./leveldb-mcpe/table/table_builder.cc",
"./leveldb-mcpe/table/two_level_iterator.cc",

"./leveldb-mcpe/util/arena.cc",
"./leveldb-mcpe/util/bloom.cc",
"./leveldb-mcpe/util/cache.cc",
Expand All @@ -98,12 +101,10 @@
"./leveldb-mcpe/util/logging.cc",
"./leveldb-mcpe/util/options.cc",
"./leveldb-mcpe/util/status.cc",

"./leveldb-mcpe/db/zlib_compressor.cc",
"./leveldb-mcpe/db/zstd_compressor.cc",
"./leveldb-mcpe/port/port_posix_sse.cc",

*extra_sources
*extra_sources,
],
include_dirs=[
"zlib",
Expand All @@ -118,5 +119,5 @@
define_macros=define_macros,
),
language_level=3,
)
),
)
11 changes: 9 additions & 2 deletions src/leveldb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from ._leveldb import LevelDB, LevelDBException, LevelDBEncrypted, LevelDBIteratorException, Iterator
from ._leveldb import (
LevelDB,
LevelDBException,
LevelDBEncrypted,
LevelDBIteratorException,
Iterator,
)

from . import _version
__version__ = _version.get_versions()['version']

__version__ = _version.get_versions()["version"]
74 changes: 61 additions & 13 deletions src/leveldb/_leveldb.pyi
Original file line number Diff line number Diff line change
@@ -1,25 +1,73 @@
from typing import Dict, Iterator, Tuple
from typing import Dict, Iterator as PyIterator, Tuple

class LevelDBException(Exception):
"""
The exception thrown for all leveldb related errors.
"""

pass

class LevelDBEncrypted(LevelDBException):
pass

class LevelDBIteratorException(LevelDBException):
"""
The exception thrown for issues related to the iterator.
"""

class Iterator:
def valid(self) -> bool:
"""
Is the iterator at a valid entry.
If False, calls to other methods may error.
"""

def seek_to_first(self) -> None:
"""Seek to the first entry in the database."""

def seek_to_last(self) -> None:
"""Seek to the last entry in the database."""

def seek(self, target: bytes) -> None:
"""
Seek to the given entry in the database.
If the entry does not exist it will seek to the location after.
"""

def next(self) -> None:
"""Seek to the next entry in the database."""

def prev(self) -> None:
"""Seek to the previous entry in the database."""

def key(self) -> bytes:
"""
Get the key of the current entry in the database.
If valid returns False this will error.
"""

def value(self) -> bytes:
"""
Get the value of the current entry in the database.
If valid returns False this will error.
"""

class LevelDB:
def __init__(self, path: str, create_if_missing: bool = False): ...
def close(self, compact: bool = False): ...
def close(self, compact: bool = False) -> None: ...
def get(self, key: bytes) -> bytes: ...
def put(self, key: bytes, val: bytes): ...
def putBatch(self, data: Dict[bytes, bytes]): ...
def delete(self, key: bytes): ...
def iterate(self, start: bytes = None, end: bytes = None) -> Iterator[Tuple[bytes, bytes]]: ...
def keys(self) -> Iterator[bytes]: ...
def items(self) -> Iterator[Tuple[bytes, bytes]]: ...
def compact(self) -> None:...
def __contains__(self, key: bytes): ...
def put(self, key: bytes, val: bytes) -> None: ...
def putBatch(self, data: Dict[bytes, bytes]) -> None: ...
def delete(self, key: bytes) -> None: ...
def new_iterator(self) -> Iterator: ...
def iterate(
self, start: bytes | None = None, end: bytes | None = None
) -> PyIterator[Tuple[bytes, bytes]]: ...
def keys(self) -> PyIterator[bytes]: ...
def items(self) -> PyIterator[Tuple[bytes, bytes]]: ...
def compact(self) -> None: ...
def __contains__(self, key: bytes) -> bool: ...
def __getitem__(self, key: bytes) -> bytes: ...
def __setitem__(self, key: bytes, value: bytes): ...
def __delitem__(self, key: bytes): ...
def __iter__(self) -> Iterator[bytes]: ...
def __setitem__(self, key: bytes, value: bytes) -> None: ...
def __delitem__(self, key: bytes) -> None: ...
def __iter__(self) -> PyIterator[bytes]: ...
Loading
Loading