{"record":{"id":"76dbceb6519490c8","repo":"apache/beam","slug":"unknown-forbidden-type-s","errorCode":null,"errorMessage":"Unknown forbidden type: %s","messagePattern":"Unknown forbidden type: (.+?)","errorType":"validation","errorClass":"TypeInferenceError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/trivial_inference.py","lineNumber":93,"sourceCode":"    else:\n      return typehints.Set[typehints.Any]\n  elif t == frozenset:\n    if len(o) > 0:\n      return typehints.FrozenSet[typehints.Union[[\n          instance_to_type(item) for item in o\n      ]]]\n    else:\n      return typehints.FrozenSet[typehints.Any]\n  elif t == dict:\n    if len(o) > 0:\n      return typehints.Dict[\n          typehints.Union[[instance_to_type(k) for k, v in o.items()]],\n          typehints.Union[[instance_to_type(v) for k, v in o.items()]],\n      ]\n    else:\n      return typehints.Dict[typehints.Any, typehints.Any]\n  else:\n    raise TypeInferenceError('Unknown forbidden type: %s' % t)\n\n\ndef union_list(xs, ys):\n  assert len(xs) == len(ys)\n  return [union(x, y) for x, y in zip(xs, ys)]\n\n\nclass Const(object):\n  def __init__(self, value):\n    self.value = value\n    self.type = instance_to_type(value)\n\n  def __eq__(self, other):\n    return isinstance(other, Const) and self.value == other.value\n\n  def __hash__(self):\n    return hash(self.value)\n","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/trivial_inference.py#L75-L111","documentation":"trivial_inference.instance_to_type maps a concrete value to a Beam type hint; if it encounters a type it explicitly refuses to infer (a 'forbidden' type), it raises TypeInferenceError. Beam deliberately does not infer hints from certain object types, so inference stops here rather than guessing a wrong type.","triggerScenarios":"Calling infer_return_type or element_type on a callable whose body/constant involves an instance of an unsupported/forbidden type (e.g. complex objects, module, functions treated as values), typically triggered when decorating a DoFn/FlatMap whose constants include such values.","commonSituations":"Applying @with_input_types/@with_output_types-free pipelines where Beam tries to infer types from a lambda that closes over unusual objects; passing callables or class objects as constants; building a schema from an instance containing an exotic type.","solutions":["Add explicit type hints (with_output_types / with_input_types) so Beam doesn't need to infer from the forbidden value.","Remove or replace the unsupported constant/object referenced in the callable (e.g. don't pass functions/classes as data).","If dicts are involved, make sure the dict instance is homogeneous or annotate it as Dict[Any, Any] explicitly.","Catch TypeInferenceError and fall back to Any typing if inference is optional."],"exampleFix":"// before\np | beam.FlatMap(lambda x: helper(x))  # helper closes over a forbidden object\n// after\np | beam.FlatMap(lambda x: helper(x)).with_output_types(str)","handlingStrategy":"type-guard","validationCode":"ALLOWED = (str, int, float, bool, bytes, list, dict, tuple, set)\ndef inferable(v) -> bool:\n    return type(v) in ALLOWED","typeGuard":"def is_supported_instance(o) -> bool:\n    return isinstance(o, (str, int, float, bool, bytes, list, dict, tuple, set))","tryCatchPattern":"try:\n    hint = infer_return_type(fn, [])\nexcept TypeInferenceError:\n    hint = typehints.Any","preventionTips":["Always declare explicit with_input_types/with_output_types on transforms","Avoid passing functions, modules, or exotic objects as data constants","Pin Beam and Python versions known to work together"],"tags":["python","apache-beam","type-inference"],"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"}