public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Remove f-strings from DAP
@ 2023-06-02 15:45 Tom Tromey
  2023-06-02 15:57 ` Paul Koning
  2023-06-12 18:23 ` Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Tom Tromey @ 2023-06-02 15:45 UTC (permalink / raw)
  To: gdb-patches; +Cc: legouguec, Tom Tromey

Kévin pointed out that gdb claims a minimum Python version of 3.2, but
the DAP code uses f-strings, which were added in 3.6.

This patch removes the uses of f-strings from the DAP code.  I can't
test an older version of Python, but I did confirm that this still
works with the version I have.
---
 gdb/python/lib/gdb/dap/evaluate.py | 2 +-
 gdb/python/lib/gdb/dap/io.py       | 2 +-
 gdb/python/lib/gdb/dap/launch.py   | 2 +-
 gdb/python/lib/gdb/dap/state.py    | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py
index fffd255417b..7c4fee4f84b 100644
--- a/gdb/python/lib/gdb/dap/evaluate.py
+++ b/gdb/python/lib/gdb/dap/evaluate.py
@@ -62,7 +62,7 @@ def eval_request(*, expression, frameId=None, context="variables", **args):
     elif context == "repl":
         return send_gdb_with_response(lambda: _repl(expression, frameId))
     else:
-        raise Exception(f'unknown evaluate context "{context}"')
+        raise Exception("unknown evaluate context " + context)
 
 
 @in_gdb_thread
diff --git a/gdb/python/lib/gdb/dap/io.py b/gdb/python/lib/gdb/dap/io.py
index 7cec7b032e3..2f3a2351925 100644
--- a/gdb/python/lib/gdb/dap/io.py
+++ b/gdb/python/lib/gdb/dap/io.py
@@ -60,7 +60,7 @@ def start_json_writer(stream, queue):
             seq = seq + 1
             encoded = json.dumps(obj)
             body_bytes = encoded.encode("utf-8")
-            header = f"Content-Length: {len(body_bytes)}\r\n\r\n"
+            header = "Content-Length: " + str(len(body_bytes)) + "\r\n\r\n"
             header_bytes = header.encode("ASCII")
             stream.write(header_bytes)
             stream.write(body_bytes)
diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py
index 21499a339e1..428fd811471 100644
--- a/gdb/python/lib/gdb/dap/launch.py
+++ b/gdb/python/lib/gdb/dap/launch.py
@@ -40,7 +40,7 @@ def launch(*, program=None, args=[], env=None, **extra):
     if program is not None:
         global _program
         _program = program
-        send_gdb(f"file {_program}")
+        send_gdb("file " + _program)
     if len(args) > 0 or env is not None:
         send_gdb(lambda: _set_args_env(args, env))
 
diff --git a/gdb/python/lib/gdb/dap/state.py b/gdb/python/lib/gdb/dap/state.py
index caf654aaf07..f4f81d2afa0 100644
--- a/gdb/python/lib/gdb/dap/state.py
+++ b/gdb/python/lib/gdb/dap/state.py
@@ -22,4 +22,4 @@ def set_thread(thread_id):
     if thread_id == 0:
         log("+++ Thread == 0 +++")
     else:
-        exec_and_log(f"thread {thread_id}")
+        exec_and_log("thread " + str(thread_id))
-- 
2.40.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Remove f-strings from DAP
  2023-06-02 15:45 [PATCH] Remove f-strings from DAP Tom Tromey
@ 2023-06-02 15:57 ` Paul Koning
  2023-06-02 16:34   ` Tom Tromey
  2023-06-12 18:23 ` Tom Tromey
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Koning @ 2023-06-02 15:57 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, legouguec



> On Jun 2, 2023, at 11:45 AM, Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> wrote:
> 
> Kévin pointed out that gdb claims a minimum Python version of 3.2, but
> the DAP code uses f-strings, which were added in 3.6.
> 
> This patch removes the uses of f-strings from the DAP code.  I can't
> test an older version of Python, but I did confirm that this still
> works with the version I have.
> ---
> gdb/python/lib/gdb/dap/evaluate.py | 2 +-
> gdb/python/lib/gdb/dap/io.py       | 2 +-
> gdb/python/lib/gdb/dap/launch.py   | 2 +-
> gdb/python/lib/gdb/dap/state.py    | 2 +-
> 4 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py
> index fffd255417b..7c4fee4f84b 100644
> --- a/gdb/python/lib/gdb/dap/evaluate.py
> +++ b/gdb/python/lib/gdb/dap/evaluate.py
> @@ -62,7 +62,7 @@ def eval_request(*, expression, frameId=None, context="variables", **args):
>     elif context == "repl":
>         return send_gdb_with_response(lambda: _repl(expression, frameId))
>     else:
> -        raise Exception(f'unknown evaluate context "{context}"')
> +        raise Exception("unknown evaluate context " + context)

That (and the others) is not quite equivalent to what was there before.  You might do this with calls to the "format" method explicitly, as in:

+        raise Exception('unknown evaluate context "{}"'.format(context))

	paul


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Remove f-strings from DAP
  2023-06-02 15:57 ` Paul Koning
@ 2023-06-02 16:34   ` Tom Tromey
  2023-06-02 18:14     ` Paul Koning
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2023-06-02 16:34 UTC (permalink / raw)
  To: Paul Koning; +Cc: Tom Tromey, gdb-patches, legouguec

>>>>> "Paul" == Paul Koning <paulkoning@comcast.net> writes:

>> -        raise Exception(f'unknown evaluate context "{context}"')
>> +        raise Exception("unknown evaluate context " + context)

Paul> That (and the others) is not quite equivalent to what was there
Paul> before.

Yeah, it isn't identical, but it's the same in practice.

In some spots the argument is known to be a string, and in ones where
str() is applied, it's known to be an int.  This is clearer after the
runtime type-checking patch is applied.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Remove f-strings from DAP
  2023-06-02 16:34   ` Tom Tromey
@ 2023-06-02 18:14     ` Paul Koning
  2023-06-02 19:02       ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Koning @ 2023-06-02 18:14 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, legouguec



> On Jun 2, 2023, at 12:34 PM, Tom Tromey <tromey@adacore.com> wrote:
> 
>>>>>> "Paul" == Paul Koning <paulkoning@comcast.net> writes:
> 
>>> -        raise Exception(f'unknown evaluate context "{context}"')
>>> +        raise Exception("unknown evaluate context " + context)
> 
> Paul> That (and the others) is not quite equivalent to what was there
> Paul> before.
> 
> Yeah, it isn't identical, but it's the same in practice.
> 
> In some spots the argument is known to be a string, and in ones where
> str() is applied, it's known to be an int.  This is clearer after the
> runtime type-checking patch is applied.
> 
> Tom

Ok, but at least in that line I pointed to, the output is different: the previous text quotes the value while your changed code does not.

	paul


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Remove f-strings from DAP
  2023-06-02 18:14     ` Paul Koning
@ 2023-06-02 19:02       ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2023-06-02 19:02 UTC (permalink / raw)
  To: Paul Koning; +Cc: Tom Tromey, gdb-patches, legouguec

Paul> Ok, but at least in that line I pointed to, the output is
Paul> different: the previous text quotes the value while your changed
Paul> code does not.

Ah, now I see what you mean.  I've fixed that.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Remove f-strings from DAP
  2023-06-02 15:45 [PATCH] Remove f-strings from DAP Tom Tromey
  2023-06-02 15:57 ` Paul Koning
@ 2023-06-12 18:23 ` Tom Tromey
  1 sibling, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2023-06-12 18:23 UTC (permalink / raw)
  To: Tom Tromey via Gdb-patches; +Cc: Tom Tromey, legouguec

>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> Kévin pointed out that gdb claims a minimum Python version of 3.2, but
Tom> the DAP code uses f-strings, which were added in 3.6.

Tom> This patch removes the uses of f-strings from the DAP code.  I can't
Tom> test an older version of Python, but I did confirm that this still
Tom> works with the version I have.

I'm checking in the updated version of this patch.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-12 18:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-02 15:45 [PATCH] Remove f-strings from DAP Tom Tromey
2023-06-02 15:57 ` Paul Koning
2023-06-02 16:34   ` Tom Tromey
2023-06-02 18:14     ` Paul Koning
2023-06-02 19:02       ` Tom Tromey
2023-06-12 18:23 ` Tom Tromey

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).