{"record":{"id":"94259e82e64a3e1f","repo":"apache/beam","slug":"length-of-parameters-to-a-mapping-type-hint-must-be-exactly","errorCode":null,"errorMessage":"Length of parameters to a Mapping type-hint must be exactly 2. Passed parameters: %s, have a length of %s.","messagePattern":"Length of parameters to a Mapping type-hint must be exactly 2\\. Passed parameters: (.+?), have a length of (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/typehints.py","lineNumber":1242,"sourceCode":"            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, bound_value_type) == (self.key_type, self.value_type):\n        return self\n      return Mapping[bound_key_type, bound_value_type]\n\n  def __getitem__(self, type_params):\n    if not isinstance(type_params, tuple):\n      raise TypeError(\n          'Parameter to Mapping type-hint must be a tuple of types: '\n          'Mapping[.., ..].')\n\n    if len(type_params) != 2:\n      raise TypeError(\n          'Length of parameters to a Mapping type-hint must be exactly 2. '\n          'Passed 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 Mapping hint')\n    validate_composite_type_param(\n        value_type, error_msg_prefix='Value-type parameter to a Mapping hint')\n\n    return self.MappingTypeConstraint(key_type, value_type)\n\n\nMappingTypeConstraint = MappingHint.MappingTypeConstraint\n\n\nclass IterableHint(CompositeTypeHint):","sourceCodeStart":1224,"sourceCodeEnd":1260,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/typehints.py#L1224-L1260","documentation":"Mapping[...] type-hints must be parameterized with exactly two types (key and value). This TypeError is raised by Mapping.__getitem__ when a tuple whose length is not 2 is used to parameterize the hint.","triggerScenarios":"Writing Mapping[int, str, float] (three parameters) or Mapping[int, str, ...] in an output-type annotation or type_check call.","commonSituations":"Copy-paste from nested generic syntax; thinking Mapping accepts extra params like variadic tuples; code generators emitting wrong arity.","solutions":["Reduce to exactly two parameters: Mapping[K, V]","Fold extra info into the value type (e.g. Mapping[K, Tuple[V1, V2]])","Use Any for sides you do not want to constrain"],"exampleFix":"// before\n.with_output_types(Mapping[str, int, float])\n// after\n.with_output_types(Mapping[str, Tuple[int, float]])","handlingStrategy":"type-guard","validationCode":"assert isinstance(params, tuple) and len(params) == 2, params","typeGuard":"def valid_mapping_params(params):\n    return isinstance(params, tuple) and len(params) == 2","tryCatchPattern":"try:\n    hint = Mapping[k, v, extra]\nexcept TypeError:\n    hint = Mapping[k, Tuple[v, type(extra)]]","preventionTips":["Never pass more than two type params to Mapping","Bundle extra types into Tuple/Union on the value side","Run mypy over pipeline modules"],"tags":["python","apache-beam","type-hints","mapping"],"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"}