Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 17, 2024
1 parent d6f2d8c commit 958e9e9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
24 changes: 6 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 = (
"{}={{{}!r}}".format(name, accessor)
f"{name}={{{accessor}!r}}"
if r == repr
else "{}={{{}_repr({})}}".format(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('{}', {}({}))".format(
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,11 +2230,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.{} = {}({})".format(
attr_name,
_INIT_CONVERTER_PAT % (attr_name,),
value_var,
)
return f"self.{attr_name} = {_INIT_CONVERTER_PAT % (attr_name,)}({value_var})"


def _determine_setters(frozen, slots, base_attr_map):
Expand Down Expand Up @@ -2267,11 +2259,7 @@ def fmt_setter_with_converter(attr_name, value_var, has_on_setattr):
attr_name, value_var, has_on_setattr
)

return "_inst_dict['{}'] = {}({})".format(
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 @@ -2519,7 +2507,7 @@ def _attrs_to_init_script(
", ".join(kw_only_args), # kw_only args
)
pre_init_kw_only_args = ", ".join(
["{}={}".format(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
6 changes: 2 additions & 4 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# SPDX-License-Identifier: MIT

import sys

from importlib import metadata

import pytest

import attr
import attrs


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().__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().f ** 2 # noqa: UP008
return super().f ** 2

assert B(11).f == 121
assert B(17).f == 289
Expand Down

0 comments on commit 958e9e9

Please sign in to comment.