diff --git a/attr/_dunders.py b/attr/_dunders.py index c14f76eb..8258f21b 100644 --- a/attr/_dunders.py +++ b/attr/_dunders.py @@ -11,12 +11,12 @@ def _attrs_to_tuple(obj, attrs): """ Create a tuple of all values of *obj*'s *attrs*. """ - return tuple(getattr(obj, a) for a in attrs) + return tuple(getattr(obj, a.name) for a in attrs) def _add_hash(cl, attrs=None): if attrs is None: - attrs = [a.name for a in cl.__attrs_attrs__] + attrs = cl.__attrs_attrs__ def hash_(self): """ @@ -30,7 +30,7 @@ def _add_hash(cl, attrs=None): def _add_cmp(cl, attrs=None): if attrs is None: - attrs = [a.name for a in cl.__attrs_attrs__] + attrs = cl.__attrs_attrs__ def attrs_to_tuple(obj): """ @@ -105,7 +105,7 @@ def _add_cmp(cl, attrs=None): def _add_repr(cl, attrs=None): if attrs is None: - attrs = [a.name for a in cl.__attrs_attrs__] + attrs = cl.__attrs_attrs__ def repr_(self): """ @@ -113,7 +113,8 @@ def _add_repr(cl, attrs=None): """ return "{0}({1})".format( self.__class__.__name__, - ", ".join(a + "=" + repr(getattr(self, a)) for a in attrs) + ", ".join(a.name + "=" + repr(getattr(self, a.name)) + for a in attrs) ) cl.__repr__ = repr_ return cl diff --git a/attr/_make.py b/attr/_make.py index 7ef4afc4..4985f9ac 100644 --- a/attr/_make.py +++ b/attr/_make.py @@ -27,7 +27,8 @@ class Attribute(object): ) -_a = ["name", "default_value", "default_factory"] +_a = [Attribute(name=name, default_value=NOTHING, default_factory=NOTHING) + for name in ("name", "default_value", "default_factory",)] Attribute = _add_cmp(_add_repr(Attribute, attrs=_a), attrs=_a)