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 python<=37 support #1270

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ build-backend = "hatchling.build"
name = "attrs"
authors = [{ name = "Hynek Schlawack", email = "hs@ox.cx" }]
license = "MIT"
requires-python = ">=3.7"
requires-python = ">=3.8"
description = "Classes Without Boilerplate"
keywords = ["class", "attribute", "boilerplate"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
5 changes: 1 addition & 4 deletions src/attr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 1 addition & 7 deletions src/attr/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 8 additions & 18 deletions src/attr/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
f"{name}={{{accessor}!r}}"
if r == repr
else "%s={%s_repr(%s)}" % (name, name, accessor)
else f"{name}={{{name}_repr({accessor})}}"
)
attribute_fragments.append(fragment)
repr_fragment = ", ".join(attribute_fragments)
Expand Down Expand Up @@ -2208,11 +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))" % (
attr_name,
_INIT_CONVERTER_PAT % (attr_name,),
value_var,
)
return f"_setattr('{attr_name}', {_INIT_CONVERTER_PAT % (attr_name,)}({value_var}))"


def _assign(attr_name, value, has_on_setattr):
Expand All @@ -2234,10 +2230,8 @@ 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)" % (
attr_name,
_INIT_CONVERTER_PAT % (attr_name,),
value_var,
return (
f"self.{attr_name} = {_INIT_CONVERTER_PAT % (attr_name,)}({value_var})"
)


Expand Down Expand Up @@ -2267,11 +2261,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)" % (
attr_name,
_INIT_CONVERTER_PAT % (attr_name,),
value_var,
)
return f"_inst_dict['{attr_name}'] = {_INIT_CONVERTER_PAT % (attr_name,)}({value_var})"

return (
("_inst_dict = self.__dict__",),
Expand Down Expand Up @@ -2514,12 +2504,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]
[f"{kw_arg}={kw_arg}" for kw_arg in kw_only_args]
)
pre_init_args += (
", " if pre_init_args else ""
Expand Down
9 changes: 2 additions & 7 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# SPDX-License-Identifier: MIT

import sys

from importlib import metadata

import pytest

import attr
import attrs


if sys.version_info < (3, 8):
import importlib_metadata as metadata
else:
from importlib import metadata


@pytest.fixture(name="mod", params=(attr, attrs))
def _mod(request):
return request.param
Expand Down
4 changes: 2 additions & 2 deletions tests/test_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class C:
field = attr.ib()

def f(self, a):
super(C, self).__init__() # noqa: UP008
super().__init__()

C(field=1)

Expand Down Expand Up @@ -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

assert B(11).f == 121
assert B(17).f == 289
Expand Down
2 changes: 1 addition & 1 deletion tests/typing_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DD:

@attr.s
class EE:
y: "list[int]" = attr.ib()
y: list[int] = attr.ib()


@attr.s
Expand Down