<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
    <channel>
      <title>til-with-llm</title>
      <link>https://kiwamizamurai.github.io/til-with-llm</link>
      <description>Last 10 notes on til-with-llm</description>
      <generator>Quartz -- quartz.jzhao.xyz</generator>
      <item>
    <title>__missing__とformat_map()でテンプレートを何回かに分けて埋める</title>
    <link>https://kiwamizamurai.github.io/til-with-llm/python/format-map-missing-partial-template</link>
    <guid>https://kiwamizamurai.github.io/til-with-llm/python/format-map-missing-partial-template</guid>
    <description><![CDATA[ 通知メールの文面で、宛名は今わかるが発送日は後で決まる、ということがある。str.format()は足りないキーが1つでもあるとKeyErrorになるので、埋められるところだけ先に埋めることができない。 tmpl = &quot;Hello {name}, your order {order_id} ships on {date}&quot; tmpl.format(name=&quot;Alice&quot;) # KeyError: &#039;order_id&#039; dictのサブクラスに__missing__を定義すると、存在しないキーをd[key]で引いたときの動きを変えられる... ]]></description>
    <pubDate>Mon, 05 Oct 2026 23:27:20 GMT</pubDate>
  </item><item>
    <title>__init_subclass__とクラス文のキーワード引数でイベントハンドラーを自動登録する</title>
    <link>https://kiwamizamurai.github.io/til-with-llm/python/init-subclass-handler-registry</link>
    <guid>https://kiwamizamurai.github.io/til-with-llm/python/init-subclass-handler-registry</guid>
    <description><![CDATA[ Webhookのイベント名と処理の対応表を手で管理していると、ハンドラーを足したのに表に登録し忘れたり、同じイベントを2つのクラスで処理していたりする。クラスを定義しただけで対応表に載り、二重登録はその場でエラーにしたい。 class Foo(Base, event=&quot;order.paid&quot;)のように、クラス文の基底クラスの後ろにはキーワード引数を書ける。この引数は、基底クラスの__init_subclass__に渡される(3.6から)。メタクラスもデコレーターも使わずに、サブクラスの定義に割り込める。 作り方 class Handler: registry: dict[s... ]]></description>
    <pubDate>Mon, 05 Oct 2026 23:27:20 GMT</pubDate>
  </item><item>
    <title>__format__でログにAPIキーを出さないSecret型を作る</title>
    <link>https://kiwamizamurai.github.io/til-with-llm/python/secret-format-masking</link>
    <guid>https://kiwamizamurai.github.io/til-with-llm/python/secret-format-masking</guid>
    <description><![CDATA[ logger.info(f&quot;calling API with {token}&quot;)のようなログを書くと、本番のログにAPIキーがそのまま残る。値を文字列にする経路で必ず伏せ字になる型を作っておくと、うっかり出力しても漏れない。 f-stringの{x:spec}のspecの部分は、そのままx.__format__(spec)に渡される。書式指定の中身は型が自由に決めてよいので、{token:last4}のような独自の指定も作れる。 作り方 文字列にする経路は__format__(f-stringとstr.format)、__str__(str()と%s)、__repr__(!... ]]></description>
    <pubDate>Mon, 05 Oct 2026 23:27:20 GMT</pubDate>
  </item><item>
    <title>__set_name__で環境変数の設定クラスからキー名の二重書きをなくす</title>
    <link>https://kiwamizamurai.github.io/til-with-llm/python/set-name-env-settings</link>
    <guid>https://kiwamizamurai.github.io/til-with-llm/python/set-name-env-settings</guid>
    <description><![CDATA[ 設定を環境変数から読むとき、database_url = os.environ[&quot;DATABASE_URL&quot;]のように同じ名前を2回書き、型の変換も場所ごとにばらばらに書いていることが多い。pydantic-settingsを入れるほどではない小さなスクリプトやバッチで、これを短く書きたい。 デスクリプタに__set_name__を定義すると、クラスを作るときに「自分がどの属性名に代入されたか」を受け取れる(3.6から)。属性名から環境変数のキーを決めれば、キー名を書かずに済む。 作り方 import os from collections.abc import Calla... ]]></description>
    <pubDate>Mon, 05 Oct 2026 23:27:20 GMT</pubDate>
  </item><item>
    <title>add_note()で例外に処理中のファイルと行を書き足す(Python 3.11)</title>
    <link>https://kiwamizamurai.github.io/til-with-llm/python/exception-add-note</link>
    <guid>https://kiwamizamurai.github.io/til-with-llm/python/exception-add-note</guid>
    <description><![CDATA[ CSVを読み込むバッチでValueError: invalid literal for int() with base 10: &#039;lots&#039;とだけ出て落ちると、どのファイルの何行目かがわからない。 例外を捕まえて別の例外をraise .. ]]></description>
    <pubDate>Mon, 05 Oct 2026 23:18:03 GMT</pubDate>
  </item><item>
    <title>TaskGroup.cancel()で一番早い応答だけを採用する(Python 3.15)</title>
    <link>https://kiwamizamurai.github.io/til-with-llm/python/taskgroup-cancel-first-wins</link>
    <guid>https://kiwamizamurai.github.io/til-with-llm/python/taskgroup-cancel-first-wins</guid>
    <description><![CDATA[ 複数のAPIやミラーに同じ問い合わせを同時に投げて、最初に返ってきた答えだけを使いたいことがある。残りのリクエストは、答えが出た時点で止めたい。 asyncio.TaskGroup(3.11)は「全部終わるまで待つ」か「どれかが失敗したら全部止める」しかできなかった。正常に終わったのに残りを止める手段がなかったので、わざと例外を投げて止めるしかなかった。 これまでの書き方 専用の例外を投げてグループを失敗させ、外側のexcept*で握りつぶす。 import asyncio class FoundIt(Exception): pass async def first_of(*jobs: tup... ]]></description>
    <pubDate>Mon, 05 Oct 2026 23:18:03 GMT</pubDate>
  </item><item>
    <title>lazy importでCLIの起動を速くする(Python 3.15)</title>
    <link>https://kiwamizamurai.github.io/til-with-llm/python/lazy-imports-cli-startup</link>
    <guid>https://kiwamizamurai.github.io/til-with-llm/python/lazy-imports-cli-startup</guid>
    <description><![CDATA[ pandasを使うCLIでtool versionを実行すると、バージョンを表示するだけなのに0.3秒ほど待たされる。ファイルの先頭にあるimport pandasが、使わないサブコマンドでも毎回実行されるからだ。 これまではimportを関数の中に移して回避していたが、依存関係がファイルのあちこちに散らばって読みにくくなる。3.15で入ったlazy import(PEP 810)を使うと、importはファイルの先頭に書いたまま、読み込みを初めて使う時点まで遅らせられる。 使い方 importの前にlazyを付けるだけでよい。 import argparse lazy import pand... ]]></description>
    <pubDate>Mon, 05 Oct 2026 23:13:00 GMT</pubDate>
  </item><item>
    <title>t-stringでSQLインジェクションを型で防ぐ(Python 3.14)</title>
    <link>https://kiwamizamurai.github.io/til-with-llm/python/t-string-sql-builder</link>
    <guid>https://kiwamizamurai.github.io/til-with-llm/python/t-string-sql-builder</guid>
    <description><![CDATA[ f-stringは便利だが、SQLを組み立てるのに使うと事故が起きる。 name = &quot;x&#039; OR &#039;1&#039;=&#039;1&quot; conn.execute(f&quot;SELECT name FROM users WHERE name = &#039;{name}&#039;&quot;).fetchall() # → [(&#039;alice&#039;,), (&#039;bob&#039;,), (&#039;carol&#039;,)] 全件取れてしまう f-stringは評価した時点でただのstrになる。どこまでがSQLで、どこからが... ]]></description>
    <pubDate>Mon, 05 Oct 2026 23:00:33 GMT</pubDate>
  </item><item>
    <title>til-with-llm</title>
    <link>https://kiwamizamurai.github.io/til-with-llm/</link>
    <guid>https://kiwamizamurai.github.io/til-with-llm/</guid>
    <description><![CDATA[ Today I Learned — LLM と一緒にまとめた学びのメモ。 左のエクスプローラーかカテゴリから読めます。ノート同士は [[wikilink]] でつながり、バックリンクとグラフで辿れます。. ]]></description>
    <pubDate>Mon, 05 Oct 2026 19:59:08 GMT</pubDate>
  </item>
    </channel>
  </rss>