Skip to content

Commit cfd4dd2

Browse files
committed
chore(file_utils): fix reportIncompatibleMethodOverride lints
This check is currently turned off in our `basic` `typeCheckingMode` profile, but is enabled in the `standard` profile. Things done here: - matched the signature of `__exit__` and `seekable` to `mmap`'s type stub. - indicate that `seekable` is present in `mmap` in Python 3.13+ - ignored the `seek` method, as we explicitly wanted it to return the file position similarly to the standard file api Error: unblob/file_utils.py unblob/file_utils.py:70:9 - error: Method "seek" overrides class "mmap" in an incompatible manner   Return type mismatch: base method returns type "None", override returns type "int"     "int" is not assignable to "None" (reportIncompatibleMethodOverride) unblob/file_utils.py:94:9 - error: Method "__exit__" overrides class "mmap" in an incompatible manner   Positional parameter count mismatch; base method has 2, but override has 4   Parameter "args" is missing in override (reportIncompatibleMethodOverride) unblob/file_utils.py:103:9 - error: Method "seekable" overrides class "mmap" in an incompatible manner   Return type mismatch: base method returns type "Literal[True]", override returns type "bool"     "bool" is not assignable to type "Literal[True]" (reportIncompatibleMethodOverride)
1 parent 50b93c4 commit cfd4dd2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

unblob/file_utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
import shutil
1010
import struct
11+
import sys
1112
import unicodedata
1213
from collections.abc import Iterable, Iterator
1314
from pathlib import Path
@@ -67,7 +68,7 @@ def from_path(cls, path: Path, access=mmap.ACCESS_READ):
6768
m.access = access
6869
return m
6970

70-
def seek(self, pos: int, whence: int = os.SEEK_SET) -> int:
71+
def seek(self, pos: int, whence: int = os.SEEK_SET) -> int: # pyright: ignore[reportIncompatibleMethodOverride]
7172
try:
7273
super().seek(pos, whence)
7374
except ValueError as e:
@@ -91,7 +92,7 @@ def size(self) -> int:
9192
def __enter__(self):
9293
return self
9394

94-
def __exit__(self, _exc_type, _exc_val, _exc_tb):
95+
def __exit__(self, *args):
9596
self.close()
9697

9798
def readable(self) -> bool:
@@ -100,8 +101,10 @@ def readable(self) -> bool:
100101
def writable(self) -> bool:
101102
return self.access in (mmap.ACCESS_WRITE, mmap.ACCESS_COPY)
102103

103-
def seekable(self) -> bool:
104-
return True # Memory-mapped files are always seekable
104+
if sys.version_info < (3, 13):
105+
106+
def seekable(self) -> Literal[True]:
107+
return True # Memory-mapped files are always seekable
105108

106109

107110
class OffsetFile:

0 commit comments

Comments
 (0)