From 266d2b09aea47ced5bb8483a98e6292ce5d72383 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Fri, 15 Dec 2023 19:52:03 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`=5F=5Fclass=5Fgetitem?= =?UTF-8?q?=5F=5F`=20signature=20in=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch also increases the coverage level expectations in the Codecov config and adds a test that hits the line with the missing coverage. Fixes #567 --- .codecov.yml | 4 ++-- frozenlist/__init__.py | 7 +++++-- frozenlist/_frozenlist.pyx | 2 +- tests/test_frozenlist.py | 3 +++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index c529e862..82c2d4f8 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -11,7 +11,7 @@ comment: require_changes: true coverage: - range: 99.09..100 + range: 100..100 status: project: default: @@ -19,7 +19,7 @@ coverage: lib: paths: - frozenlist/ - target: 97.79% + target: 100% tests: paths: - tests/ diff --git a/frozenlist/__init__.py b/frozenlist/__init__.py index e1c83c56..cfbe924a 100644 --- a/frozenlist/__init__.py +++ b/frozenlist/__init__.py @@ -3,7 +3,7 @@ import types from collections.abc import MutableSequence from functools import total_ordering -from typing import Type +from typing import Any, Type __version__ = "1.4.2.dev0" @@ -22,7 +22,10 @@ class FrozenList(MutableSequence): else: @classmethod - def __class_getitem__(cls: Type["FrozenList"]) -> Type["FrozenList"]: + def __class_getitem__( + cls: Type["FrozenList"], + cls_item: Any, + ) -> Type["FrozenList"]: return cls def __init__(self, items=None): diff --git a/frozenlist/_frozenlist.pyx b/frozenlist/_frozenlist.pyx index 9ee846c1..45d11de1 100644 --- a/frozenlist/_frozenlist.pyx +++ b/frozenlist/_frozenlist.pyx @@ -9,7 +9,7 @@ cdef class FrozenList: __class_getitem__ = classmethod(types.GenericAlias) else: @classmethod - def __class_getitem__(cls): + def __class_getitem__(cls, cls_item): return cls cdef readonly bint frozen diff --git a/tests/test_frozenlist.py b/tests/test_frozenlist.py index 403d3ec8..c0d91b5d 100644 --- a/tests/test_frozenlist.py +++ b/tests/test_frozenlist.py @@ -13,6 +13,9 @@ class FrozenListMixin: SKIP_METHODS = {"__abstractmethods__", "__slots__"} + def test___class_getitem__(self) -> None: + assert self.FrozenList[str] is not None + def test_subclass(self) -> None: assert issubclass(self.FrozenList, MutableSequence) From f27d9b9df3d731f2273a341706010175b4db62be Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Fri, 15 Dec 2023 20:00:06 +0100 Subject: [PATCH 2/2] Add a change note for PR #571 --- CHANGES/567.bugfix.rst | 1 + CHANGES/571.bugfix.rst | 6 ++++++ 2 files changed, 7 insertions(+) create mode 120000 CHANGES/567.bugfix.rst create mode 100644 CHANGES/571.bugfix.rst diff --git a/CHANGES/567.bugfix.rst b/CHANGES/567.bugfix.rst new file mode 120000 index 00000000..562c0d4c --- /dev/null +++ b/CHANGES/567.bugfix.rst @@ -0,0 +1 @@ +571.bugfix.rst \ No newline at end of file diff --git a/CHANGES/571.bugfix.rst b/CHANGES/571.bugfix.rst new file mode 100644 index 00000000..067781d6 --- /dev/null +++ b/CHANGES/571.bugfix.rst @@ -0,0 +1,6 @@ +An incorrect signature of the ``__class_getitem__`` class method +has been fixed, adding a missing ``class_item`` argument under +Python 3.8 and older. + +This change also improves the code coverage of this method that +was previously missing -- by :user:`webknjaz`.