bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnulib-tool.py: Simplify file list construction.


From: Collin Funk
Subject: gnulib-tool.py: Simplify file list construction.
Date: Mon, 8 Apr 2024 04:14:58 -0700
User-agent: Mozilla Thunderbird

Some more cleanup.

Patch 0005 changes a list to a set. Previously, it checked if each
file was a member of the list before appending it. We can just let
Python do this for us. I've also sorted before returning to make it
behave like gnulib-tool.sh. In func_modules_to_filelist:

    files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`

I seem to have not noticed that since now. Hopefully that should help
me cleanup random sorted() calls in other places without breaking the
test suite...

Patch 0006 turns the avoided modules in GLModuleTable into a set
instead of a list. Since we check every module for membership in the
avoided modules, it makes more sense to use a set. The avoided modules
emitted in the actioncmd and gnulib-comp.m4 are stored in GLConfig, so
doing this doesn't break anything.

Patch 0007 uses defaultdict() instead of dict() for module
dependencies. This has been around for a long time and deals with the
explicit initialization case for you:

>>> var = dict()
>>> var['a'].add(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'a'
>>> from collections import defaultdict
>>> var = defaultdict(set)
>>> var['a'].add(1)
>>> print(var)
defaultdict(<class 'set'>, {'a': {1}})

[1] https://docs.python.org/3/library/collections.html#defaultdict-objects

Collin

Attachment: 0005-gnulib-tool.py-Simplify-file-list-construction.patch
Description: Text Data

Attachment: 0006-gnulib-tool.py-Use-a-set-instead-of-list-for-avoided.patch
Description: Text Data

Attachment: 0007-gnulib-tool.py-Use-a-defaultdict-to-simplify-code.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]