{"record":{"id":"94b0550df80317ab","repo":"apache/beam","slug":"bad-type-s","errorCode":null,"errorMessage":"bad type: %s","messagePattern":"bad type: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/typehints.py","lineNumber":431,"sourceCode":"  Args:\n    type_constraint: An instance of a TypeConstraint or a built-in Python type.\n    object_instance: An object instance.\n\n  Raises:\n    SimpleTypeHintError: If 'type_constraint' is a one of the allowed primitive\n      Python types and 'object_instance' isn't an instance of this type.\n    CompositeTypeHintError: If 'type_constraint' is a TypeConstraint object and\n      'object_instance' does not satisfy its constraint.\n  \"\"\"\n  if type_constraint is None and object_instance is None:\n    return\n  elif isinstance(type_constraint, TypeConstraint):\n    type_constraint.type_check(object_instance)\n  elif type_constraint is None:\n    # TODO(robertwb): Fix uses of None for Any.\n    pass\n  elif not isinstance(type_constraint, type):\n    raise RuntimeError(\"bad type: %s\" % (type_constraint, ))\n  elif not isinstance(object_instance, type_constraint):\n    raise SimpleTypeHintError\n\n\nclass AnyTypeConstraint(TypeConstraint):\n  \"\"\"An Any type-hint.\n\n  Any is intended to be used as a \"don't care\" when hinting the types of\n  function arguments or return types. All other TypeConstraint's are equivalent\n  to 'Any', and its 'type_check' method is a no-op.\n  \"\"\"\n  def __eq__(self, other):\n    return type(self) == type(other)\n\n  def __repr__(self):\n    return 'Any'\n\n  def __hash__(self):","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/typehints.py#L413-L449","documentation":"check_constraint raises RuntimeError('bad type: %s') when the type_constraint argument is neither a TypeConstraint, None, nor a Python type (class). This is an internal argument-validation guard: Beam cannot know how to check an object against something that isn't a recognizable type specification.","triggerScenarios":"Calling check_constraint (directly or via type_check paths like _check_instance_type) with an invalid constraint such as an instance, a string like 'int', or a typing generic object not understood by Beam (older Python typing interop gaps).","commonSituations":"Hand-written type hints passed into Beam internals; mixing typing.List[int] objects into Beam's own constraint API on versions where interop is incomplete; custom hint objects that subclass neither TypeConstraint nor type.","solutions":["Ensure the constraint passed is a class (int, str), a beam TypeConstraint, or None.","Convert typing-module generics to Beam hints (or vice versa) compatible with your Beam version; upgrade Beam if typing interop is the issue.","Print type(type_constraint) and its __module__ to see what leaked into the API.","Wrap custom hint classes in TypeConstraint subclasses so check_constraint can dispatch them."],"exampleFix":"# before\ncheck_constraint('int', value)  # string, not a type\n# after\ncheck_constraint(int, value)","handlingStrategy":"type-guard","validationCode":"from apache_beam.typehints import TypeConstraint\ndef is_checkable_constraint(c):\n    return isinstance(c, TypeConstraint) or c is None or isinstance(c, type)","typeGuard":"def is_class(x):\n    return isinstance(x, type)","tryCatchPattern":"try:\n    check_constraint(tc, value)\nexcept RuntimeError as e:\n    if str(e).startswith('bad type:'):\n        logger.error('invalid constraint object: %r', tc)\n    raise","preventionTips":["Only pass classes, TypeConstraint instances, or None to check_constraint","Convert typing generics to Beam-supported forms for your Beam version","Upgrade Beam if mixing typing generics and Beam hints is required"],"tags":["python","apache-beam","typehints","runtime-error"],"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-20T03:17:13.778Z"}