Modify load method to support method chaining

Commit c17988c · Harrison Erd · 2026-01-04T23:45:48-05:00

Changeset
c17988cddb24def1abecc3e0c67e8f84245c46f6
Parents
ad2b2f939effdb2207d430775ffd2299edee25ba

View source at this commit

Modify load method to support method chaining

Updated load method to return self for chaining.

Comments

No comments yet.

Log in to comment

Diff

diff --git a/pickledb.py b/pickledb.py
index e3022c0..306808b 100644
--- a/pickledb.py
+++ b/pickledb.py
@@ -80,7 +80,8 @@ class PickleDB:
         """
         Load JSON database from disk into memory.
 
-        Returns True on success (or if the file did not exist / was empty).
+        Returns `self` to allow chaining:
+            db = PickleDB("Example.json").load()
         """
         if os.path.exists(self.location) and os.path.getsize(self.location) > 0:
             async with aiofiles.open(self.location, "rb") as f:
@@ -91,7 +92,7 @@ class PickleDB:
 
         async with self._lock:
             self.db = new_db
-        return True
+        return self
 
     @dualmethod
     async def save(self) -> bool: