Skip to content

Commit

Permalink
feat: version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
corenting committed Jul 21, 2023
1 parent 33beaef commit 36a6fb6
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 201 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -20,14 +20,14 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12.0-beta.3"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12.0-beta.4"]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
if: ${{ matrix.python-version != '3.12.0-beta.3' }} # remove when codeql is fixed on 3.12
if: ${{ matrix.python-version != '3.12.0-beta.4' }} # remove when codeql is fixed on 3.12
with:
languages: python
- name: Install Poetry
Expand All @@ -45,7 +45,7 @@ jobs:
run: make test
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
if: ${{ matrix.python-version != '3.12.0-beta.3' }} # remove when codeql is fixed on 3.12
if: ${{ matrix.python-version != '3.12.0-beta.4' }} # remove when codeql is fixed on 3.12
- name: Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,11 @@
# Version 3.0.0

- `copy()` (**breaking change**): remove the option to pass keyword arguments (which were present as key/value pairs in the copy). Now the method doesn't take any arguments (it behaves the same as a normal `dict`).
- Python versions: drop Python 3.7 support
- Typing: fixes
- Make the key covariant. Thanks to [@spacether](https://github.com/spacether) for the [PR #244](https://github.com/corenting/immutabledict/pull/244)
- Fix key/value typing missing for ImmutableOrderedDict

# Version 2.2.5

- Fix hard-coded class reference in fromkeys() resulting in always using `dict` for `fromkeys()` (instead of OrderedDict in ImmutableOrderedDict for example). Thanks to [@cthoyt](https://github.com/cthoyt) for the [PR #234](https://github.com/corenting/immutabledict/pull/234)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -9,7 +9,7 @@ format:
style:
$(PYTHON) black --check immutabledict tests
$(PYTHON) ruff immutabledict tests
$(PYTHON) mypy -- immutabledict
$(PYTHON) mypy -- immutabledict tests

.PHONY: test
test:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -10,14 +10,13 @@ This library is a pure Python, MIT-licensed alternative to the new LGPL-3.0 lice
It implements the complete mapping interface and can be used as a drop-in replacement for dictionaries where immutability is desired.
The immutabledict constructor mimics dict, and all of the expected interfaces (iter, len, repr, hash, getitem) are provided. Note that an immutabledict does not guarantee the immutability of its values, so the utility of hash method is restricted by usage.

The only difference is that the copy() method of immutable takes variable keyword arguments, which will be present as key/value pairs in the new, immutable copy.

## Installation

Available as `immutabledict` on :
- [pypi](https://pypi.org/project/immutabledict/)
- [conda-forge](https://anaconda.org/conda-forge/immutabledict) (community-maintained, not an official release)
- alpine as [py3-immutabledict](https://pkgs.alpinelinux.org/packages?name=py3-immutabledict) (community-maintained, not an official release)
Official release in [on pypy](https://pypi.org/project/immutabledict/) as `immutabledict`.

**Community-maintained** releases are available:
- On [conda-forge](https://anaconda.org/conda-forge/immutabledict) as `immutabledict`
- On [various package repositories](https://repology.org/project/python:immutabledict/versions)

## Example

Expand All @@ -30,7 +29,8 @@ print(my_item["a"]) # Print "value"

## Differences with the old original frozendict package

- Dropped support of EOL Python versions (version 1.0.0 supports Python 3.5, versions <= 2.2.1 supports Python 3.6)
- Dropped support of EOL Python versions (older versions of the library may support older Python versions)
- Fixed `collections.Mapping` deprecation warning
- Typing
- [PEP 584 union operators](https://www.python.org/dev/peps/pep-0584/)
- Keep the same signature for `copy()` as `dict` (starting with immutabledict 3.0.0), don't accept extra keyword arguments.
11 changes: 4 additions & 7 deletions immutabledict/__init__.py
Expand Up @@ -3,7 +3,7 @@
from collections import OrderedDict
from typing import Any, Dict, Iterable, Iterator, Mapping, Optional, Type, TypeVar

__version__ = "2.2.5"
__version__ = "3.0.0"

_K = TypeVar("_K")
_V = TypeVar("_V", covariant=True)
Expand All @@ -22,7 +22,7 @@ class immutabledict(Mapping[_K, _V]):
@classmethod
def fromkeys(
cls, seq: Iterable[_K], value: Optional[_V] = None
) -> "immutabledict[_K, _V]":
) -> immutabledict[_K, _V]:
return cls(cls.dict_cls.fromkeys(seq, value))

def __init__(self, *args: Any, **kwargs: Any) -> None:
Expand All @@ -45,7 +45,7 @@ def __len__(self) -> int:
return len(self._dict)

def __repr__(self) -> str:
return "%s(%r)" % (self.__class__.__name__, self._dict)
return "{}({!r})".format(self.__class__.__name__, self._dict)

def __hash__(self) -> int:
if self._hash is None:
Expand Down Expand Up @@ -74,12 +74,9 @@ def __ior__(self, other: Any) -> immutabledict[_K, _V]:
raise TypeError(f"'{self.__class__.__name__}' object is not mutable")


class ImmutableOrderedDict(immutabledict):
class ImmutableOrderedDict(immutabledict[_K, _V]):
"""
An immutabledict subclass that maintains key order.
Not necessary anymore as for Python >= 3.7 order is guaranteed with the normal
immutabledict class, but kept for compatibility purpose.
"""

dict_cls = OrderedDict

0 comments on commit 36a6fb6

Please sign in to comment.