{"record":{"id":"013dcf66c6f8b8a4","repo":"apache/beam","slug":"s-is-not-iterable","errorCode":null,"errorMessage":"%s is not iterable","messagePattern":"(.+?) is not iterable","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/typehints.py","lineNumber":1605,"sourceCode":"  if isinstance(type_hint, typing.TypeVar):\n    return typing.Any\n  if isinstance(type_hint, AnyTypeConstraint):\n    return type_hint\n  if isinstance(type_hint, UnionConstraint):\n    yielded_types = set()\n    for typ in type_hint.inner_types():\n      yielded_types.add(get_yielded_type(typ))\n    return Union[yielded_types]\n  if is_consistent_with(type_hint, Iterator[Any]):\n    return type_hint.yielded_type\n  if is_consistent_with(type_hint, Tuple[Any, ...]):\n    if isinstance(type_hint, TupleConstraint):\n      return Union[type_hint.tuple_types]\n    else:  # TupleSequenceConstraint\n      return type_hint.inner_type\n  if is_consistent_with(type_hint, Iterable[Any]):\n    return type_hint.inner_type\n  raise ValueError('%s is not iterable' % type_hint)\n\n\ndef coerce_to_kv_type(element_type, label=None, side_input_producer=None):\n  \"\"\"Attempts to coerce element_type to a compatible kv type.\n\n  Raises an error on failure.\n  \"\"\"\n  if side_input_producer:\n    consumer = 'side-input of %r (producer: %r)' % (label, side_input_producer)\n  else:\n    consumer = '%r' % label\n\n  # If element_type is not specified, then treat it as `Any`.\n  if not element_type:\n    return KV[Any, Any]\n  elif isinstance(element_type, TupleHint.TupleConstraint):\n    if len(element_type.tuple_types) == 2:\n      return element_type","sourceCodeStart":1587,"sourceCodeEnd":1623,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/typehints.py#L1587-L1623","documentation":"Beam's typehint machinery raises this when asked for the element type of a type hint that is not iterable. iterables_type_or_inner_type only extracts inner_type from Iterable-compatible hints; anything else fails. It means you passed a non-iterable type hint where Beam expects a stream of elements.","triggerScenarios":"Calling iterables_type_or_inner_type (directly or via PTransform type inference, e.g. FlatMap/CoGroupByKey expansions) with a hint like int, Dict[str, str], or Any not consistent with Iterable[Any].","commonSituations":"Passing a scalar side input to a transform that requires a PCollection; annotating a DoFn input with a non-iterable hint; CoGroupByKey inputs hinted as dict instead of list/tuple of values.","solutions":["Change the type hint to an iterable form, e.g. List[int], Sequence[Tuple[K, V]], or Iterable[T].","If the value is a single element, wrap it in a list or use a singleton PCollection instead of a side input.","Inspect the hint with apache_beam.typehints.is_consistent_with(hint, Iterable[Any]) before passing it.","If the hint is genuinely unknown, use Any inside an iterable: Iterable[Any]."],"exampleFix":"// before\nwith beam.Pipeline() as p:\n  res = pc | beam.FlatMap(lambda x: x * 2).with_input_types(int)\n// after\nres = pc | beam.FlatMap(lambda x: x * 2).with_input_types(Iterable[int])","handlingStrategy":"type-guard","validationCode":"from apache_beam.typehints import Iterable, is_consistent_with\nif not is_consistent_with(hint, Iterable[Any]):\n    raise TypeError(f'expected iterable type hint, got {hint}')","typeGuard":"def is_iterable_hint(hint) -> bool:\n    from apache_beam.typehints import Iterable, is_consistent_with\n    return is_consistent_with(hint, Iterable[Any])","tryCatchPattern":"try:\n    inner = iterables_type_or_inner_type(hint)\nexcept ValueError:\n    inner = None  # handle non-iterable hint\nif inner is None:\n    hint = Iterable[Any]  # or wrap value in a list","preventionTips":["Prefer concrete iterable hints (List[T], Sequence[T]) on transforms","Run type-check on small sample data pipelines before production","Avoid passing scalars/dicts where PCollections of elements are expected"],"tags":["python","apache-beam","type-hints"],"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"}