public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>, Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 03/10] gdb: gdbarch.py: spell out parameters of _Component.__init__
Date: Fri, 24 Feb 2023 22:30:40 -0500	[thread overview]
Message-ID: <20230225033047.373899-4-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20230225033047.373899-1-simon.marchi@polymtl.ca>

The way _Component uses kwargs is handy to save a few characters, but it
doesn't play well with static analysis.  When editing gdbarch.py, my
editor (which uses pylance under the hood) knows nothing about the
properties of components.  So it's full of squiggly lines, and typing
analysis (which I find really helpful) doesn't work.  I therefore think
it would be better to spell out the parameters.

Change-Id: Iaf561beb0d0fbe170ce1c79252a291e0945e1830
Reviewed-By: Tom Tromey <tom@tromey.com>
---
 gdb/gdbarch.py | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py
index 68c7bbae6618..63c3aee1dc0e 100755
--- a/gdb/gdbarch.py
+++ b/gdb/gdbarch.py
@@ -49,9 +49,34 @@ def join_params(params):
 class _Component:
     "Base class for all components."
 
-    def __init__(self, **kwargs):
-        for key in kwargs:
-            setattr(self, key, kwargs[key])
+    def __init__(
+        self,
+        name,
+        type,
+        printer,
+        comment=None,
+        predicate=False,
+        predefault=None,
+        postdefault=None,
+        invalid=None,
+        params=None,
+        param_checks=None,
+        result_checks=None,
+        implement=True,
+    ):
+        self.name = name
+        self.type = type
+        self.printer = printer
+        self.comment = comment
+        self.predicate = predicate
+        self.predefault = predefault
+        self.postdefault = postdefault
+        self.invalid = invalid
+        self.params = params
+        self.param_checks = param_checks
+        self.result_checks = result_checks
+        self.implement = implement
+
         components.append(self)
 
         # It doesn't make sense to have a check of the result value
@@ -87,7 +112,7 @@ class Value(_Component):
         name,
         type,
         comment=None,
-        predicate=None,
+        predicate=False,
         predefault=None,
         postdefault=None,
         invalid=None,
@@ -115,7 +140,7 @@ class Function(_Component):
         type,
         params,
         comment=None,
-        predicate=None,
+        predicate=False,
         predefault=None,
         postdefault=None,
         invalid=None,
-- 
2.39.2


  parent reply	other threads:[~2023-02-25  3:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-25  3:30 [PATCH v2 00/10] Add typing annotations to gdbarch*.py and make-target-delegates.py Simon Marchi
2023-02-25  3:30 ` [PATCH v2 01/10] gdb: remove invalid / dead code from gdbarch.py Simon Marchi
2023-02-25  3:30 ` [PATCH v2 02/10] gdb: reformat Python files with black 23.1.0 Simon Marchi
2023-02-25  3:30 ` Simon Marchi [this message]
2023-02-25  3:30 ` [PATCH v2 04/10] gdb: gdbarch.py: remove Info.__init__ Simon Marchi
2023-02-25  3:30 ` [PATCH v2 05/10] gdb: pyproject.toml: set pyright typeCheckingMode = "strict" Simon Marchi
2023-02-25  3:30 ` [PATCH v2 06/10] gdb: split gdbarch component types to gdbarch_types.py Simon Marchi
2023-02-25  3:30 ` [PATCH v2 07/10] gdb: gdbarch*.py, copyright.py: add type annotations Simon Marchi
2023-02-25  3:30 ` [PATCH v2 08/10] gdb: make-target-delegates.py: make one string raw Simon Marchi
2023-02-25  3:30 ` [PATCH v2 09/10] gdb: make-target-delegates.py: add Entry type Simon Marchi
2023-02-25  3:30 ` [PATCH v2 10/10] gdb: make-target-delegates.py: add type annotations Simon Marchi
2023-02-25 11:05 ` [PATCH v2 00/10] Add typing annotations to gdbarch*.py and make-target-delegates.py Andrew Burgess
2023-02-27  1:11   ` 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=20230225033047.373899-4-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).