From 270230a833e7b89052eb93086a1548818bcd4264 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 31 Mar 2025 15:40:17 -0500 Subject: [PATCH] scripts: Adopted del to resolve shadowed builtins So: all_ = all; del all Instead of: import builtins all_, all = all, builtins.all The del exposes the globally scoped builtin we accidentally shadow. This requires less megic, and no module imports, though tbh I'm surprised it works. It also works in the case where you change a builtin globally, but that's a bit too crazy even for me... --- scripts/code.py | 3 +-- scripts/cov.py | 3 +-- scripts/csv.py | 3 +-- scripts/ctx.py | 3 +-- scripts/data.py | 3 +-- scripts/dbgerr.py | 3 +-- scripts/dbgflags.py | 5 ++--- scripts/dbglfs.py | 24 ++++++++---------------- scripts/dbgtag.py | 3 +-- scripts/perf.py | 3 +-- scripts/perfbd.py | 3 +-- scripts/stack.py | 3 +-- scripts/structs.py | 3 +-- 13 files changed, 21 insertions(+), 41 deletions(-) diff --git a/scripts/code.py b/scripts/code.py index fe429add..efdf78df 100755 --- a/scripts/code.py +++ b/scripts/code.py @@ -604,8 +604,7 @@ def table(Result, results, diff_results=None, *, small_table=False, summary=False, **_): - import builtins - all_, all = all, builtins.all + all_ = all; del all if by is None: by = Result._by diff --git a/scripts/cov.py b/scripts/cov.py index 94f2888e..87aefa0f 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -459,8 +459,7 @@ def table(Result, results, diff_results=None, *, small_table=False, summary=False, **_): - import builtins - all_, all = all, builtins.all + all_ = all; del all if by is None: by = Result._by diff --git a/scripts/csv.py b/scripts/csv.py index 633328a4..63a4fa4c 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -1748,8 +1748,7 @@ def table(Result, results, diff_results=None, *, small_table=False, summary=False, **_): - import builtins - all_, all = all, builtins.all + all_ = all; del all if by is None: by = Result._by diff --git a/scripts/ctx.py b/scripts/ctx.py index 176f6353..595c4567 100755 --- a/scripts/ctx.py +++ b/scripts/ctx.py @@ -864,8 +864,7 @@ def table(Result, results, diff_results=None, *, small_table=False, summary=False, **_): - import builtins - all_, all = all, builtins.all + all_ = all; del all if by is None: by = Result._by diff --git a/scripts/data.py b/scripts/data.py index 0c0bf7bb..6532e38e 100755 --- a/scripts/data.py +++ b/scripts/data.py @@ -604,8 +604,7 @@ def table(Result, results, diff_results=None, *, small_table=False, summary=False, **_): - import builtins - all_, all = all, builtins.all + all_ = all; del all if by is None: by = Result._by diff --git a/scripts/dbgerr.py b/scripts/dbgerr.py index 67e355bd..6195f612 100755 --- a/scripts/dbgerr.py +++ b/scripts/dbgerr.py @@ -28,8 +28,7 @@ ERRS = [ def main(errs, *, list=False): - import builtins - list_, list = list, builtins.list + list_ = list; del list lines = [] # list all known error codes diff --git a/scripts/dbgflags.py b/scripts/dbgflags.py index 5fbf1e01..5c8a745f 100755 --- a/scripts/dbgflags.py +++ b/scripts/dbgflags.py @@ -194,9 +194,8 @@ FLAGS = [ def main(flags, *, list=False, all=False): - import builtins - list_, list = list, builtins.list - all_, all = all, builtins.all + list_ = list; del list + all_ = all; del all # first compile prefixes prefixes = {} diff --git a/scripts/dbglfs.py b/scripts/dbglfs.py index b26bf9e8..edef2e74 100755 --- a/scripts/dbglfs.py +++ b/scripts/dbglfs.py @@ -3345,8 +3345,7 @@ class Lfs: # lookup operations def lookup(self, mid, mdir=None, *, all=False): - import builtins - all_, all = all, builtins.all + all_ = all; del all # is this mid grmed? if not all_ and self.grmed(mid): @@ -3367,8 +3366,7 @@ class Lfs: def namelookup(self, did, name, *, all=False): - import builtins - all_, all = all, builtins.all + all_ = all; del all mid_, mdir_, name_ = self.mtree.namelookup(did, name) if mid_ is None: @@ -3430,8 +3428,7 @@ class Lfs: all=False, path=False, depth=None): - import builtins - all_, all = all, builtins.all + all_ = all; del all # default to the root directory if path_ is None: @@ -3470,8 +3467,7 @@ class Lfs: all=False, path=False, depth=None): - import builtins - all_, all = all, builtins.all + all_ = all; del all file, *path__ = self.pathlookup_(did, path_, all=all_, @@ -3486,8 +3482,7 @@ class Lfs: all=False, path=False, depth=None): - import builtins - all_, all = all, builtins.all + all_ = all; del all # default to the root directory did = did or self.root.did @@ -3536,8 +3531,7 @@ class Lfs: all=False, path=False, depth=None): - import builtins - all_, all = all, builtins.all + all_ = all; del all for file, *path__ in self.files_(did, all=all_, @@ -3553,8 +3547,7 @@ class Lfs: def orphans(self, all=False): - import builtins - all_, all = all, builtins.all + all_ = all; del all # first find all reachable dids dids = {self.root.did} @@ -4069,8 +4062,7 @@ def dbg_files(lfs, paths, all=False, no_orphans=False, **args): - import builtins - all_, all = all, builtins.all + all_ = all; del all # parse all paths first, error if anything is malformed dirs = [] diff --git a/scripts/dbgtag.py b/scripts/dbgtag.py index b77815a4..652859e1 100755 --- a/scripts/dbgtag.py +++ b/scripts/dbgtag.py @@ -232,8 +232,7 @@ def main(tags, *, block_count=None, off=None, **args): - import builtins - list_, list = list, builtins.list + list_ = list; del list # list all known tags if list_: diff --git a/scripts/perf.py b/scripts/perf.py index feab8fc3..2d766989 100755 --- a/scripts/perf.py +++ b/scripts/perf.py @@ -965,8 +965,7 @@ def table(Result, results, diff_results=None, *, small_table=False, summary=False, **_): - import builtins - all_, all = all, builtins.all + all_ = all; del all if by is None: by = Result._by diff --git a/scripts/perfbd.py b/scripts/perfbd.py index caa31686..d11b60f0 100755 --- a/scripts/perfbd.py +++ b/scripts/perfbd.py @@ -939,8 +939,7 @@ def table(Result, results, diff_results=None, *, small_table=False, summary=False, **_): - import builtins - all_, all = all, builtins.all + all_ = all; del all if by is None: by = Result._by diff --git a/scripts/stack.py b/scripts/stack.py index ef21030a..afdb0013 100755 --- a/scripts/stack.py +++ b/scripts/stack.py @@ -607,8 +607,7 @@ def table(Result, results, diff_results=None, *, small_table=False, summary=False, **_): - import builtins - all_, all = all, builtins.all + all_ = all; del all if by is None: by = Result._by diff --git a/scripts/structs.py b/scripts/structs.py index 53285308..71d71515 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -745,8 +745,7 @@ def table(Result, results, diff_results=None, *, small_table=False, summary=False, **_): - import builtins - all_, all = all, builtins.all + all_ = all; del all if by is None: by = Result._by