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.
This commit is contained in:
Christopher Haster
2024-12-01 00:49:13 -06:00
parent 55d01f69f9
commit b4c79c53d2

View File

@@ -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