From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH] gdb: add type annotations to ada-unicode.py
Date: Thu, 25 Apr 2024 13:26:11 -0400 [thread overview]
Message-ID: <20240425172618.44739-1-simon.marchi@efficios.com> (raw)
Add type annotations to ada-unicode.py, just enough to make pyright
happy:
$ pyright --version
pyright 1.1.359
$ pyright ada-unicode.py
0 errors, 0 warnings, 0 informations
Introduce a `Range` class instead of using separate variables and
tuples, to make the code and type annotations a bit cleaner.
When running ada-unicode.py, I get a diff for ada-casefold.h, but I get
the same diff before and after this patch, so that is a separate issue.
Change-Id: I0d8975a57f9fb115703178ae197dc6b6b8b4eb7a
---
gdb/ada-unicode.py | 98 +++++++++++++++++++++++++++++-----------------
1 file changed, 61 insertions(+), 37 deletions(-)
diff --git a/gdb/ada-unicode.py b/gdb/ada-unicode.py
index 06c5de0f6e55..f128dee69f54 100755
--- a/gdb/ada-unicode.py
+++ b/gdb/ada-unicode.py
@@ -25,41 +25,59 @@
import gdbcopyright
-# The start of the current range of case-conversions we are
-# processing. If RANGE_START is None, then we're outside of a range.
-range_start = None
-# End of the current range.
-range_end = None
-# The delta between RANGE_START and the upper-case variant of that
-# character.
-upper_delta = None
-# The delta between RANGE_START and the lower-case variant of that
-# character.
-lower_delta = None
+
+class Range:
+ def __init__(self, range_start: int, upper_delta: int, lower_delta: int):
+ self._range_start = range_start
+ self._range_end = range_start
+ self._upper_delta = upper_delta
+ self._lower_delta = lower_delta
+
+ # The start of the range.
+ @property
+ def range_start(self):
+ return self._range_start
+
+ # The end of the range.
+ @property
+ def range_end(self):
+ return self._range_end
+
+ @range_end.setter
+ def range_end(self, val: int):
+ self._range_end = val
+
+ # The delta between RANGE_START and the upper-case variant of that
+ # character.
+ @property
+ def upper_delta(self):
+ return self._upper_delta
+
+ # The delta between RANGE_START and the lower-case variant of that
+ # character.
+ @property
+ def lower_delta(self):
+ return self._lower_delta
+
+
+# The current range we are processing. If None, then we're outside of a range.
+current_range: Range | None = None
# All the ranges found and completed so far.
-# Each entry is a tuple of the form (START, END, UPPER_DELTA, LOWER_DELTA).
-all_ranges = []
+all_ranges: list[Range] = []
def finish_range():
- global range_start
- global range_end
- global upper_delta
- global lower_delta
- if range_start is not None:
- all_ranges.append((range_start, range_end, upper_delta, lower_delta))
- range_start = None
- range_end = None
- upper_delta = None
- lower_delta = None
-
-
-def process_codepoint(val):
- global range_start
- global range_end
- global upper_delta
- global lower_delta
+ global current_range
+
+ if current_range is not None:
+ all_ranges.append(current_range)
+ current_range = None
+
+
+def process_codepoint(val: int):
+ global current_range
+
c = chr(val)
low = c.lower()
up = c.upper()
@@ -74,13 +92,16 @@ def process_codepoint(val):
return
updelta = ord(up) - val
lowdelta = ord(low) - val
- if range_start is not None and (updelta != upper_delta or lowdelta != lower_delta):
+
+ if current_range is not None and (
+ updelta != current_range.upper_delta or lowdelta != current_range.lower_delta
+ ):
finish_range()
- if range_start is None:
- range_start = val
- upper_delta = updelta
- lower_delta = lowdelta
- range_end = val
+
+ if current_range is None:
+ current_range = Range(val, updelta, lowdelta)
+
+ current_range.range_end = val
for c in range(0, 0x10FFFF):
@@ -93,4 +114,7 @@ with open("ada-casefold.h", "w") as f:
)
print("", file=f)
for r in all_ranges:
- print(f" {{{r[0]}, {r[1]}, {r[2]}, {r[3]}}},", file=f)
+ print(
+ f" {{{r.range_start}, {r.range_end}, {r.upper_delta}, {r.lower_delta}}},",
+ file=f,
+ )
base-commit: 5b9707eb872ad4cb50c98d396d16f110070a44ca
--
2.44.0
next reply other threads:[~2024-04-25 17:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-25 17:26 Simon Marchi [this message]
2024-04-25 18:25 ` Tom Tromey
2024-04-25 18:37 ` Simon Marchi
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=20240425172618.44739-1-simon.marchi@efficios.com \
--to=simon.marchi@efficios.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).