Skip to content

Commit 213d0b1

Browse files
cephadm: update some type annotations
Update some function typing from the old comment based style to the current type annotations style. Not only does this modernize the code but it fixes issues found by newer versions of flake8 that were flagging types only referenced in type comments as unused imports. Part of an effort to get ceph tox environments passing on Python 3.12. Signed-off-by: John Mulligan <[email protected]>
1 parent a1c7b5d commit 213d0b1

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/cephadm/cephadmlib/file_utils.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def write_new(
5252
os.rename(tempname, destination)
5353

5454

55-
def populate_files(config_dir, config_files, uid, gid):
56-
# type: (str, Dict, int, int) -> None
55+
def populate_files(
56+
config_dir: str, config_files: Dict, uid: int, gid: int
57+
) -> None:
5758
"""create config files for different services"""
5859
for fname in config_files:
5960
config_file = os.path.join(config_dir, fname)
@@ -71,8 +72,7 @@ def touch(
7172
os.chown(file_path, uid, gid)
7273

7374

74-
def write_tmp(s, uid, gid):
75-
# type: (str, int, int) -> IO[str]
75+
def write_tmp(s: str, uid: int, gid: int) -> IO[str]:
7676
tmp_f = tempfile.NamedTemporaryFile(mode='w', prefix='ceph-tmp')
7777
os.fchown(tmp_f.fileno(), uid, gid)
7878
tmp_f.write(s)
@@ -97,8 +97,7 @@ def recursive_chown(path: str, uid: int, gid: int) -> None:
9797
os.chown(os.path.join(dirpath, filename), uid, gid)
9898

9999

100-
def read_file(path_list, file_name=''):
101-
# type: (List[str], str) -> str
100+
def read_file(path_list: List[str], file_name: str = '') -> str:
102101
"""Returns the content of the first file found within the `path_list`
103102
104103
:param path_list: list of file paths to search
@@ -123,14 +122,12 @@ def read_file(path_list, file_name=''):
123122
return 'Unknown'
124123

125124

126-
def pathify(p):
127-
# type: (str) -> str
125+
def pathify(p: str) -> str:
128126
p = os.path.expanduser(p)
129127
return os.path.abspath(p)
130128

131129

132-
def get_file_timestamp(fn):
133-
# type: (str) -> Optional[str]
130+
def get_file_timestamp(fn: str) -> Optional[str]:
134131
try:
135132
mt = os.path.getmtime(fn)
136133
return datetime.datetime.fromtimestamp(

0 commit comments

Comments
 (0)