Skip to content

Commit bb2895b

Browse files
committed
[API] Type-hint return types
1 parent 5815bf9 commit bb2895b

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

mfusepy.py

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from ctypes.util import find_library
4040
from signal import SIG_DFL, SIGINT, SIGTERM, signal
4141
from stat import S_IFDIR
42-
from typing import List, Optional, Sequence, Tuple, Type, Union
42+
from typing import Any, Iterable, List, Mapping, Optional, Sequence, Tuple, Type, Union
4343

4444
FieldsEntry = Union[Tuple[str, Type], Tuple[str, Type, int]]
4545

@@ -1053,7 +1053,7 @@ def time_of_timespec(ts, use_ns: bool = False) -> float:
10531053
return ts.tv_sec + ts.tv_nsec / 1e9
10541054

10551055

1056-
def set_st_attrs(st, attrs, use_ns: bool = False) -> None:
1056+
def set_st_attrs(st, attrs: Mapping[str, Any], use_ns: bool = False) -> None:
10571057
for key, val in attrs.items():
10581058
if key in ('st_atime', 'st_mtime', 'st_ctime', 'st_birthtime'):
10591059
timespec = getattr(st, key + 'spec', None)
@@ -1679,23 +1679,23 @@ def __call__(self, op, *args):
16791679
return getattr(self, op)(*args)
16801680

16811681
@_nullable_dummy_function
1682-
def access(self, path: str, amode: int):
1682+
def access(self, path: str, amode: int) -> int:
16831683
return 0
16841684

16851685
@_nullable_dummy_function
1686-
def bmap(self, path: str, blocksize: int, idx):
1687-
pass
1686+
def bmap(self, path: str, blocksize: int, idx) -> int:
1687+
return 0
16881688

16891689
@_nullable_dummy_function
1690-
def chmod(self, path: str, mode: int):
1690+
def chmod(self, path: str, mode: int) -> int:
16911691
raise FuseOSError(errno.EROFS)
16921692

16931693
@_nullable_dummy_function
1694-
def chown(self, path: str, uid: int, gid: int):
1694+
def chown(self, path: str, uid: int, gid: int) -> int:
16951695
raise FuseOSError(errno.EROFS)
16961696

16971697
@_nullable_dummy_function
1698-
def create(self, path: str, mode: int, fi=None):
1698+
def create(self, path: str, mode: int, fi=None) -> int:
16991699
'''
17001700
When raw_fi is False (default case), create should return a
17011701
numerical file handle and the signature of create becomes:
@@ -1708,19 +1708,19 @@ def create(self, path: str, mode: int, fi=None):
17081708
raise FuseOSError(errno.EROFS)
17091709

17101710
@_nullable_dummy_function
1711-
def destroy(self, path: str):
1711+
def destroy(self, path: str) -> None:
17121712
'Called on filesystem destruction. Path is always /'
17131713

17141714
@_nullable_dummy_function
1715-
def flush(self, path: str, fh: int):
1715+
def flush(self, path: str, fh: int) -> int:
17161716
return 0
17171717

17181718
@_nullable_dummy_function
1719-
def fsync(self, path: str, datasync: int, fh: int):
1719+
def fsync(self, path: str, datasync: int, fh: int) -> int:
17201720
return 0
17211721

17221722
@_nullable_dummy_function
1723-
def fsyncdir(self, path: str, datasync: int, fh: int):
1723+
def fsyncdir(self, path: str, datasync: int, fh: int) -> int:
17241724
return 0
17251725

17261726
# Either fgetattr or getattr must be non-null or else libfuse 2.6 will segfault
@@ -1729,7 +1729,7 @@ def fsyncdir(self, path: str, datasync: int, fh: int):
17291729
# That particular location seems to have been fixed in 2.8.0 and 2.7.0, but not in 2.6.5.
17301730
# It seems to have been fixed only by accident in feature commit:
17311731
# https://github.com/libfuse/libfuse/commit/3a7c00ec0c156123c47b53ec1cd7ead001fa4dfb
1732-
def getattr(self, path: str, fh: Optional[int] = None):
1732+
def getattr(self, path: str, fh: Optional[int] = None) -> Mapping[str, Any]:
17331733
'''
17341734
Returns a dictionary with keys identical to the stat C structure of
17351735
stat(2).
@@ -1746,15 +1746,15 @@ def getattr(self, path: str, fh: Optional[int] = None):
17461746
return {'st_mode': (S_IFDIR | 0o755), 'st_nlink': 2}
17471747

17481748
@_nullable_dummy_function
1749-
def init(self, path: str):
1749+
def init(self, path: str) -> None:
17501750
'''
17511751
Called on filesystem initialization. (Path is always /)
17521752
17531753
Use it instead of __init__ if you start threads on initialization.
17541754
'''
17551755

17561756
@_nullable_dummy_function
1757-
def init_with_config(self, conn_info, config_3):
1757+
def init_with_config(self, conn_info, config_3) -> None:
17581758
'''
17591759
Called on filesystem initialization. Same function as 'init' but with more parameters.
17601760
Only either 'init' or 'init_with_config' should be overridden.
@@ -1763,17 +1763,17 @@ def init_with_config(self, conn_info, config_3):
17631763
'''
17641764

17651765
@_nullable_dummy_function
1766-
def ioctl(self, path: str, cmd: int, arg, fh: int, flags: int, data):
1766+
def ioctl(self, path: str, cmd: int, arg, fh: int, flags: int, data) -> int:
17671767
raise FuseOSError(errno.ENOTTY)
17681768

17691769
@_nullable_dummy_function
1770-
def link(self, target: str, source: str):
1770+
def link(self, target: str, source: str) -> int:
17711771
'creates a hard link `target -> source` (e.g. ln source target)'
17721772

17731773
raise FuseOSError(errno.EROFS)
17741774

17751775
@_nullable_dummy_function
1776-
def listxattr(self, path: str):
1776+
def listxattr(self, path: str) -> Iterable[str]:
17771777
'''
17781778
Return all extended file attribute keys for the specified path.
17791779
Should return an iterable of text strings.
@@ -1796,19 +1796,19 @@ def getxattr(self, path: str, name, position=0):
17961796
raise FuseOSError(ENOTSUP)
17971797

17981798
@_nullable_dummy_function
1799-
def lock(self, path: str, fh: int, cmd: int, lock):
1799+
def lock(self, path: str, fh: int, cmd: int, lock) -> int:
18001800
raise FuseOSError(errno.ENOSYS)
18011801

18021802
@_nullable_dummy_function
1803-
def mkdir(self, path: str, mode: int):
1803+
def mkdir(self, path: str, mode: int) -> int:
18041804
raise FuseOSError(errno.EROFS)
18051805

18061806
@_nullable_dummy_function
1807-
def mknod(self, path: str, mode: int, dev: int):
1807+
def mknod(self, path: str, mode: int, dev: int) -> int:
18081808
raise FuseOSError(errno.EROFS)
18091809

18101810
@_nullable_dummy_function
1811-
def open(self, path: str, flags: int):
1811+
def open(self, path: str, flags: int) -> int:
18121812
'''
18131813
When raw_fi is False (default case), open should return a numerical
18141814
file handle.
@@ -1822,56 +1822,57 @@ def open(self, path: str, flags: int):
18221822
return 0
18231823

18241824
@_nullable_dummy_function
1825-
def opendir(self, path: str):
1825+
def opendir(self, path: str) -> int:
18261826
'Returns a numerical file handle.'
18271827

18281828
return 0
18291829

18301830
@_nullable_dummy_function
1831-
def read(self, path: str, size: int, offset: int, fh: int):
1832-
'Returns a string containing the data requested.'
1831+
def read(self, path: str, size: int, offset: int, fh: int) -> bytes:
1832+
'Returns bytes containing the requested data.'
18331833

18341834
raise FuseOSError(errno.EIO)
18351835

18361836
@_nullable_dummy_function
1837-
def readdir(self, path: str, fh: int):
1837+
def readdir(self, path: str, fh: int) -> Iterable[Union[str, Tuple[str, Mapping[str, int], int]]]:
18381838
'''
18391839
Can return either a list of names, or a list of (name, attrs, offset)
18401840
tuples. attrs is a dict as in getattr.
1841+
Only st_mode in attrs is used! In the future it may be possible to simply return the mode.
18411842
'''
18421843

18431844
return ['.', '..']
18441845

18451846
@_nullable_dummy_function
1846-
def readlink(self, path: str):
1847+
def readlink(self, path: str) -> str:
18471848
raise FuseOSError(errno.ENOENT)
18481849

18491850
@_nullable_dummy_function
1850-
def release(self, path: str, fh: int):
1851+
def release(self, path: str, fh: int) -> int:
18511852
return 0
18521853

18531854
@_nullable_dummy_function
1854-
def releasedir(self, path: str, fh: int):
1855+
def releasedir(self, path: str, fh: int) -> int:
18551856
return 0
18561857

18571858
@_nullable_dummy_function
1858-
def removexattr(self, path: str, name):
1859+
def removexattr(self, path: str, name) -> int:
18591860
raise FuseOSError(ENOTSUP)
18601861

18611862
@_nullable_dummy_function
1862-
def rename(self, old: str, new: str):
1863+
def rename(self, old: str, new: str) -> int:
18631864
raise FuseOSError(errno.EROFS)
18641865

18651866
@_nullable_dummy_function
1866-
def rmdir(self, path: str):
1867+
def rmdir(self, path: str) -> int:
18671868
raise FuseOSError(errno.EROFS)
18681869

18691870
@_nullable_dummy_function
1870-
def setxattr(self, path: str, name, value, options, position=0):
1871+
def setxattr(self, path: str, name, value, options, position=0) -> int:
18711872
raise FuseOSError(ENOTSUP)
18721873

18731874
@_nullable_dummy_function
1874-
def statfs(self, path: str):
1875+
def statfs(self, path: str) -> Mapping[str, Any]:
18751876
'''
18761877
Returns a dictionary with keys identical to the statvfs C structure of
18771878
statvfs(3).
@@ -1883,47 +1884,47 @@ def statfs(self, path: str):
18831884
return {}
18841885

18851886
@_nullable_dummy_function
1886-
def symlink(self, target: str, source: str):
1887+
def symlink(self, target: str, source: str) -> int:
18871888
'creates a symlink `target -> source` (e.g. ln -s source target)'
18881889

18891890
raise FuseOSError(errno.EROFS)
18901891

18911892
@_nullable_dummy_function
1892-
def truncate(self, path: str, length: int, fh: Optional[int] = None):
1893+
def truncate(self, path: str, length: int, fh: Optional[int] = None) -> int:
18931894
raise FuseOSError(errno.EROFS)
18941895

18951896
@_nullable_dummy_function
1896-
def unlink(self, path: str):
1897+
def unlink(self, path: str) -> int:
18971898
raise FuseOSError(errno.EROFS)
18981899

18991900
@_nullable_dummy_function
1900-
def utimens(self, path: str, times: Optional[Tuple[int, int]] = None):
1901+
def utimens(self, path: str, times: Optional[Tuple[int, int]] = None) -> int:
19011902
'Times is a (atime, mtime) tuple. If None use current time.'
19021903

19031904
return 0
19041905

19051906
@_nullable_dummy_function
1906-
def write(self, path: str, data, offset: int, fh: int):
1907+
def write(self, path: str, data, offset: int, fh: int) -> int:
19071908
raise FuseOSError(errno.EROFS)
19081909

19091910
@_nullable_dummy_function
1910-
def poll(self, path: str, fh: int, ph, reventsp):
1911+
def poll(self, path: str, fh: int, ph, reventsp) -> int:
19111912
raise FuseOSError(errno.ENOSYS)
19121913

19131914
@_nullable_dummy_function
1914-
def write_buf(self, path: str, buf, offset: int, fh: int):
1915+
def write_buf(self, path: str, buf, offset: int, fh: int) -> int:
19151916
raise FuseOSError(errno.ENOSYS)
19161917

19171918
@_nullable_dummy_function
1918-
def read_buf(self, path: str, bufpp, size: int, offset: int, fh: int):
1919+
def read_buf(self, path: str, bufpp, size: int, offset: int, fh: int) -> int:
19191920
raise FuseOSError(errno.ENOSYS)
19201921

19211922
@_nullable_dummy_function
1922-
def flock(self, path: str, fh: int, op: int):
1923+
def flock(self, path: str, fh: int, op: int) -> int:
19231924
raise FuseOSError(errno.ENOSYS)
19241925

19251926
@_nullable_dummy_function
1926-
def fallocate(self, path: str, mode: int, offset: int, size: int, fh: int):
1927+
def fallocate(self, path: str, mode: int, offset: int, size: int, fh: int) -> int:
19271928
raise FuseOSError(errno.ENOSYS)
19281929

19291930

0 commit comments

Comments
 (0)