diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 31062030..881a49a3 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 d231faab..73323f99 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", diff --git a/src/monty/collections.py b/src/monty/collections.py index 154a9c86..9fe64cdb 100644 --- a/src/monty/collections.py +++ b/src/monty/collections.py @@ -89,7 +89,9 @@ def __setitem__(self, key, value) -> None: def update(self, *args, **kwargs) -> None: """Forbid adding or updating keys based on _allow_add and _allow_update.""" - for key in dict(*args, **kwargs): + + updates = 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." @@ -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. diff --git a/src/monty/io.py b/src/monty/io.py index ccd24189..17021fca 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_collections.py b/tests/test_collections.py index 118a08a8..af31f409 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 @@ -122,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"}) @@ -157,7 +166,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" diff --git a/tests/test_io.py b/tests/test_io.py index f4422bf2..0fe06285 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, @@ -426,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, ):