Skip to content

Commit ff1d68a

Browse files
committed
filesystem: add static typing in Inode
1 parent 0650b83 commit ff1d68a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

hooks/filesystem.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
from collections import Counter
88
from pathlib import Path
9+
from typing import Optional
910

1011
import guestfs
1112
import magic
@@ -49,7 +50,7 @@ def close(self):
4950

5051
@property
5152
@functools.lru_cache()
52-
def str_path(self):
53+
def str_path(self) -> str:
5354
return str(self.path)
5455

5556
@property
@@ -94,14 +95,14 @@ def inode_type_value(self):
9495

9596
@property
9697
@functools.lru_cache()
97-
def local_file(self):
98+
def local_file(self) -> str:
9899
STATS['local_file'] += 1
99100
self._tmp_local_file = TEMPFILE.NamedTemporaryFile()
100101
self._gfs.download(self.str_path, self._tmp_local_file.name)
101102
return self._tmp_local_file.name
102103

103104
@functools.lru_cache()
104-
def filecmd_output(self, mime_option=False):
105+
def filecmd_output(self, mime_option=False) -> Optional[str]:
105106
"""Run the file utility and returns the output"""
106107
if not self.inode_type == InodeType.REG:
107108
return None
@@ -113,15 +114,15 @@ def filecmd_output(self, mime_option=False):
113114

114115
@property
115116
@functools.lru_cache()
116-
def gfs_file(self):
117+
def gfs_file(self) -> Optional[str]:
117118
if not self.inode_type == InodeType.REG:
118119
return None
119120
STATS['guestfs_file'] += 1
120121
return self._gfs.file(self.str_path)
121122

122123
@property
123124
@functools.lru_cache()
124-
def file_magic_type(self):
125+
def file_magic_type(self) -> Optional[str]:
125126
"""this method is faster than py_magic_type, since it doesn't involve
126127
downloading the whole file to the host"""
127128
STATS['file_magic_type'] += 1
@@ -139,7 +140,7 @@ def file_magic_type(self):
139140

140141
@property
141142
@functools.lru_cache()
142-
def py_magic_type(self):
143+
def py_magic_type(self) -> Optional[str]:
143144
if not self.inode_type == InodeType.REG:
144145
return None
145146
STATS['py_magic_type'] += 1

0 commit comments

Comments
 (0)