From 5d4dd5d4c317197e618ec68482cb56500e298825 Mon Sep 17 00:00:00 2001 From: Jos Verlinde Date: Tue, 1 Dec 2026 09:19:10 +0100 Subject: [PATCH 1/2] stdlib/gzip: Update function signatures to be positional-only. Signed-off-by: Jos Verlinde --- python-stdlib/gzip/gzip.py | 6 +++--- python-stdlib/gzip/manifest.py | 2 +- python-stdlib/gzip/test_gzip.py | 26 ++++++++++++++++++++++++++ tools/ci.sh | 1 + 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 python-stdlib/gzip/test_gzip.py diff --git a/python-stdlib/gzip/gzip.py b/python-stdlib/gzip/gzip.py index 12bfb1ff5d..4645135110 100644 --- a/python-stdlib/gzip/gzip.py +++ b/python-stdlib/gzip/gzip.py @@ -10,20 +10,20 @@ def GzipFile(fileobj): return deflate.DeflateIO(fileobj, deflate.GZIP, _WBITS) -def open(filename, mode="rb"): +def open(filename, mode="rb", /): return deflate.DeflateIO(builtins.open(filename, mode), deflate.GZIP, _WBITS, True) if hasattr(deflate.DeflateIO, "write"): - def compress(data): + def compress(data, /): f = io.BytesIO() with GzipFile(fileobj=f) as g: g.write(data) return f.getvalue() -def decompress(data): +def decompress(data, /): f = io.BytesIO(data) with GzipFile(fileobj=f) as g: return g.read() diff --git a/python-stdlib/gzip/manifest.py b/python-stdlib/gzip/manifest.py index c422b29657..95ef40dbe8 100644 --- a/python-stdlib/gzip/manifest.py +++ b/python-stdlib/gzip/manifest.py @@ -1,3 +1,3 @@ -metadata(version="1.0.1") +metadata(version="1.0.2") module("gzip.py") diff --git a/python-stdlib/gzip/test_gzip.py b/python-stdlib/gzip/test_gzip.py new file mode 100644 index 0000000000..c6b2f20183 --- /dev/null +++ b/python-stdlib/gzip/test_gzip.py @@ -0,0 +1,26 @@ +import gzip +import unittest + + +class TestPositionalOnly(unittest.TestCase): + def test_open(self): + with self.assertRaises(TypeError): + gzip.open(filename="/__gzip_signature_check__.gz") + with self.assertRaises(TypeError): + gzip.open("/__gzip_signature_check__.gz", mode="rb") + + def test_decompress(self): + data = bytes.fromhex("1f8b08000000000002ffcb48cdc9c9070086a6103605000000") + self.assertEqual(gzip.decompress(data), b"hello") + with self.assertRaises(TypeError): + gzip.decompress(data=data) + + @unittest.skipUnless(hasattr(gzip, "compress"), "compression unavailable") + def test_compress(self): + self.assertEqual(gzip.decompress(gzip.compress(b"hello")), b"hello") + with self.assertRaises(TypeError): + gzip.compress(data=b"hello") + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/ci.sh b/tools/ci.sh index eee4521d24..c852ea2312 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -70,6 +70,7 @@ function ci_package_tests_run { python-stdlib/functools/test_partial.py \ python-stdlib/functools/test_reduce.py \ python-stdlib/functools/test_cache.py \ + python-stdlib/gzip/test_gzip.py \ python-stdlib/heapq/test_heapq.py \ python-stdlib/hmac/test_hmac.py \ python-stdlib/itertools/test_itertools.py \ From 2955b9fbd41f682b8cea2bc7e4f94ac160c119a9 Mon Sep 17 00:00:00 2001 From: Jos Verlinde Date: Tue, 1 Dec 2026 09:19:50 +0100 Subject: [PATCH 2/2] stdlib/zlib: Update function signatures to be positional-only. Signed-off-by: Jos Verlinde --- python-stdlib/zlib/manifest.py | 2 +- python-stdlib/zlib/test_zlib.py | 27 +++++++++++++++++++++++++++ python-stdlib/zlib/zlib.py | 4 ++-- tools/ci.sh | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 python-stdlib/zlib/test_zlib.py diff --git a/python-stdlib/zlib/manifest.py b/python-stdlib/zlib/manifest.py index f95602f252..6a15c82720 100644 --- a/python-stdlib/zlib/manifest.py +++ b/python-stdlib/zlib/manifest.py @@ -1,3 +1,3 @@ -metadata(version="1.0.0", description="Compression and decompression using the deflate algorithm") +metadata(version="1.0.1", description="Compression and decompression using the deflate algorithm") module("zlib.py") diff --git a/python-stdlib/zlib/test_zlib.py b/python-stdlib/zlib/test_zlib.py new file mode 100644 index 0000000000..b4805ae416 --- /dev/null +++ b/python-stdlib/zlib/test_zlib.py @@ -0,0 +1,27 @@ +import unittest +import zlib + + +class TestPositionalOnly(unittest.TestCase): + def test_decompress(self): + data = bytes.fromhex("789ccb48cdc9c90700062c0215") + # positional only + with self.assertRaises(TypeError): + zlib.decompress(data=data) + # positional or keyword + self.assertEqual(zlib.decompress(data), b"hello") + self.assertEqual(zlib.decompress(data, 15), b"hello") + self.assertEqual(zlib.decompress(data, wbits=0), b"hello") + + @unittest.skipUnless(hasattr(zlib, "compress"), "compression unavailable") + def test_compress(self): + # positional only + with self.assertRaises(TypeError): + zlib.compress(data=b"hello") + # positional or keyword + self.assertEqual(zlib.decompress(zlib.compress(b"hello")), b"hello") + self.assertEqual(zlib.decompress(zlib.compress(b"hello", 15), 15), b"hello") + self.assertEqual(zlib.decompress(zlib.compress(b"hello", 15), wbits=15), b"hello") + +if __name__ == "__main__": + unittest.main() diff --git a/python-stdlib/zlib/zlib.py b/python-stdlib/zlib/zlib.py index e6c342ef74..a8da65beb1 100644 --- a/python-stdlib/zlib/zlib.py +++ b/python-stdlib/zlib/zlib.py @@ -26,14 +26,14 @@ def _decode_wbits(wbits, decompress): if hasattr(deflate.DeflateIO, "write"): - def compress(data, wbits=_MAX_WBITS): + def compress(data, /, wbits=_MAX_WBITS): f = io.BytesIO() with deflate.DeflateIO(f, *_decode_wbits(wbits, False)) as g: g.write(data) return f.getvalue() -def decompress(data, wbits=_MAX_WBITS): +def decompress(data, /, wbits=_MAX_WBITS): f = io.BytesIO(data) with deflate.DeflateIO(f, *_decode_wbits(wbits, True)) as g: return g.read() diff --git a/tools/ci.sh b/tools/ci.sh index c852ea2312..48d661bb28 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -79,6 +79,7 @@ function ci_package_tests_run { python-stdlib/pickle/test_pickle.py \ python-stdlib/pprint/test_pprint.py \ python-stdlib/string/test_translate.py \ + python-stdlib/zlib/test_zlib.py \ python-stdlib/unittest/tests/exception.py \ unix-ffi/gettext/test_gettext.py \ unix-ffi/pwd/test_getpwnam.py \