This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: dataclass generated __str__ does not use overridden member __str__
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: Bruce Eckel, eric.smith
Priority: normal Keywords:

Created on 2022-02-09 17:18 by Bruce Eckel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
DataClassStrBug.py Bruce Eckel, 2022-02-09 17:18 Demonstration of bug
Messages (4)
msg412927 - (view) Author: Bruce Eckel (Bruce Eckel) * Date: 2022-02-09 17:18
When creating a dataclass using members of other classes that have overridden their __str__ methods, the __str__ method synthesized by the dataclass ignores the overridden __str__ methods in its component members.

Demonstrated in attached file.
msg412928 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-02-09 17:20
I believe dataclasses uses repr() of the members, not str(). Can you try using specifying __repr__ in Teacup? Just __repr__ = __str__ should work.
msg412929 - (view) Author: Bruce Eckel (Bruce Eckel) * Date: 2022-02-09 17:26
Oops. That does in fact work. How do I remove the bug report?

*Bruce Eckel*
HappyPathProgramming.com
SummerTechForum.com
MindViewLLC.com
Blog: BruceEckel.com
EvolveWork.co
WinterTechForum.com <http://www.WinterTechForum.com>
OnJava8.com <http://www.OnJava8.com>
www.AtomicKotlin.com
Reinventing-Business.com <http://www.Reinventing-Business.com>

On Wed, Feb 9, 2022 at 10:20 AM Eric V. Smith <report@bugs.python.org>
wrote:

>
> Eric V. Smith <eric@trueblade.com> added the comment:
>
> I believe dataclasses uses repr() of the members, not str(). Can you try
> using specifying __repr__ in Teacup? Just __repr__ = __str__ should work.
>
> ----------
> nosy: +eric.smith
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue46693>
> _______________________________________
>
msg412949 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-02-09 22:24
I'll close it.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90851
2022-02-09 22:24:28eric.smithsetstatus: open -> closed
resolution: not a bug
messages: + msg412949

stage: resolved
2022-02-09 17:26:34Bruce Eckelsetmessages: + msg412929
2022-02-09 17:20:50eric.smithsetassignee: eric.smith
2022-02-09 17:20:43eric.smithsetnosy: + eric.smith
messages: + msg412928
2022-02-09 17:18:08Bruce Eckelcreate