From da23bf07420489d72e56ec1c21849403317c1770 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 30 Mar 2025 11:59:12 +0800 Subject: [PATCH] cephfs-top: Removes unused `global` statements Recent flake8 runs were failing with: ``` py3: flake8==7.2.0,mccabe==0.7.0,pip==25.0.1,pycodestyle==2.13.0,pyflakes==3.3.0,setuptools==75.8.0,wheel==0.45.1 py3: commands[0] /home/jenkins-build/build/workspace/ceph-pull-requests/src/tools/cephfs/top> flake8 --ignore=W503 --max-line-length=100 cephfs-top cephfs-top:344:9: F824 `global fs_list` is unused: name is never assigned in scope cephfs-top:466:13: F824 `global current_states` is unused: name is never assigned in scope cephfs-top:872:9: F824 `global metrics_dict` is unused: name is never assigned in scope cephfs-top:872:9: F824 `global current_states` is unused: name is never assigned in scope cephfs-top:911:9: F824 `global fs_list` is unused: name is never assigned in scope cephfs-top:981:9: F824 `global current_states` is unused: name is never assigned in scope cephfs-top:1126:13: F824 `global current_states` is unused: name is never assigned in scope py3: exit 1 (0.77 seconds) /home/jenkins-build/build/workspace/ceph-pull-requests/src/tools/cephfs/top> flake8 --ignore=W503 --max-line-length=100 cephfs-top pid=2309605 py3: FAIL code 1 (8.15=setup[7.38]+cmd[0.77] seconds) evaluation failed :( (8.24 seconds) ``` Since these variables are only being referenced and not assigned within their scopes, the `global` declarations are unnecessary and can be safely removed. This change: - Removes all flagged `global` statements - Fixes the failing flake8 checks in the CI pipeline - Maintains the original code behavior as variable references still work without the `global` keyword The `global` keyword is only needed when assigning to global variables within a function scope, not when simply referencing them. Signed-off-by: Kefu Chai (cherry picked from commit 39b262f7a6e1d69dc96255a1df62a68297d3f931) --- src/tools/cephfs/top/cephfs-top | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/tools/cephfs/top/cephfs-top b/src/tools/cephfs/top/cephfs-top index 45900f9a025..2e83149af61 100755 --- a/src/tools/cephfs/top/cephfs-top +++ b/src/tools/cephfs/top/cephfs-top @@ -341,7 +341,6 @@ class FSTop(FSTopBase): except Exception as e: raise FSTopException(f'Error in fs ls: {e}') fs_map = json.loads(buf.decode('utf-8')) - global fs_list fs_list.clear() for filesystem in fs_map: fs = filesystem['name'] @@ -469,7 +468,7 @@ class FSTop(FSTopBase): key = 0 endwhile = False while not endwhile: - global current_states, fs_list + global fs_list fs_list = self.get_fs_names() if key == curses.KEY_UP and curr_row1 > 0: @@ -875,7 +874,6 @@ class FSTop(FSTopBase): xp += len(self.items(item)) + ITEMS_PAD_LEN def create_clients(self, stats_json, fs_name): - global metrics_dict, current_states counters = [m.upper() for m in stats_json[GLOBAL_COUNTERS_KEY]] self.tablehead_y += 2 res = stats_json[GLOBAL_METRICS_KEY].get(fs_name, {}) @@ -914,7 +912,6 @@ class FSTop(FSTopBase): if not stats_json['version'] == FS_TOP_SUPPORTED_VER: self.header.addstr(0, 0, 'perf stats version mismatch!', curses.A_BOLD) return False - global fs_list for fs_name in fs_list: client_metadata = stats_json[CLIENT_METADATA_KEY].get(fs_name, {}) client_cnt = len(client_metadata) @@ -979,7 +976,7 @@ class FSTop(FSTopBase): curses.halfdelay(1) cmd = self.stdscr.getch() - global fs_list, current_states + global fs_list while not self.exit_ev.is_set(): fs_list = self.get_fs_names() fs = current_states["last_fs"] @@ -1119,7 +1116,7 @@ class FSTop(FSTopBase): self.exit_ev.set() # header display - global fs_list, current_states + global fs_list fs_list = self.get_fs_names() current_states["last_fs"] = fs_list stats_json = self.perf_stats_query() -- 2.39.5