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 v2 3/4] Reduce dictionary lookups
Date: Fri, 18 Sep 2026 15:02:54 -0400	[thread overview]
Message-ID: <20260918-stronger-type-checking-v2-3-37de1d8a6c86@kernel.org> (raw)
In-Reply-To: <20260918-stronger-type-checking-v2-0-37de1d8a6c86@kernel.org>

Use dict.get instead of separate membership checks and lookups when
reading XDG_DATA_HOME and cached identity keys.

Signed-off-by: Tamir Duberstein <tamird@kernel.org>
Assisted-by: LLM
---
 src/patatt/__init__.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/patatt/__init__.py b/src/patatt/__init__.py
index d33ff68..7254fcc 100644
--- a/src/patatt/__init__.py
+++ b/src/patatt/__init__.py
@@ -1037,8 +1037,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'
@@ -1454,8 +1454,7 @@ def get_algo_keydata(config: GitConfigType) -> tuple[str, str]:
             f'Identity must be a string, got {type(identity).__name__}'
         )
 
-    if identity in KEYCACHE:
-        cached = KEYCACHE[identity]
+    if (cached := KEYCACHE.get(identity)) is not None:
         assert isinstance(cached, tuple)
         algo, keydata = cached
         assert isinstance(algo, str)

-- 
2.56.0.rc0.682.g1951b10616.frankengit


  parent reply	other threads:[~2026-09-18 19:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 19:02 [PATCH patatt v2 0/4] Harden local checks Tamir Duberstein
2026-09-18 19:02 ` [PATCH patatt v2 1/4] Track uv.lock for reproducible checks Tamir Duberstein
2026-09-18 19:02 ` [PATCH patatt v2 2/4] Tighten local type and lint checks Tamir Duberstein
2026-09-18 19:02 ` Tamir Duberstein [this message]
2026-09-18 19:02 ` [PATCH patatt v2 4/4] Import PyNaCl unconditionally Tamir Duberstein
2026-10-05 10:46 ` [PATCH patatt v2 0/4] Harden local checks Konstantin Ryabitsev

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=20260918-stronger-type-checking-v2-3-37de1d8a6c86@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