Skip to content

Commit

Permalink
Leave __str__ alone since we upcall
Browse files Browse the repository at this point in the history
Based on Python pizza hallway feedback by @ambv.
  • Loading branch information
hynek committed Feb 24, 2019
1 parent db35d15 commit c7e76a1
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/attr/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,8 @@ def add_str(self):
"__str__ can only be generated if a __repr__ exists."
)

if self._is_exc:

def __str__(self):
return BaseException.__str__(self)

else:

def __str__(self):
return self.__repr__()
def __str__(self):
return self.__repr__()

self._cls_dict["__str__"] = self._add_method_dunders(__str__)
return self
Expand Down Expand Up @@ -871,9 +864,7 @@ def attrs(
- all attributes that are either passed into ``__init__`` or have a
default value are additionally available as a tuple in the ``args``
attribute,
- the value of *str* is ignored and a ``__str__`` method is added that
returns a str of the ``args`` tuple (this differs from passing
``str=True`` which returns the same string as ``repr()``).
- the value of *str* is ignored leaving ``__str__`` to base classes.
.. versionadded:: 16.0.0 *slots*
.. versionadded:: 16.1.0 *frozen*
Expand Down Expand Up @@ -917,7 +908,7 @@ def wrap(cls):

if repr is True:
builder.add_repr(repr_ns)
if str is True or is_exc:
if str is True:
builder.add_str()
if cmp is True and not is_exc:
builder.add_cmp()
Expand Down

0 comments on commit c7e76a1

Please sign in to comment.