Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jeremy Bryant <jb@jeremybryant.net>
To: Tom Tromey <tom@tromey.com>
Cc: GDB Patches <gdb-patches@sourceware.org>,
	 Simon Marchi <simon.marchi@polymtl.ca>,
	 Simon Marchi <simark@simark.ca>,  Eli Zaretskii <eliz@gnu.org>
Subject: [PATCH v2] - Adapt to Python-3 print syntax
Date: Wed, 15 Oct 2025 21:19:33 +0100	[thread overview]
Message-ID: <874irz9aui.fsf@jeremybryant.net> (raw)
In-Reply-To: <87jz0wth2c.fsf@tromey.com> (Tom Tromey's message of "Wed, 15 Oct 2025 07:44:59 -0600")

[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Jeremy" == Jeremy Bryant <jb@jeremybryant.net> writes:
>
> Jeremy> This change adapts doc examples to Python 3 so they work on current
> Jeremy> installations.
>
> Jeremy> python.texi uses a mixture of Python 3 and Python 2 print syntax, the
> Jeremy> latter having been sunsetted several years ago.
>
> This looks reasonable but:
>
> Jeremy> -(@value{GDBP}) python print 23
> Jeremy> +(@value{GDBP}) python print(23)
>
> Here there's no space after the "print" -- which is standard Python
> style, so seems fine; but...
>
> Jeremy> -print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
> Jeremy> +print (gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\""))
>
> ... here there's no space.  There were a few like this and I wondered
> why the discrepancy.
>
> Tom

Thanks Tom, I've corrected the discrepancy and now all changes are
consistent.  See revised patch v2 inline below for critique and attached
for completeness.
In the course of this, I've also removed a pre-existing extraneous space.

WDYT?



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-doc-python.texi-Adapt-to-Python-3-print-syntax.patch --]
[-- Type: text/x-diff, Size: 2944 bytes --]

From 94dde31def1f9ce943819857a7205b3557276d33 Mon Sep 17 00:00:00 2001
From: Jeremy Bryant <jb@jeremybryant.net>
Date: Tue, 14 Oct 2025 22:55:39 +0100
Subject: [PATCH] * doc/python.texi : Adapt to Python 3 print syntax

This change adapts the print syntax to Python 3.
The documentation examples will then work on current installations.
Python 2 was sunsetted in January 2020.
---
 gdb/doc/python.texi | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ed113173667..9df2c58f210 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -76,7 +76,7 @@ If given an argument, the @code{python} command will evaluate the
 argument as a Python command.  For example:
 
 @smallexample
-(@value{GDBP}) python print 23
+(@value{GDBP}) python print(23)
 23
 @end smallexample
 
@@ -88,7 +88,7 @@ containing @code{end}.  For example:
 
 @smallexample
 (@value{GDBP}) python
->print 23
+>print(23)
 >end
 23
 @end smallexample
@@ -756,7 +756,7 @@ depends on @code{set python print-stack} (@pxref{Python Commands}).
 Example:
 
 @smallexample
-(@value{GDBP}) python print foo
+(@value{GDBP}) python print(foo)
 Traceback (most recent call last):
   File "<string>", line 1, in <module>
 NameError: name 'foo' is not defined
@@ -1945,7 +1945,7 @@ settings.  During a @code{print} or other operation, the values will
 reflect any flags that are temporarily in effect.
 
 @smallexample
-(gdb) python print (gdb.print_options ()['max_elements'])
+(gdb) python print(gdb.print_options ()['max_elements'])
 200
 @end smallexample
 @end defun
@@ -4652,7 +4652,7 @@ Arguments are separated by spaces and may be quoted.
 Example:
 
 @smallexample
-print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
+print(gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\""))
 ['1', '2 "3', '4 "5', "6 '7"]
 @end smallexample
 
@@ -5981,7 +5981,7 @@ Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
 operator, like:
 
 @smallexample
-(@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
+(@value{GDBP}) python print(gdb.newest_frame() == gdb.selected_frame ())
 True
 @end smallexample
 
@@ -9129,7 +9129,7 @@ Then in gdb:
 (gdb) start
 (gdb) python import gdb.types
 (gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
-(gdb) python print gdb.types.get_basic_type(foo_ref.type)
+(gdb) python print(gdb.types.get_basic_type(foo_ref.type))
 int
 @end smallexample
 
@@ -9162,9 +9162,9 @@ Then in @value{GDBN}:
 @smallexample
 (@value{GDBP}) python import gdb.types
 (@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
-(@value{GDBP}) python print struct_a.keys ()
+(@value{GDBP}) python print(struct_a.keys ())
 @{['a', '']@}
-(@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
+(@value{GDBP}) python print([k for k,v in gdb.types.deep_items(struct_a)])
 @{['a', 'b0', 'b1']@}
 @end smallexample
 
-- 
2.47.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-doc-python.texi-Adapt-to-Python-3-print-syntax.patch --]
[-- Type: text/x-diff, Size: 2944 bytes --]

From 94dde31def1f9ce943819857a7205b3557276d33 Mon Sep 17 00:00:00 2001
From: Jeremy Bryant <jb@jeremybryant.net>
Date: Tue, 14 Oct 2025 22:55:39 +0100
Subject: [PATCH] * doc/python.texi : Adapt to Python 3 print syntax

This change adapts the print syntax to Python 3.
The documentation examples will then work on current installations.
Python 2 was sunsetted in January 2020.
---
 gdb/doc/python.texi | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ed113173667..9df2c58f210 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -76,7 +76,7 @@ If given an argument, the @code{python} command will evaluate the
 argument as a Python command.  For example:
 
 @smallexample
-(@value{GDBP}) python print 23
+(@value{GDBP}) python print(23)
 23
 @end smallexample
 
@@ -88,7 +88,7 @@ containing @code{end}.  For example:
 
 @smallexample
 (@value{GDBP}) python
->print 23
+>print(23)
 >end
 23
 @end smallexample
@@ -756,7 +756,7 @@ depends on @code{set python print-stack} (@pxref{Python Commands}).
 Example:
 
 @smallexample
-(@value{GDBP}) python print foo
+(@value{GDBP}) python print(foo)
 Traceback (most recent call last):
   File "<string>", line 1, in <module>
 NameError: name 'foo' is not defined
@@ -1945,7 +1945,7 @@ settings.  During a @code{print} or other operation, the values will
 reflect any flags that are temporarily in effect.
 
 @smallexample
-(gdb) python print (gdb.print_options ()['max_elements'])
+(gdb) python print(gdb.print_options ()['max_elements'])
 200
 @end smallexample
 @end defun
@@ -4652,7 +4652,7 @@ Arguments are separated by spaces and may be quoted.
 Example:
 
 @smallexample
-print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
+print(gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\""))
 ['1', '2 "3', '4 "5', "6 '7"]
 @end smallexample
 
@@ -5981,7 +5981,7 @@ Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
 operator, like:
 
 @smallexample
-(@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
+(@value{GDBP}) python print(gdb.newest_frame() == gdb.selected_frame ())
 True
 @end smallexample
 
@@ -9129,7 +9129,7 @@ Then in gdb:
 (gdb) start
 (gdb) python import gdb.types
 (gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
-(gdb) python print gdb.types.get_basic_type(foo_ref.type)
+(gdb) python print(gdb.types.get_basic_type(foo_ref.type))
 int
 @end smallexample
 
@@ -9162,9 +9162,9 @@ Then in @value{GDBN}:
 @smallexample
 (@value{GDBP}) python import gdb.types
 (@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
-(@value{GDBP}) python print struct_a.keys ()
+(@value{GDBP}) python print(struct_a.keys ())
 @{['a', '']@}
-(@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
+(@value{GDBP}) python print([k for k,v in gdb.types.deep_items(struct_a)])
 @{['a', 'b0', 'b1']@}
 @end smallexample
 
-- 
2.47.2


  reply	other threads:[~2025-10-15 20:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 22:14 [PATCH] " Jeremy Bryant
2025-10-15 12:01 ` Eli Zaretskii
2025-10-15 13:44 ` Tom Tromey
2025-10-15 20:19   ` Jeremy Bryant [this message]
2025-10-15 20:32     ` [PATCH v2] " Tom Tromey
2025-10-16 20:04       ` Ready for Write After Approval - " Jeremy Bryant
2025-10-17 11:25         ` Eli Zaretskii
2025-10-19 19:16           ` Contributor guidelines - " Jeremy Bryant
2025-10-20  2:25             ` Eli Zaretskii
2025-10-17 14:45         ` Tom Tromey
2025-10-19 17:02           ` Thank you - " Jeremy Bryant

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=874irz9aui.fsf@jeremybryant.net \
    --to=jb@jeremybryant.net \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    --cc=simon.marchi@polymtl.ca \
    --cc=tom@tromey.com \
    /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