Skip to content

Commit 035b699

Browse files
Enhance type hinting for optional imports in persistent storage modules
- Added type ignore comments for optional imports of plyvel and rocksdb to improve type checking. - Updated the RocksDBDatastoreSync class to include a type ignore comment for the dynamically imported _rocksdb module, ensuring better compatibility with type checkers.
1 parent 45ae052 commit 035b699

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

libp2p/peer/persistent/datastore/rocksdb_sync.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def _ensure_connection(self) -> None:
111111
setattr(opts, key, value)
112112

113113
# Open RocksDB database
114-
self.db = self._rocksdb.DB(str(self.path), opts)
114+
# pyrefly can't infer types for dynamically imported modules
115+
self.db = self._rocksdb.DB(str(self.path), opts) # type: ignore[missing-attribute]
115116

116117
def get(self, key: bytes) -> bytes | None:
117118
"""Retrieve a value by key."""

libp2p/peer/persistent/factory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
# Optional imports - check availability once at module level
1212
try:
13-
import plyvel
13+
import plyvel # type: ignore[import-untyped]
1414

1515
PLYVEL_AVAILABLE = True
1616
except ImportError:
17-
plyvel = None
17+
plyvel = None # type: ignore[assignment]
1818
PLYVEL_AVAILABLE = False
1919

2020
try:
21-
import rocksdb
21+
import rocksdb # type: ignore[import-untyped]
2222

2323
ROCKSDB_AVAILABLE = True
2424
except ImportError:
25-
rocksdb = None
25+
rocksdb = None # type: ignore[assignment]
2626
ROCKSDB_AVAILABLE = False
2727

2828
from .async_.peerstore import AsyncPersistentPeerStore

0 commit comments

Comments
 (0)