From b4c79c53d293606c2b149b0c938739eaa55a533e Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 1 Dec 2024 00:49:13 -0600 Subject: [PATCH] scripts: csv.py: Fixed NoneType issues with default sort $ ./scripts/csv.py lfs.code.csv -bfunction -fsize -S ... blablabla ... TypeError: cannot unpack non-iterable NoneType object The issue was argparse's const defaults bypassing the type callback, so the sort field ends up with None when it expects a tuple (well technically a tuple tuple). This is only an issue for csv.py because csv.py's sort fields can contain exprs. --- scripts/csv.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/csv.py b/scripts/csv.py index b70a2f4b..866f1e5a 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -1264,7 +1264,7 @@ def infer(fields_, results, # make sure sort fields are included if sort is not None: by.extend(k for k, reverse in sort - if k not in by and k not in fields) + if k and k not in by and k not in fields) # find best type for all fields used by field exprs fields__ = set(it.chain.from_iterable( @@ -1891,6 +1891,7 @@ if __name__ == "__main__": k.strip(), RExpr(v) if v is not None else None) )(*x.split('=', 1)), + const=(None, None), help="Sort by this field. Can include an expression of the form " "field=expr.") parser.add_argument( @@ -1902,6 +1903,7 @@ if __name__ == "__main__": k.strip(), RExpr(v) if v is not None else None) )(*x.split('=', 1)), + const=(None, None), help="Sort by this field, but backwards. Can include an expression " "of the form field=expr.") sys.exit(main(**{k: v