scripts: Reverted del to resolve shadowed builtins

I don't know how I completely missed that this doesn't actually work!

Using del _does_ work in Python's repl, but it makes sense the repl may
differ from actual function execution in this case.

The problem is Python still thinks the relevant builtin is a local
variables after deletion, raising an UnboundLocalError instead of
performing a global lookup. In theory this would work if the variable
could be made global, but since global/nonlocal statements are lifted,
Python complains with "SyntaxError: name 'list' is parameter and
global".

And that's A-Ok! Intentionally shadowing language builtins already puts
this code deep into ugly hacks territory.
This commit is contained in:
Christopher Haster
2025-05-15 14:10:36 -05:00
parent 48c1a016a0
commit 55ea13b994
20 changed files with 70 additions and 36 deletions
+2 -1
View File
@@ -603,7 +603,8 @@ def table(Result, results, diff_results=None, *,
small_table=False,
summary=False,
**_):
all_ = all; del all
import builtins
all_, all = all, builtins.all
if by is None:
by = Result._by
+2 -1
View File
@@ -463,7 +463,8 @@ def table(Result, results, diff_results=None, *,
small_table=False,
summary=False,
**_):
all_ = all; del all
import builtins
all_, all = all, builtins.all
if by is None:
by = Result._by
+2 -1
View File
@@ -41,7 +41,8 @@ def crc32c(data, crc=0):
def main(paths, *,
hex=False,
string=False):
hex_ = hex; del hex
import builtins
hex_, hex = hex, builtins.hex
# interpret as sequence of hex bytes
if hex_:
+2 -1
View File
@@ -1735,7 +1735,8 @@ def table(Result, results, diff_results=None, *,
small_table=False,
summary=False,
**_):
all_ = all; del all
import builtins
all_, all = all, builtins.all
if by is None:
by = Result._by
+2 -1
View File
@@ -863,7 +863,8 @@ def table(Result, results, diff_results=None, *,
small_table=False,
summary=False,
**_):
all_ = all; del all
import builtins
all_, all = all, builtins.all
if by is None:
by = Result._by
+2 -1
View File
@@ -603,7 +603,8 @@ def table(Result, results, diff_results=None, *,
small_table=False,
summary=False,
**_):
all_ = all; del all
import builtins
all_, all = all, builtins.all
if by is None:
by = Result._by
+10 -5
View File
@@ -2964,7 +2964,8 @@ class Lfs:
# lookup operations
def lookup(self, mid, mdir=None, *,
all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# is this mid grmed?
if not all_ and self.grmed(mid):
@@ -2985,7 +2986,8 @@ class Lfs:
def namelookup(self, did, name, *,
all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
mid_, mdir_, name_ = self.mtree.namelookup(did, name)
if mid_ is None:
@@ -3047,7 +3049,8 @@ class Lfs:
all=False,
path=False,
depth=None):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# default to the root directory
if path_ is None:
@@ -3100,7 +3103,8 @@ class Lfs:
all=False,
path=False,
depth=None):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# default to the root directory
did = did or self.root.did
@@ -3155,7 +3159,8 @@ class Lfs:
def orphans(self,
all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# first find all reachable dids
dids = {self.root.did}
+10 -5
View File
@@ -2994,7 +2994,8 @@ class Lfs:
# lookup operations
def lookup(self, mid, mdir=None, *,
all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# is this mid grmed?
if not all_ and self.grmed(mid):
@@ -3015,7 +3016,8 @@ class Lfs:
def namelookup(self, did, name, *,
all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
mid_, mdir_, name_ = self.mtree.namelookup(did, name)
if mid_ is None:
@@ -3077,7 +3079,8 @@ class Lfs:
all=False,
path=False,
depth=None):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# default to the root directory
if path_ is None:
@@ -3130,7 +3133,8 @@ class Lfs:
all=False,
path=False,
depth=None):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# default to the root directory
did = did or self.root.did
@@ -3185,7 +3189,8 @@ class Lfs:
def orphans(self,
all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# first find all reachable dids
dids = {self.root.did}
+2 -1
View File
@@ -28,7 +28,8 @@ ERRS = [
def main(errs, *,
list=False):
list_ = list; del list
import builtins
list_, list = list, builtins.list
lines = []
# list all known error codes
+3 -2
View File
@@ -205,8 +205,9 @@ FLAGS = [
def main(flags, *,
list=False,
all=False):
list_ = list; del list
all_ = all; del all
import builtins
list_, list = list, builtins.list
all_, all = all, builtins.all
# first compile prefixes
prefixes = {}
+2 -1
View File
@@ -59,7 +59,8 @@ def main(le32s, *,
hex=False,
input=None,
word_bits=32):
hex_ = hex; del hex
import builtins
hex_, hex = hex, builtins.hex
# interpret as a sequence of hex bytes
if hex_:
+2 -1
View File
@@ -71,7 +71,8 @@ def main(leb128s, *,
hex=False,
input=None,
word_bits=32):
hex_ = hex; del hex
import builtins
hex_, hex = hex, builtins.hex
# interpret as a sequence of hex bytes
if hex_:
+12 -6
View File
@@ -2921,7 +2921,8 @@ class Lfs:
# lookup operations
def lookup(self, mid, mdir=None, *,
all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# is this mid grmed?
if not all_ and self.grmed(mid):
@@ -2942,7 +2943,8 @@ class Lfs:
def namelookup(self, did, name, *,
all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
mid_, mdir_, name_ = self.mtree.namelookup(did, name)
if mid_ is None:
@@ -3004,7 +3006,8 @@ class Lfs:
all=False,
path=False,
depth=None):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# default to the root directory
if path_ is None:
@@ -3057,7 +3060,8 @@ class Lfs:
all=False,
path=False,
depth=None):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# default to the root directory
did = did or self.root.did
@@ -3112,7 +3116,8 @@ class Lfs:
def orphans(self,
all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# first find all reachable dids
dids = {self.root.did}
@@ -4142,7 +4147,8 @@ def dbg_files(lfs, paths, *,
all=False,
no_orphans=False,
**args):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# parse all paths first, error if anything is malformed
dirs = []
+4 -2
View File
@@ -948,7 +948,8 @@ class JumpArt:
@classmethod
def fromrbyd(cls, rbyd, all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
jumps = []
j_ = 4
@@ -1100,7 +1101,8 @@ class LifetimeArt:
@classmethod
def fromrbyd(cls, rbyd, all=False):
all_ = all; del all
import builtins
all_, all = all, builtins.all
# first figure out where each rid comes from
id = 0
+3 -2
View File
@@ -290,8 +290,9 @@ def main(tags, *,
hex=False,
input=None,
word_bits=32):
list_ = list; del list
hex_ = hex; del hex
import builtins
list_, list = list, builtins.list
hex_, hex = hex, builtins.hex
# list all known tags
if list_:
+2 -1
View File
@@ -49,7 +49,8 @@ def parity(x):
def main(paths, *,
hex=False,
string=False):
hex_ = hex; del hex
import builtins
hex_, hex = hex, builtins.hex
# interpret as sequence of hex bytes
if hex_:
+2 -1
View File
@@ -964,7 +964,8 @@ def table(Result, results, diff_results=None, *,
small_table=False,
summary=False,
**_):
all_ = all; del all
import builtins
all_, all = all, builtins.all
if by is None:
by = Result._by
+2 -1
View File
@@ -938,7 +938,8 @@ def table(Result, results, diff_results=None, *,
small_table=False,
summary=False,
**_):
all_ = all; del all
import builtins
all_, all = all, builtins.all
if by is None:
by = Result._by
+2 -1
View File
@@ -606,7 +606,8 @@ def table(Result, results, diff_results=None, *,
small_table=False,
summary=False,
**_):
all_ = all; del all
import builtins
all_, all = all, builtins.all
if by is None:
by = Result._by
+2 -1
View File
@@ -744,7 +744,8 @@ def table(Result, results, diff_results=None, *,
small_table=False,
summary=False,
**_):
all_ = all; del all
import builtins
all_, all = all, builtins.all
if by is None:
by = Result._by