From: John Mulligan Date: Fri, 1 Nov 2024 18:36:51 +0000 (-0400) Subject: cephadm: update some type annotations X-Git-Tag: v20.0.0~647^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=213d0b1ea2d0be9e7c1a56aa0045aa4020f658d6;p=ceph.git 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 --- diff --git a/src/cephadm/cephadmlib/file_utils.py b/src/cephadm/cephadmlib/file_utils.py index 399729f2dcc..27e70e31756 100644 --- a/src/cephadm/cephadmlib/file_utils.py +++ b/src/cephadm/cephadmlib/file_utils.py @@ -52,8 +52,9 @@ def write_new( os.rename(tempname, destination) -def populate_files(config_dir, config_files, uid, gid): - # type: (str, Dict, int, int) -> None +def populate_files( + config_dir: str, config_files: Dict, uid: int, gid: int +) -> None: """create config files for different services""" for fname in config_files: config_file = os.path.join(config_dir, fname) @@ -71,8 +72,7 @@ def touch( os.chown(file_path, uid, gid) -def write_tmp(s, uid, gid): - # type: (str, int, int) -> IO[str] +def write_tmp(s: str, uid: int, gid: int) -> IO[str]: tmp_f = tempfile.NamedTemporaryFile(mode='w', prefix='ceph-tmp') os.fchown(tmp_f.fileno(), uid, gid) tmp_f.write(s) @@ -97,8 +97,7 @@ def recursive_chown(path: str, uid: int, gid: int) -> None: os.chown(os.path.join(dirpath, filename), uid, gid) -def read_file(path_list, file_name=''): - # type: (List[str], str) -> str +def read_file(path_list: List[str], file_name: str = '') -> str: """Returns the content of the first file found within the `path_list` :param path_list: list of file paths to search @@ -123,14 +122,12 @@ def read_file(path_list, file_name=''): return 'Unknown' -def pathify(p): - # type: (str) -> str +def pathify(p: str) -> str: p = os.path.expanduser(p) return os.path.abspath(p) -def get_file_timestamp(fn): - # type: (str) -> Optional[str] +def get_file_timestamp(fn: str) -> Optional[str]: try: mt = os.path.getmtime(fn) return datetime.datetime.fromtimestamp(