From: Bruno Larsen <blarsen@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>,
Matheus Branco Borella via Gdb-patches
<gdb-patches@sourceware.org>
Cc: Matheus Branco Borella <dark.ryu.550@gmail.com>
Subject: Re: [PATCH] Add __repr__() implementation to a few Python types
Date: Thu, 19 Jan 2023 09:23:31 +0100 [thread overview]
Message-ID: <b2fbbb76-3c33-312f-aff8-228eaa20addf@redhat.com> (raw)
In-Reply-To: <87wn5jen5t.fsf@redhat.com>
On 18/01/2023 19:02, Andrew Burgess via Gdb-patches wrote:
>> --- a/gdb/testsuite/gdb.python/py-arch.exp
>> +++ b/gdb/testsuite/gdb.python/py-arch.exp
>> @@ -29,6 +29,8 @@ if ![runto_main] {
>> # Test python/15461. Invalid architectures should not trigger an
>> # internal GDB assert.
>> gdb_py_test_silent_cmd "python empty = gdb.Architecture()" "get empty arch" 0
>> +gdb_test "python print(repr (empty))" "<gdb\\.Architecture \\(invalid\\)>" \
>> + "Test empty achitecture __repr__ does not trigger an assert"
> I guess I was surprised that so many of the new tests included an
> explicit call to repr, given the premise of the change was that simply
> 'print(empty)' would now print something useful.
>
> I guess maybe it doesn't hurt to_also_ include some explicit repr
> calls, but I was expecting most tests to just be printing the object
> directly.
>
> Is there some reasoning here that I'm missing?
>
When you make a print(empty) call, python internally calls __str__
instead or __repr__. The latter is only called when the former is not
available or when it is being printed by the interpreter. Since
py-type.c already includes a __str__ implementation, the test would
still pass if you just had print(empty) without Matheus's changes.
--
Cheers,
Bruno
next prev parent reply other threads:[~2023-01-19 8:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3Cc9d2dc49-45c7-d6b9-c567-4ec78dd870a0>
2023-01-11 0:35 ` Matheus Branco Borella
2023-01-18 17:05 ` Bruno Larsen
2023-01-18 18:02 ` Andrew Burgess
2023-01-19 8:23 ` Bruno Larsen [this message]
2023-01-20 1:43 ` Matheus Branco Borella
2023-01-20 16:45 ` Andrew Burgess
2023-01-24 14:45 ` Andrew Burgess
2023-05-18 3:33 ` Matheus Branco Borella
2023-05-19 21:27 ` [PATCHv3 0/2] " Andrew Burgess
2023-05-19 21:27 ` [PATCHv3 1/2] gdb: have mdict_size always return a symbol count Andrew Burgess
2023-05-19 21:27 ` [PATCHv3 2/2] gdb: add __repr__() implementation to a few Python types Andrew Burgess
2023-06-07 17:05 ` [PATCHv3 0/2] Add " Matheus Branco Borella
2023-06-08 18:46 ` Andrew Burgess
2023-06-09 12:33 ` Andrew Burgess
2023-07-04 11:09 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b2fbbb76-3c33-312f-aff8-228eaa20addf@redhat.com \
--to=blarsen@redhat.com \
--cc=aburgess@redhat.com \
--cc=dark.ryu.550@gmail.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).