FunctionInputOutputTypeChecker rejects correct values for fixed-length tuple annotations (tuple[int, str])
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
Línea de trabajo
Empieza en htypes.check_instance, donde el issue indica que listas, conjuntos y tuplas comparten una rama, y compara cómo maneja las tuplas con check_input_type, que ya maneja las tuplas de longitud fija. Añade pruebas para los tipos de los elementos, la longitud de la tupla, las anotaciones de tuplas vacías y tuple[X, ...]; el issue describe los casos esperados de éxito y error. El cambio está terminado cuando esos casos pasen, incluido el comportamiento del adaptador y del controlador.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Jupyter Notebook
- Estrellas
- 2.6k
- Forks
- 223
- Merge medio
- 14 h
- PR fusionados (30 d)
- 12
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/hamilton
-
Engine crashes when client sends nan or inf float to UIQuizá libre de nuevo @Exudev la tomó hace 244 días y no hay ningún pull request abierto. Abiertobug SDK
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
apache/hamilton#1458 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
More detailed type annotations in graph visualizationsQuizá libre de nuevo @Nishant-Manocha la tomó hace 379 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
apache/hamilton#1383 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Documentation: add explainer for FastAPIQuizá libre de nuevo @Aditya-Deshwal23 la tomó hace 198 días y no hay ningún pull request abierto. Abiertodocumentation
Dificultad 2/5 1-2 días Aptitud para principiantes 65/100
apache/hamilton#1304 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
Link back to github from reference API docsPosiblemente ocupada @naikvaib la tomó hace 36 días. Abiertodocumentation good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
apache/hamilton#572 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
Todos los issues de apache/hamilton
Issues similares
-
bug bug:behavior clawsweeper:bulk-filed clawsweeper:fix-shape-clear clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:auth-provider issue-rating: 🦞 diamond lobster P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
openclaw/openclaw#185297 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
agent-ready agent:in-progress backend/api
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 3 días
-
Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
P-47D: GEAR_LVR always reads 1Posiblemente ocupada @cbass2404 la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
DCS-Skunkworks/dcs-bios#1932 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
scikit-learn-contrib/category_encoders#553 ·
Los mantenedores suelen responder en 1 día