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:
+12
-6
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user