{"record":{"id":"9b4cf1aa9c60be3d","repo":"apache/beam","slug":"parameter-to-dict-type-hint-must-be-a-tuple-of-types-dict","errorCode":null,"errorMessage":"Parameter to Dict type-hint must be a tuple of types: Dict[.., ..].","messagePattern":"Parameter to Dict type-hint must be a tuple of types: Dict\\[\\.\\., \\.\\.\\]\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/typehints.py","lineNumber":949,"sourceCode":"        bindings = {}\n        bindings.update(\n            match_type_variables(self.key_type, concrete_type.key_type))\n        bindings.update(\n            match_type_variables(self.value_type, concrete_type.value_type))\n        return bindings\n      return {}\n\n    def bind_type_variables(self, bindings):\n      bound_key_type = bind_type_variables(self.key_type, bindings)\n      bound_value_type = bind_type_variables(self.value_type, bindings)\n      if (bound_key_type, self.key_type) == (bound_value_type, self.value_type):\n        return self\n      return Dict[bound_key_type, bound_value_type]\n\n  def __getitem__(self, type_params):\n    # Type param must be a (k, v) pair.\n    if not isinstance(type_params, tuple):\n      raise TypeError(\n          'Parameter to Dict type-hint must be a tuple of types: '\n          'Dict[.., ..].')\n\n    if len(type_params) != 2:\n      raise TypeError(\n          'Length of parameters to a Dict type-hint must be exactly 2. Passed '\n          'parameters: %s, have a length of %s.' %\n          (type_params, len(type_params)))\n\n    key_type, value_type = type_params\n\n    validate_composite_type_param(\n        key_type, error_msg_prefix='Key-type parameter to a Dict hint')\n    validate_composite_type_param(\n        value_type, error_msg_prefix='Value-type parameter to a Dict hint')\n\n    return self.DictConstraint(key_type, value_type)\n","sourceCodeStart":931,"sourceCodeEnd":967,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/typehints.py#L931-L967","documentation":"DictHint.__getitem__ is a type guard on subscripted Dict[...] hints: the type parameters must arrive as a tuple of exactly two types (Dict[K, V]); a bare single type (e.g. Dict[str] missing the value type) fails this check at typehint-construction time.","triggerScenarios":"Dict[str] (one param); Dict[[str, int]] or other non-tuple containers; programmatically building params as a list.","commonSituations":"Typos in annotations; dynamic hint builders passing lists; porting typing.Dict usage where a single type argument was intended (e.g. Dict[str] is invalid there too, but errors differ).","solutions":["Use two parameters: Dict[str, int]","Convert dynamic params to a 2-tuple: Dict[tuple(params)] with len==2","Use Any for the un-constrained side, e.g. Dict[str, Any]"],"exampleFix":"# before\nDict[str]\n# after\nDict[str, Any]","handlingStrategy":"type-guard","validationCode":"assert isinstance(params, tuple) and len(params) == 2, 'Dict requires (K, V) tuple'","typeGuard":"def valid_dict_params(p): return isinstance(p, tuple) and len(p) == 2","tryCatchPattern":null,"preventionTips":["Always subscript Dict with two types","Use Any for unconstrained sides; coerce dynamic param lists to tuples"],"tags":["python","apache-beam","type-hints","dict"],"backgroundTag":"invalid-argument-format","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"}