{"record":{"id":"4d66a10f246c95f9","repo":"apache/beam","slug":"bad-tuple-arguments-for-s-expected-s-got-s","errorCode":null,"errorMessage":"Bad tuple arguments for %s: expected %s, got %s","messagePattern":"Bad tuple arguments for (.+?): expected (.+?), got (.+?)","errorType":"validation","errorClass":"TypeCheckError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/decorators.py","lineNumber":702,"sourceCode":"  Tuple[Tuple[Int, Any], float] when applied to the type hints\n  {a: int, b: Any, c: float}.\n  \"\"\"\n  if isinstance(arg, list):\n    return typehints.Tuple[[_positional_arg_hints(a, hints) for a in arg]]\n  return hints.get(arg, typehints.Any)\n\n\ndef _unpack_positional_arg_hints(arg, hint):\n  \"\"\"Unpacks the given hint according to the nested structure of arg.\n\n  For example, if arg is [[a, b], c] and hint is Tuple[Any, int], then\n  this function would return ((Any, Any), int) so it can be used in conjunction\n  with inspect.getcallargs.\n  \"\"\"\n  if isinstance(arg, list):\n    tuple_constraint = typehints.Tuple[[typehints.Any] * len(arg)]\n    if not typehints.is_consistent_with(hint, tuple_constraint):\n      raise TypeCheckError(\n          'Bad tuple arguments for %s: expected %s, got %s' %\n          (arg, tuple_constraint, hint))\n    if isinstance(hint, typehints.TupleConstraint):\n      return tuple(\n          _unpack_positional_arg_hints(a, t)\n          for a, t in zip(arg, hint.tuple_types))\n    return (typehints.Any, ) * len(arg)\n  return hint\n\n\ndef _normalize_var_positional_hint(hint):\n  \"\"\"Converts a var_positional hint into Tuple[Union[<types>], ...] form.\n\n  Args:\n    hint: (tuple) Should be either a tuple of one or more types, or a single\n      Tuple[<type>, ...].\n\n  Raises:","sourceCodeStart":684,"sourceCodeEnd":720,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/decorators.py#L684-L720","documentation":"_unpack_positional_arg_hints verifies that a hint given for a *args-style list argument is consistent with a Tuple[Any, ..., Any] of the list's length. When the hint cannot match the tuple arity/shape (e.g. hint is int for a 3-element list, or a variadic Tuple where a fixed one is needed), it raises TypeCheckError.","triggerScenarios":"Calling with_input_types / @with_input_types with a list positional argument whose declared hint is not consistent with Tuple[Any]*len(list), e.g. hint=List[int] or int for a fixed-length list arg, then getcallargs_forhints unpacks positional hints.","commonSituations":"Annotating *args-using functions where the hint was written for a homogeneous variable-length tuple but the unpacker needs fixed arity; copy-pasted hints between functions with different arity.","solutions":["Change the hint to a fixed-length Tuple matching the list length, e.g. Tuple[int, int, int] for 3 elements","If the argument is truly variadic, restructure so the hint is Tuple[Any, ...] handled by the VAR_POSITIONAL path instead of a list","Print the expected tuple_constraint vs actual hint from the message and align arities","Use Any elements if the exact per-element types are unknown: Tuple[Any, Any, Any]"],"exampleFix":"// before\nwith_input_types(List[int], int)\ndef f(points, n): ...\n// after\nfrom apache_beam.typehints import Tuple\nwith_input_types(Tuple[int, int, int], int)\ndef f(points, n): ...","handlingStrategy":"validation","validationCode":"from apache_beam import typehints\ndef check_tuple_hint(hint, n):\n  expected = typehints.Tuple[[typehints.Any] * n]\n  return typehints.is_consistent_with(hint, expected)","typeGuard":null,"tryCatchPattern":"try:\n  getcallargs_forhints(fn, hints)\nexcept TypeCheckError as e:\n  log.error('positional hint arity mismatch: %s', e)","preventionTips":["Match fixed-length Tuple hints to list argument length","Use variadic Tuple[T, ...] only for true *args","Test with_input_types declarations in unit tests"],"tags":["python","type-hints","apache-beam"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}