Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for Python 3.7 #84

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
include:
- os: windows-latest
python-version: "3.7"
python-version: "3.8"
- os: windows-latest
python-version: "3.11"
- os: macos-latest
python-version: "3.7"
python-version: "3.8"
- os: macos-latest
python-version: "3.11"

Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ repos:
hooks:
- id: pyupgrade
args:
- --py37-plus
- --py38-plus
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
language_version: python3
args:
- --target-version=py37
- --target-version=py38
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changelog

2.3.0 - Unreleased
------------------
- Dropped support for Python 3.7 (:pr:`84`) `Guido Imperiale`_
- ``File.__getitem__`` now returns bytearray instead of bytes. This prevents a memcpy
when deserializing numpy arrays with dask. (:pr:`74`) `Guido Imperiale`_
- Removed dependency from ``heapdict``; sped up ``LRU``. (:pr:`77`) `Guido Imperiale`_
Expand Down
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ classifiers =
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand All @@ -31,7 +30,7 @@ classifiers =
packages = zict
zip_safe = False # https://mypy.readthedocs.io/en/latest/installed_packages.html
include_package_data = True
python_requires = >=3.7
python_requires = >=3.8
install_requires =

[options.package_data]
Expand Down Expand Up @@ -76,7 +75,7 @@ known_first_party = zict


[mypy]
# Silence errors about Python 3.9-style delayed type annotations on Python 3.7/3.8
# Silence errors about Python 3.9-style delayed type annotations on Python 3.8
python_version = 3.9
# See https://github.com/python/mypy/issues/12286 for automatic multi-platform support
platform = linux
Expand Down
2 changes: 1 addition & 1 deletion zict/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def close(self) -> None:


if TYPE_CHECKING:
# TODO Python 3.9: remove this branch and just use [] in the implementation below
# TODO remove this branch and just use [] in the implementation below (needs Python >=3.9)
class WeakValueMapping(weakref.WeakValueDictionary[KT, VT]):
...

Expand Down
56 changes: 19 additions & 37 deletions zict/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,29 @@
from collections.abc import Iterable, Mapping
from itertools import chain
from typing import MutableMapping # TODO move to collections.abc (needs Python >=3.9)
from typing import Any, TypeVar, overload
from typing import TYPE_CHECKING, Any, TypeVar

T = TypeVar("T")
KT = TypeVar("KT")
VT = TypeVar("VT")

if TYPE_CHECKING:
# TODO import from typing (needs Python >=3.11)
from typing_extensions import Self


class ZictBase(MutableMapping[KT, VT]):
"""Base class for zict mappings"""

# TODO use positional-only arguments to protect self (requires Python 3.8+)
@overload # type: ignore[override]
def update(self, __m: Mapping[KT, VT], **kwargs: VT) -> None:
...

@overload
def update(self, __m: Iterable[tuple[KT, VT]], **kwargs: VT) -> None:
...

@overload
def update(self, **kwargs: VT) -> None:
...

def update(*args, **kwargs): # type: ignore[no-untyped-def]
# Boilerplate for implementing an update() method
if not args:
raise TypeError(
"descriptor 'update' of MutableMapping object " "needs an argument"
)
self = args[0]
args = args[1:]
if len(args) > 1:
raise TypeError("update expected at most 1 arguments, got %d" % len(args))
items = []
if args:
other = args[0]
if isinstance(other, Mapping) or hasattr(other, "items"):
items = other.items()
else:
# Assuming (key, value) pairs
items = other
if kwargs:
items = chain(items, kwargs.items())
self._do_update(items)
def update( # type: ignore[override]
self,
other: Mapping[KT, VT] | Iterable[tuple[KT, VT]] = (),
/,
**kwargs: VT,
) -> None:
if hasattr(other, "items"):
other = other.items()
other = chain(other, kwargs.items()) # type: ignore
self._do_update(other)

def _do_update(self, items: Iterable[tuple[KT, VT]]) -> None:
# Default implementation, can be overriden for speed
Expand All @@ -56,12 +35,15 @@ def _do_update(self, items: Iterable[tuple[KT, VT]]) -> None:
def close(self) -> None:
"""Release any system resources held by this object"""

def __enter__(self: T) -> T:
def __enter__(self) -> Self:
return self

def __exit__(self, *args: Any) -> None:
self.close()

def __del__(self) -> None:
self.close()


def close(*z: Any) -> None:
"""Close *z* if possible."""
Expand Down
53 changes: 53 additions & 0 deletions zict/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from collections import UserDict

from zict.common import ZictBase


def test_close_on_del():
closed = False

class D(ZictBase, UserDict):
def close(self):
nonlocal closed
closed = True

d = D()
del d
assert closed


def test_context():
closed = False

class D(ZictBase, UserDict):
def close(self):
nonlocal closed
closed = True

d = D()
with d as d2:
assert d2 is d
assert closed


def test_update():
items = []

class D(ZictBase, UserDict):
def _do_update(self, items_):
nonlocal items
items = items_

d = D()
d.update({"x": 1})
assert list(items) == [("x", 1)]
d.update(iter([("x", 2)]))
assert list(items) == [("x", 2)]
d.update({"x": 3}, y=4)
assert list(items) == [("x", 3), ("y", 4)]
d.update(x=5)
assert list(items) == [("x", 5)]

# Special kwargs can't overwrite positional-only parameters
d.update(self=1, other=2)
assert list(items) == [("self", 1), ("other", 2)]
8 changes: 4 additions & 4 deletions zict/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import zipfile
from collections.abc import Iterator
from typing import MutableMapping # TODO move to collections.abc (needs Python >=3.9)
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Literal

if TYPE_CHECKING:
# TODO: move to typing on Python 3.8+ and 3.10+ respectively
from typing_extensions import Literal, TypeAlias
# TODO: import from typing (needs Python >=3.10)
from typing_extensions import TypeAlias

FileMode: TypeAlias = Literal["r", "w", "x", "a"]
FileMode: TypeAlias = Literal["r", "w", "x", "a"]


class Zip(MutableMapping[str, bytes]):
Expand Down