Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
From: Tamir Duberstein <tamird@kernel.org>
To: "Kernel.org Tools" <tools@kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
	 Tamir Duberstein <tamird@kernel.org>
Subject: [PATCH patatt 6/7] Reduce dictionary lookups
Date: Sun, 19 Apr 2026 21:22:26 -0400	[thread overview]
Message-ID: <20260419-stronger-type-checking-v1-6-5c108048d2c7@kernel.org> (raw)
In-Reply-To: <20260419-stronger-type-checking-v1-0-5c108048d2c7@kernel.org>

Use `dict.get` instead of separately `in` checks and lookups.

Signed-off-by: Tamir Duberstein <tamird@kernel.org>
---
 src/patatt/__init__.py | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/patatt/__init__.py b/src/patatt/__init__.py
index 7087479..b20074a 100644
--- a/src/patatt/__init__.py
+++ b/src/patatt/__init__.py
@@ -1024,8 +1024,8 @@ def get_data_dir() -> Path:
     Returns:
         Path to $XDG_DATA_HOME/patatt or ~/.local/share/patatt.
     """
-    if 'XDG_DATA_HOME' in os.environ:
-        datahome = Path(os.environ['XDG_DATA_HOME'])
+    if (xdg_data_home := os.environ.get('XDG_DATA_HOME')) is not None:
+        datahome = Path(xdg_data_home)
     else:
         datahome = Path.home() / '.local' / 'share'
     datadir = datahome / 'patatt'
@@ -1100,16 +1100,13 @@ def get_config_from_git(
                 continue
 
             if cfgkey in multivals:
-                if cfgkey not in gitconfig:
-                    values: List[str] = list()
+                cfgvalue = gitconfig.setdefault(cfgkey, list())
+                if isinstance(cfgvalue, str):
+                    values = [cfgvalue]
+                    gitconfig[cfgkey] = values
                 else:
-                    cfgvalue = gitconfig[cfgkey]
-                    if isinstance(cfgvalue, str):
-                        values = [cfgvalue]
-                    else:
-                        values = cfgvalue
+                    values = cfgvalue
                 values.append(value)
-                gitconfig[cfgkey] = values
             else:
                 gitconfig[cfgkey] = value
         except ValueError:
@@ -1423,8 +1420,8 @@ def get_algo_keydata(config: GitConfigType) -> Tuple[str, str]:
             'Identity must be a string, got %s' % type(identity).__name__
         )
 
-    if identity in KEYCACHE:
-        algo, keydata = KEYCACHE[identity]
+    if (t := KEYCACHE.get(identity)) is not None:
+        algo, keydata = t
         return algo, keydata
 
     if not config.get('signingkey'):

-- 
2.53.0


  parent reply	other threads:[~2026-04-20  1:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20  1:22 [PATCH patatt 0/7] Harden local checks Tamir Duberstein
2026-04-20  1:22 ` [PATCH patatt 1/7] Add local CI script Tamir Duberstein
2026-04-20  1:22 ` [PATCH patatt 2/7] Add Ruff import checks Tamir Duberstein
2026-04-20  1:22 ` [PATCH patatt 3/7] Add Ruff format check Tamir Duberstein
2026-04-20  1:22 ` [PATCH patatt 4/7] Add pyright strict checks Tamir Duberstein
2026-04-20  1:22 ` [PATCH patatt 5/7] Add ty checks Tamir Duberstein
2026-04-20  1:22 ` Tamir Duberstein [this message]
2026-04-20  1:22 ` [PATCH patatt 7/7] Import PyNaCl unconditionally Tamir Duberstein
2026-04-27 20:20 ` [PATCH patatt 0/7] Harden local checks Tamir Duberstein

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=20260419-stronger-type-checking-v1-6-5c108048d2c7@kernel.org \
    --to=tamird@kernel.org \
    --cc=konstantin@linuxfoundation.org \
    --cc=tools@kernel.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