typing: simplify archive.gz writing and drop a few pytype suppressions
authorMatt Harbison <matt_harbison@yahoo.com>
Thu, 12 Sep 2024 12:53:00 -0400
changeset 51861 f81e0ce5103a
parent 51860 8c39ba94acce
child 51862 607e94e01851
typing: simplify archive.gz writing and drop a few pytype suppressions I was waiting until 3.8 to use `Literal` to fix this, but there's also the ":" and "|" characters that are passed along here, meant only for the non-gz archive types. But manipulating what the local caller passes is silly- we know we're writing, so just open it for writing. As an added bonus, PyCharm stops flagging the call too (since it doesn't know about pytype suppression comments).
mercurial/archival.py
--- a/mercurial/archival.py	Thu Sep 12 12:38:43 2024 -0400
+++ b/mercurial/archival.py	Thu Sep 12 12:53:00 2024 -0400
@@ -163,16 +163,7 @@
                     mtime=mtime,
                 )
                 self.fileobj = gzfileobj
-                return (
-                    # taropen() wants Literal['a', 'r', 'w', 'x'] for the mode,
-                    # but Literal[] is only available in 3.8+ without the
-                    # typing_extensions backport.
-                    # pytype: disable=wrong-arg-types
-                    tarfile.TarFile.taropen(  # pytype: disable=attribute-error
-                        name, pycompat.sysstr(mode), gzfileobj
-                    )
-                    # pytype: enable=wrong-arg-types
-                )
+                return tarfile.TarFile.taropen(name, "w", gzfileobj)
             else:
                 try:
                     return tarfile.open(