Skip to content

Commit

Permalink
Make the type checker happy
Browse files Browse the repository at this point in the history
For DataReader to be considered file like it has to match the interface exactly, hence DataReader.read has to have a default argument for count(), it also needs to return a bytes object for all code paths.
  • Loading branch information
TomHodson committed Oct 3, 2024
1 parent d72a3a5 commit b00f7e8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pyfdb/pyfdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
import io
import os
from typing import Iterator

import cffi
import findlibs
Expand Down Expand Up @@ -262,13 +263,14 @@ def tell(self):
lib.fdb_datareader_tell(self.__dataread, where)
return where[0]

def read(self, count):
def read(self, count=-1) -> bytes:
self.open()
if isinstance(count, int):
buf = bytearray(count)
read = ffi.new("long*")
lib.fdb_datareader_read(self.__dataread, ffi.from_buffer(buf), count, read)
return buf[0 : read[0]]
return bytearray()

def __enter__(self):
return self
Expand Down Expand Up @@ -298,10 +300,10 @@ def archive(self, data, request=None):
def flush(self):
lib.fdb_flush(self.ctype)

def list(self, request=None, duplicates=False, keys=False):
def list(self, request=None, duplicates=False, keys=False) -> Iterator[dict]:
return ListIterator(self, request, duplicates, keys)

def retrieve(self, request):
def retrieve(self, request) -> DataRetriever:
return DataRetriever(self, request)

@property
Expand All @@ -319,7 +321,7 @@ def archive(data):
fdb.archive(data)


def list(request, duplicates=False, keys=False):
def list(request, duplicates=False, keys=False) -> Iterator[dict]:
global fdb
if not fdb:
fdb = FDB()
Expand Down

0 comments on commit b00f7e8

Please sign in to comment.