bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Collin Funk <collin.funk1@gmail.com>
To: bug-gnulib@gnu.org
Subject: gnulib-tool.py: Update type hints and docstring.
Date: Sat, 20 Apr 2024 20:03:44 -0700	[thread overview]
Message-ID: <08a4ef71-bbb0-49a7-83fa-0a9fc43929a3@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 878 bytes --]

Two type hints are incorrectly marked 'dict[str, str]' instead of
'dict[str, tuple[re.Pattern, str] | None]'. I assume I forgot to
change these when inlining sed expressions to use re.sub().

Previously the dict would be:

    # key : value
    'file-category' : 'sed-expression'

but now it is:

    # Arguments for re.sub()
    'file-category' : (regexp, 'replacement-string')
    # or no replacements needed.
    'file-category' : None

I've also updated an outdated doc string since we no longer use sed
invocations for this and we don't perform license replacements on
source files.

Now that I think about it, I should have used a list of re.sub()
arguments. But I think these variables are only used by the 'config-h'
module to replace "#if HAVE_CONFIG_H" with "#if 1". Until we need
something more complex than that, how it is currently written should
work fine.

Collin

[-- Attachment #2: 0001-gnulib-tool.py-Update-type-hints-and-docstring.patch --]
[-- Type: text/x-patch, Size: 2644 bytes --]

From f1b179f77fb64aed33f40cdd8ad3bd7a2c83ba8d Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.funk1@gmail.com>
Date: Sat, 20 Apr 2024 19:47:28 -0700
Subject: [PATCH] gnulib-tool.py: Update type hints and docstring.

* pygnulib/GLImport.py (GLImport.execute): Update transformer type hint
to reflect change from sed expressions to re.sub() arguments.
(GLImport.prepare): Likewise. Don't reference sed or license
replacements in docstring.
---
 ChangeLog            | 8 ++++++++
 pygnulib/GLImport.py | 8 ++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4bb812ef1a..2ede5219a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-04-20  Collin Funk  <collin.funk1@gmail.com>
+
+	gnulib-tool.py: Update type hints and docstring.
+	* pygnulib/GLImport.py (GLImport.execute): Update transformer type hint
+	to reflect change from sed expressions to re.sub() arguments.
+	(GLImport.prepare): Likewise. Don't reference sed or license
+	replacements in docstring.
+
 2024-04-20  Bruno Haible  <bruno@clisp.org>
 
 	signed-snan: Relicense under LGPLv2+.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 0863ba530e..cc7648890d 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -805,9 +805,9 @@ def _update_ignorelist_(self, directory: str, ignore: str, files_added: list[str
                 else:  # if self.config['dryrun']
                     print('Create %s' % srcpath)
 
-    def prepare(self) -> tuple[dict[str, list[str]], dict[str, str]]:
-        '''Make all preparations before the execution of the code.
-        Returns filetable and sed transformers, which change the license.'''
+    def prepare(self) -> tuple[dict[str, list[str]], dict[str, tuple[re.Pattern, str] | None]]:
+        '''Perform preperations before GLImport.execute().
+        Returns a filetable and the transformers passed to GLFileAssistant().'''
         destdir = self.config['destdir']
         modules = list(self.config['modules'])
         m4base = self.config['m4base']
@@ -979,7 +979,7 @@ def prepare(self) -> tuple[dict[str, list[str]], dict[str, str]]:
         result = tuple([filetable, transformers])
         return result
 
-    def execute(self, filetable: dict[str, list[str]], transformers: dict[str, str]) -> None:
+    def execute(self, filetable: dict[str, list[str]], transformers: dict[str, tuple[re.Pattern, str] | None]) -> None:
         '''Perform operations on the lists of files, which are given in a special
         format except filelist argument. Such lists of files can be created using
         GLImport.prepare() function.'''
-- 
2.44.0


             reply	other threads:[~2024-04-21  3:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-21  3:03 Collin Funk [this message]
2024-04-21 11:07 ` gnulib-tool.py: Update type hints and docstring Bruno Haible
2024-04-21 18:43   ` Collin Funk
2024-04-21 21:43     ` Bruno Haible
2024-04-21 22:37       ` Collin Funk
2024-04-21 22:42         ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=08a4ef71-bbb0-49a7-83fa-0a9fc43929a3@gmail.com \
    --to=collin.funk1@gmail.com \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).