Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

FunctionInputOutputTypeChecker rejects correct values for fixed-length tuple annotations (tuple[int, str])

Aperta Adatta ai principianti
#1,749 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia in htypes.check_instance, dove l’issue dice che liste, set e tuple condividono un ramo, e confronta la gestione delle tuple con check_input_type, che gestisce già le tuple di lunghezza fissa. Aggiungi test per i tipi degli elementi, la lunghezza delle tuple, le annotazioni di tuple vuote e tuple[X, ...]; l’issue descrive i casi di successo e fallimento attesi. La modifica è completata quando questi casi passano, incluso il comportamento dell’adattatore e del driver.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 False
  • check_instance((1,), tuple[int, str]) returns True
  • check_instance((1,), tuple[()]) raises IndexError: 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.

Lingua principale
Jupyter Notebook
Stelle
2.6k
Fork
218
Merge medio
2g 13h
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/hamilton

Tutte le issue di apache/hamilton

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.