Hi Collin,
> > - A function _eliminate_NMD_from_line that takes a single line as argument
> > and return a line or None.
> > - A function _eliminate_NMD that invokes _eliminate_NMD_from_line on each
> > line of the snippet, and combines the results?
>
> I tried to implement it as you described it here. Feel free to let me
> know if I missed anything.
It is much more understandable this way; thanks.
There is a pitfall with the list.join('\n') idiom: it's mainly designed for
non-empty lists. I therefore add the patch below.
> These comments were above the assignments to 'sed_eliminate_NMD' in
> the shell script. I've decided to place them in the body of
> GLEmiter.lib_Makefile_am and GLEmiter.tests_Makefile_am
That's good; thanks.
> Since we have discussed the type hints before and decided we can
> assume Python version >= 3.7, I felt it was okay to add with this
> patch.
Yes, it is OK. Let me only add a comment about it.
2024-03-11 Bruno Haible <[email protected]>
gnulib-tool.py: Tweak last commit.
* pygnulib/GLEmiter.py (_eliminate_NMD): Don't add an extra newline when
the result should be empty.
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index f0ae4627e6..11f1a2c9fc 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -13,7 +13,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
+# Allow the use of union type specifiers, using the syntax Type1 | Type2,
+# in Python ≥ 3.7. Cf. <https://docs.python.org/3/library/__future__.html>
+# and <https://stackoverflow.com/questions/73879925/>.
from __future__ import annotations
+
#===============================================================================
# Define global imports
#===============================================================================
@@ -84,7 +88,10 @@ def _eliminate_NMD(snippet: str, automake_subdir: bool) ->
str:
line = _eliminate_NMD_from_line(line, automake_subdir)
if line != None:
result.append(line)
- return '\n'.join(result) + '\n'
+ if len(result) > 0:
+ return '\n'.join(result) + '\n'
+ else:
+ return ''
#===============================================================================