FunctionInputOutputTypeChecker rejects correct values for fixed-length tuple annotations (tuple[int, str])
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
htypes.check_instanceから始めます。issueによると、list、set、tupleは同じ分岐を共有しています。固定長のtupleをすでに処理するcheck_input_typeと、tupleの処理を比較してください。要素の型、tupleの長さ、空のtupleのアノテーション、tuple[X, ...]を網羅するテストを追加してください。issueには、期待される成功ケースと失敗ケースが記載されています。アダプターとドライバーの動作も含め、これらのケースが通れば変更は完了です。
索引モデルが issue の本文から書いたものです。
説明
With lifecycle.default.FunctionInputOutputTypeChecker enabled, a node annotated with a fixed-length tuple such as tuple[int, str] fails on a correct value, and a wrong-length tuple passes.
Current behavior
htypes.check_instance handles list, set and tuple in one branch and checks every element against the first type argument (element_type = element_type[0]). For tuple[int, str] that means "a" is checked against int.
check_instance((1, "a"), tuple[int, str])returns Falsecheck_instance((1,), tuple[int, str])returns Truecheck_instance((1,), tuple[()])raisesIndexError: tuple index out of range
tuple[int, ...] is handled correctly. check_input_type already handles fixed-length tuples (#1550); check_instance does not.
Stack Traces
File "hamilton/lifecycle/default.py", line 533, in run_after_node_execution
raise TypeError(
TypeError: Node pair returned a result of type <class 'tuple'>, expected tuple[int, str]
Steps to replicate behavior
from hamilton import ad_hoc_utils, driver
from hamilton.lifecycle import default
def pair() -> tuple[int, str]:
return 1, "a"
def describe(pair: tuple[int, str]) -> str:
return f"{pair[0]}-{pair[1]}"
dr = (
driver.Builder()
.with_modules(ad_hoc_utils.create_temporary_module(pair, describe))
.with_adapters(default.FunctionInputOutputTypeChecker())
.build()
)
dr.execute(["describe"]) # TypeError: Node pair returned a result of type <class 'tuple'>, expected tuple[int, str]
Without the adapter it returns {'describe': '1-a'}.
Library & System Information
Apache Hamilton main @ fa786eae, Python 3.12, macOS.
Expected behavior
Fixed-length tuples are checked position by position, including the length: (1, "a") passes for tuple[int, str], while (1,) and ("a", 1) are rejected. tuple[X, ...] keeps checking every element against X.
Additional context
The fix is a small extra branch in check_instance for origin is tuple when the type isn't tuple[X, ...]. It doesn't overlap with #1739 (other generics in the same function). I have it with regression tests (unit tests plus a driver test with the adapter) and would like to open a PR for it.
Disclosure: found, reproduced and the draft fix tested locally with the help of an AI coding agent (Claude Code); reviewed before filing.
- 主要言語
- Jupyter Notebook
- スター
- 2.6k
- フォーク
- 223
- 平均マージ
- 14時間
- マージ済み PR(30日)
- 12
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/hamilton のほかの issue
-
Engine crashes when client sends nan or inf float to UI再び着手できるかも @Exudev が 242 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug SDK
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
apache/hamilton#1458 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
More detailed type annotations in graph visualizations再び着手できるかも @Nishant-Manocha が 377 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
apache/hamilton#1383 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
Documentation: add explainer for FastAPI再び着手できるかも @Aditya-Deshwal23 が 197 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンdocumentation
難易度 2/5 1〜2日 初心者へのやさしさ 65/100
apache/hamilton#1304 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
Link back to github from reference API docs対応中かも @naikvaib が 34 日前に担当しました。 オープンdocumentation good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/hamilton#572 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
apache/hamilton の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
bigcapitalhq/bigcapital#1545 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
conda-forge/conda-forge-bot#7025 ·
メンテナーはふだん 1 日以内に返信
-
area/backends bug session-analysis
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
home-assistant/core#188424 ·
メンテナーはふだん 1 日以内に返信