From d6f2d8cbc3d8c1aa549e22aff10bcf4e220c8dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C5=82oczko?= Date: Sun, 17 Mar 2024 21:10:15 +0000 Subject: [PATCH] drop python<=37 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python 3.7 has been EOSed at 27 Jun 2023 (https://endoflife.date/python) Filter all code over `pyupgrade --py38'. Signed-off-by: Tomasz Kłoczko --- src/attr/__init__.py | 5 +---- src/attr/_compat.py | 8 +------- src/attr/_make.py | 14 +++++++------- tests/test_packaging.py | 5 +---- tests/test_slots.py | 4 ++-- tests/typing_example.py | 2 +- 6 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/attr/__init__.py b/src/attr/__init__.py index 9226258a2..7cd4734ea 100644 --- a/src/attr/__init__.py +++ b/src/attr/__init__.py @@ -98,10 +98,7 @@ def __getattr__(name: str) -> str: import sys import warnings - if sys.version_info < (3, 8): - from importlib_metadata import metadata - else: - from importlib.metadata import metadata + from importlib.metadata import metadata if name not in ("__version__", "__version_info__"): warnings.warn( diff --git a/src/attr/_compat.py b/src/attr/_compat.py index b7d7a4b86..7edb762a5 100644 --- a/src/attr/_compat.py +++ b/src/attr/_compat.py @@ -17,13 +17,7 @@ PY_3_13_PLUS = sys.version_info[:2] >= (3, 13) -if sys.version_info < (3, 8): - try: - from typing_extensions import Protocol - except ImportError: # pragma: no cover - Protocol = object -else: - from typing import Protocol # noqa: F401 +from typing import Protocol # noqa: F401 class _AnnotationExtractor: diff --git a/src/attr/_make.py b/src/attr/_make.py index 0114582aa..8b1e19f8c 100644 --- a/src/attr/_make.py +++ b/src/attr/_make.py @@ -1979,9 +1979,9 @@ def _make_repr(attrs, ns, cls): "self." + name if i else 'getattr(self, "' + name + '", NOTHING)' ) fragment = ( - "%s={%s!r}" % (name, accessor) + "{}={{{}!r}}".format(name, accessor) if r == repr - else "%s={%s_repr(%s)}" % (name, name, accessor) + else "{}={{{}_repr({})}}".format(name, name, accessor) ) attribute_fragments.append(fragment) repr_fragment = ", ".join(attribute_fragments) @@ -2208,7 +2208,7 @@ def _setattr_with_converter(attr_name, value_var, has_on_setattr): Use the cached object.setattr to set *attr_name* to *value_var*, but run its converter first. """ - return "_setattr('%s', %s(%s))" % ( + return "_setattr('{}', {}({}))".format( attr_name, _INIT_CONVERTER_PAT % (attr_name,), value_var, @@ -2234,7 +2234,7 @@ def _assign_with_converter(attr_name, value_var, has_on_setattr): if has_on_setattr: return _setattr_with_converter(attr_name, value_var, True) - return "self.%s = %s(%s)" % ( + return "self.{} = {}({})".format( attr_name, _INIT_CONVERTER_PAT % (attr_name,), value_var, @@ -2267,7 +2267,7 @@ def fmt_setter_with_converter(attr_name, value_var, has_on_setattr): attr_name, value_var, has_on_setattr ) - return "_inst_dict['%s'] = %s(%s)" % ( + return "_inst_dict['{}'] = {}({})".format( attr_name, _INIT_CONVERTER_PAT % (attr_name,), value_var, @@ -2514,12 +2514,12 @@ def _attrs_to_init_script( args = ", ".join(args) pre_init_args = args if kw_only_args: - args += "%s*, %s" % ( + args += "{}*, {}".format( ", " if args else "", # leading comma ", ".join(kw_only_args), # kw_only args ) pre_init_kw_only_args = ", ".join( - ["%s=%s" % (kw_arg, kw_arg) for kw_arg in kw_only_args] + ["{}={}".format(kw_arg, kw_arg) for kw_arg in kw_only_args] ) pre_init_args += ( ", " if pre_init_args else "" diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 5a2fdb269..669f9203e 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -8,10 +8,7 @@ import attrs -if sys.version_info < (3, 8): - import importlib_metadata as metadata -else: - from importlib import metadata +from importlib import metadata @pytest.fixture(name="mod", params=(attr, attrs)) diff --git a/tests/test_slots.py b/tests/test_slots.py index c1332f2d3..bd6e27858 100644 --- a/tests/test_slots.py +++ b/tests/test_slots.py @@ -597,7 +597,7 @@ class C: field = attr.ib() def f(self, a): - super(C, self).__init__() # noqa: UP008 + super().__init__() # noqa: UP008 C(field=1) @@ -685,7 +685,7 @@ def f(self): class C(A): @property def f(self): - return super(C, self).f ** 2 # noqa: UP008 + return super().f ** 2 # noqa: UP008 assert B(11).f == 121 assert B(17).f == 289 diff --git a/tests/typing_example.py b/tests/typing_example.py index 2124912c8..d5899ddc6 100644 --- a/tests/typing_example.py +++ b/tests/typing_example.py @@ -56,7 +56,7 @@ class DD: @attr.s class EE: - y: "list[int]" = attr.ib() + y: list[int] = attr.ib() @attr.s