From 7161836a2019e13a8597676a1592250050b3b16d Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 11 Dec 2024 15:45:41 +0800 Subject: [PATCH 01/13] test goes first --- tests/test_collections.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_collections.py b/tests/test_collections.py index 118a08a87..5faa20512 100644 --- a/tests/test_collections.py +++ b/tests/test_collections.py @@ -62,6 +62,10 @@ def test_update_allowed(self): dct.update({"a": 3}) assert dct["a"] == 3 + # Test Iterator handling + dct.update(zip(["c", "d"], [11, 12])) + assert dct["c"] == 11 + dct.setdefault("a", 4) # existing key assert dct["a"] == 3 @@ -157,7 +161,11 @@ def test_namespace_dict(): dct["hello"] = "world" assert dct["key"] == "val" - # Test update (not allowed) + # Test use `update` to add new values + dct.update({"new_key": "new_value"}) + assert dct["new_key"] == "new_value" + + # Test add (not allowed) with pytest.raises(TypeError, match="update is disabled"): dct["key"] = "val" From 7021d7a203a80123597d1c395b322163b3a1891a Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 11 Dec 2024 20:14:56 +0800 Subject: [PATCH 02/13] fix iterator handling --- src/monty/collections.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/monty/collections.py b/src/monty/collections.py index 154a9c863..78e8d4cd6 100644 --- a/src/monty/collections.py +++ b/src/monty/collections.py @@ -89,6 +89,8 @@ def __setitem__(self, key, value) -> None: def update(self, *args, **kwargs) -> None: """Forbid adding or updating keys based on _allow_add and _allow_update.""" + + updates = dict(*args, **kwargs) for key in dict(*args, **kwargs): if key not in self.data and not self._allow_add: raise TypeError( @@ -99,7 +101,7 @@ def update(self, *args, **kwargs) -> None: f"Cannot update key {key!r} using update, because update is disabled." ) - super().update(*args, **kwargs) + super().update(updates) def setdefault(self, key, default=None) -> Any: """Forbid adding or updating keys based on _allow_add and _allow_update. From da8be8ea08745258aeae9a60d8bd5c0004e28e7b Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 11 Dec 2024 20:23:40 +0800 Subject: [PATCH 03/13] add test for python 3.13 --- .github/workflows/test.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 31062030c..881a49a32 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: max-parallel: 20 matrix: os: [ubuntu-latest, macos-14] #, windows-latest] - python-version: ["3.10", "3.12"] + python-version: ["3.10", "3.11", "3.12", "3.13"] runs-on: ${{ matrix.os }} diff --git a/pyproject.toml b/pyproject.toml index d231faab6..73323f99a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ maintainers = [ ] description = "Monty is the missing complement to Python." readme = "README.md" -requires-python = ">=3.10" +requires-python = ">=3.10,<=3.13" classifiers = [ "Programming Language :: Python :: 3", "Development Status :: 4 - Beta", From d54bde4c6fa03839e7c2716fa46d164d10ae0474 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 12 Dec 2024 18:55:32 +0800 Subject: [PATCH 04/13] drop custom encoding warning as min python bump to 3.10 --- src/monty/io.py | 3 --- tests/test_io.py | 1 - 2 files changed, 4 deletions(-) diff --git a/src/monty/io.py b/src/monty/io.py index ccd24189e..17021fcaf 100644 --- a/src/monty/io.py +++ b/src/monty/io.py @@ -22,9 +22,6 @@ from typing import IO, Any, Iterator, Union -class EncodingWarning(Warning): ... # Added in Python 3.10 - - def zopen( filename: Union[str, Path], /, diff --git a/tests/test_io.py b/tests/test_io.py index f4422bf2a..5f3f78c13 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -9,7 +9,6 @@ import pytest from monty.io import ( - EncodingWarning, FileLock, FileLockException, _get_line_ending, From e49e1a483922bbb1f2abc32ba0ba9a25ac9a261a Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 12 Dec 2024 18:58:21 +0800 Subject: [PATCH 05/13] filter known warning --- tests/test_io.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_io.py b/tests/test_io.py index 5f3f78c13..0fe062852 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -425,6 +425,7 @@ def test_lzw_files(self): # Cannot decompress a real LZW file with ( + pytest.warns(FutureWarning, match="compress LZW-compressed files"), pytest.raises(gzip.BadGzipFile, match="Not a gzipped file"), zopen(f"{TEST_DIR}/real_lzw_file.txt.Z", "rt", encoding="utf-8") as f, ): From c110169814be73fb313401abef3962fbfc48c96a Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 13 Dec 2024 20:01:19 +0800 Subject: [PATCH 06/13] improve iterator test --- src/monty/collections.py | 2 +- tests/test_collections.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/monty/collections.py b/src/monty/collections.py index 78e8d4cd6..9fe64cdbc 100644 --- a/src/monty/collections.py +++ b/src/monty/collections.py @@ -91,7 +91,7 @@ def update(self, *args, **kwargs) -> None: """Forbid adding or updating keys based on _allow_add and _allow_update.""" updates = dict(*args, **kwargs) - for key in dict(*args, **kwargs): + for key in updates: if key not in self.data and not self._allow_add: raise TypeError( f"Cannot add new key {key!r} using update, because add is disabled." diff --git a/tests/test_collections.py b/tests/test_collections.py index 5faa20512..af31f409c 100644 --- a/tests/test_collections.py +++ b/tests/test_collections.py @@ -126,6 +126,11 @@ def test_frozen_like(self): assert not dct._allow_add assert not dct._allow_update + def test_iterator_handling(self): + """Make sure iterators are handling correctly.""" + c_dict = ControlledDict(zip(["c", "d"], [11, 12])) + assert c_dict["c"] == 11 + def test_frozendict(): dct = frozendict({"hello": "world"}) From b1c9df3223af829978d3d2c2dfde47c47b28ef0a Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Tue, 17 Dec 2024 15:42:34 +0800 Subject: [PATCH 07/13] fix missing space --- src/monty/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monty/io.py b/src/monty/io.py index 17021fcaf..9555c4c49 100644 --- a/src/monty/io.py +++ b/src/monty/io.py @@ -58,7 +58,7 @@ def zopen( # TODO: remove default value of `mode` to force user to give one after deadline if mode is None: warnings.warn( - "We strongly discourage using a default `mode`, it would be" + "We strongly discourage using a default `mode`, it would be " f"set to `r` now but would not be allowed after {_deadline}", FutureWarning, stacklevel=2, From a11d4c405cdd040ea843500b85d8c13899f241eb Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 20 Dec 2024 10:35:22 +0800 Subject: [PATCH 08/13] revert delete of encoding warning for another PR --- src/monty/io.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/monty/io.py b/src/monty/io.py index 9555c4c49..96a899877 100644 --- a/src/monty/io.py +++ b/src/monty/io.py @@ -22,6 +22,9 @@ from typing import IO, Any, Iterator, Union +class EncodingWarning(Warning): ... # Added in Python 3.10 + + def zopen( filename: Union[str, Path], /, From 7856ec7049d1482f3ee4fd1fe9fe9706b8dbc5e2 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 20 Dec 2024 10:43:40 +0800 Subject: [PATCH 09/13] Revert "revert delete of encoding warning for another PR" This reverts commit a11d4c405cdd040ea843500b85d8c13899f241eb. --- src/monty/io.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/monty/io.py b/src/monty/io.py index 96a899877..9555c4c49 100644 --- a/src/monty/io.py +++ b/src/monty/io.py @@ -22,9 +22,6 @@ from typing import IO, Any, Iterator, Union -class EncodingWarning(Warning): ... # Added in Python 3.10 - - def zopen( filename: Union[str, Path], /, From 5043be8247de60656f92a0127edde037209f313c Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 20 Dec 2024 10:47:51 +0800 Subject: [PATCH 10/13] fix test matrix python version --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 881a49a32..958660a9c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,10 +16,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python }} + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python }} + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | From df87e77cc4a25cfb3bce0bbde93e8ffa0d8aea87 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 20 Dec 2024 10:50:11 +0800 Subject: [PATCH 11/13] fix required python --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 73323f99a..b402c087c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ maintainers = [ ] description = "Monty is the missing complement to Python." readme = "README.md" -requires-python = ">=3.10,<=3.13" +requires-python = ">=3.10,<3.14" classifiers = [ "Programming Language :: Python :: 3", "Development Status :: 4 - Beta", From 6deb13244d01a5e7443723ce635707b260aeb2ed Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 20 Dec 2024 10:52:48 +0800 Subject: [PATCH 12/13] revert encoding warning delete --- src/monty/io.py | 3 +++ tests/test_io.py | 1 + 2 files changed, 4 insertions(+) diff --git a/src/monty/io.py b/src/monty/io.py index 9555c4c49..96a899877 100644 --- a/src/monty/io.py +++ b/src/monty/io.py @@ -22,6 +22,9 @@ from typing import IO, Any, Iterator, Union +class EncodingWarning(Warning): ... # Added in Python 3.10 + + def zopen( filename: Union[str, Path], /, diff --git a/tests/test_io.py b/tests/test_io.py index 0fe062852..f79c9d7b2 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -9,6 +9,7 @@ import pytest from monty.io import ( + EncodingWarning, FileLock, FileLockException, _get_line_ending, From ffd142eb638f9f69ce31ee355a2bae2d52efdeae Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 20 Dec 2024 10:55:06 +0800 Subject: [PATCH 13/13] try to recover windows test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 958660a9c..e3e6e6339 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: fail-fast: false max-parallel: 20 matrix: - os: [ubuntu-latest, macos-14] #, windows-latest] + os: [ubuntu-latest, macos-14, windows-latest] python-version: ["3.10", "3.11", "3.12", "3.13"] runs-on: ${{ matrix.os }}