{"record":{"id":"b37ef77afdd581f4","repo":"apache/beam","slug":"unsupported-union-with-no-arguments","errorCode":null,"errorMessage":"Unsupported Union with no arguments.","messagePattern":"Unsupported Union with no arguments\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/native_type_compatibility.py","lineNumber":518,"sourceCode":"          beam_type=typehints.Mapping),\n  ]\n\n  # Find the first matching entry.\n  matched_entry = next((entry for entry in type_map if entry.match(typ)), None)\n  if not matched_entry:\n    # Please add missing type support if you see this message.\n    _LOGGER.info('Using Any for unsupported type: %s', typ)\n    return typehints.Any\n\n  args = _get_args(typ)\n  len_args = len(args)\n  if len_args == 0 and len_args != matched_entry.arity:\n    arity = matched_entry.arity\n    # Handle unsubscripted types.\n    if _match_issubclass(typing.Tuple)(typ):\n      args = (typehints.TypeVariable('T'), Ellipsis)\n    elif _match_is_union(typ):\n      raise ValueError('Unsupported Union with no arguments.')\n    elif _match_issubclass(typing.Generator)(typ):\n      # Assume a simple generator.\n      args = (typehints.TypeVariable('T_co'), type(None), type(None))\n    elif _match_issubclass(typing.Dict)(typ):\n      args = (typehints.TypeVariable('KT'), typehints.TypeVariable('VT'))\n    elif (_match_issubclass(typing.Iterator)(typ) or\n          _match_is_exactly_iterable(typ)):\n      args = (typehints.TypeVariable('T_co'), )\n    else:\n      args = (typehints.TypeVariable('T'), ) * arity\n  elif matched_entry.arity == -1:\n    arity = len_args\n  # Counters are special dict types that are implicitly parameterized to\n  # [T, int], so we fix cases where they only have one argument to match\n  # a more traditional dict hint.\n  elif len_args == 1 and _safe_issubclass(getattr(typ, '__origin__', typ),\n                                          collections.Counter):\n    args = (args[0], int)","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/native_type_compatibility.py#L500-L536","documentation":"convert_to_beam_type translates native typing annotations into Beam typehints. A bare typing.Union (used without subscript, i.e. no member types) has no arguments to convert, so Beam raises ValueError 'Unsupported Union with no arguments.' Bare Union is essentially meaningless in an annotation.","triggerScenarios":"Writing output_types=Union (unsubscripted) in @with_output_types, from_callable hint extraction, or _extract_tagged_from_type — anywhere a native typing annotation is a plain Union object with len(args)==0 and the union branch of the unsubscripted-type handler is hit.","commonSituations":"Typos like Union instead of Union[int, str]; using typing.Union itself as a sentinel/default value in generated code or metaprogramming; forgetting subscripts when converting from string annotations via get_type_hints.","solutions":["Subscript the union with its member types: Union[int, str] instead of bare Union","If any type is acceptable, use typing.Any instead of a bare Union","If a default placeholder is needed in generated code, use object or Any rather than typing.Union","Run typing.get_type_hints on string annotations so unresolved ForwardRefs don't surface as bare Union"],"exampleFix":"// before\n@with_output_types(Union)\ndef f(x): ...\n// after\nfrom typing import Union\n@with_output_types(Union[int, str])\ndef f(x): ...","handlingStrategy":"type-guard","validationCode":"from typing import Union, get_args, Any\ndef is_subscripted_union(t):\n  return t is not Union and (get_args(t) != () or get_origin(t) is not Union)","typeGuard":"def is_usable_native_type(t):\n  if t is Union:\n    return False\n  o = get_origin(t)\n  return o is not Union or len(get_args(t)) > 0","tryCatchPattern":"try:\n  beam_hint = convert_to_beam_type(t)\nexcept ValueError as e:\n  if 'no arguments' in str(e):\n    beam_hint = Any  # treat bare Union as Any","preventionTips":["Always subscript Union: Union[int, str]","Use typing.Any instead of bare Union as an 'any type' placeholder","Run typing.get_type_hints to resolve string annotations before conversion"],"tags":["python","type-hints","apache-beam","typing"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}