{"record":{"id":"9deab6bb7a261a31","repo":"apache/beam","slug":"ptransform-cannot-have-both-positional-and-keyword-input","errorCode":null,"errorMessage":"PTransform cannot have both positional and keyword input type hints without overriding %s._type_check_%s()","messagePattern":"PTransform cannot have both positional and keyword input type hints without overriding (.+?)\\._type_check_(.+?)\\(\\)","errorType":"validation","errorClass":"TypeCheckError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/ptransform.py","lineNumber":499,"sourceCode":"\n  def type_check_inputs(self, pvalueish):\n    self.type_check_inputs_or_outputs(pvalueish, 'input')\n\n  def infer_output_type(self, unused_input_type):\n    return self.get_type_hints().simple_output_type(self.label) or typehints.Any\n\n  def type_check_outputs(self, pvalueish):\n    self.type_check_inputs_or_outputs(pvalueish, 'output')\n\n  def type_check_inputs_or_outputs(self, pvalueish, input_or_output):\n    type_hints = self.get_type_hints()\n    hints = getattr(type_hints, input_or_output + '_types')\n    if hints is None or not any(hints):\n      return\n    arg_hints, kwarg_hints = hints\n    # Output types can have kwargs for tagged output types.\n    if arg_hints and kwarg_hints and input_or_output != 'output':\n      raise TypeCheckError(\n          'PTransform cannot have both positional and keyword input type hints'\n          ' without overriding %s._type_check_%s()' %\n          (self.__class__, input_or_output))\n    root_hint = (\n        arg_hints[0] if len(arg_hints) == 1 else arg_hints or kwarg_hints)\n    for context, pvalue_, hint in _ZipPValues().visit(pvalueish, root_hint):\n      if isinstance(pvalue_, DoOutputsTuple):\n        continue\n      if pvalue_.element_type is None:\n        # TODO(robertwb): It's a bug that we ever get here. (typecheck)\n        continue\n      if hint and not typehints.is_consistent_with(pvalue_.element_type, hint):\n        at_context = ' %s %s' % (input_or_output, context) if context else ''\n        raise TypeCheckError(\n            '{type} type hint violation at {label}{context}: expected {hint}, '\n            'got {actual_type}'.format(\n                type=input_or_output.title(),\n                label=self.label,","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/ptransform.py#L481-L517","documentation":"Beam's type-hint checking supports either positional arg hints or keyword hints, not both for inputs (keywords only allowed for outputs, used as tagged output types). Combining both without overriding the transform's _type_check_inputs/_type_check_outputs raises TypeCheckError.","triggerScenarios":"Decorating or calling with_type_hint on a PTransform with both *args hints and **kwargs hints on the input side (e.g. @with_input_types(a=int, **{'b': str}) style mixing).","commonSituations":"Misusing with_input_types decorator with both positional and keyword specs; custom PTransforms adding hints for inputs that use keyword syntax.","solutions":["Use only positional input type hints, or only keyword hints if the framework allows for your transform.","Override _type_check_inputs (or _type_check_outputs) in your PTransform subclass to implement custom checking.","Move complex hint logic into a custom typecheck override rather than mixing hint styles."],"exampleFix":"// before\nclass MyT(beam.PTransform):\n  ...\nMyT().with_type_input_types(int, **{'b': str})  # mixed\n// after\nclass MyT(beam.PTransform):\n  def _type_check_inputs(self, pvalueish, hints): ...\n  def _type_check_outputs(self, pvalueish, hints): ...","handlingStrategy":"type-guard","validationCode":"arg_hints, kwarg_hints = hints\nassert not (arg_hints and kwarg_hints), \"use positional OR keyword hints, not both\"","typeGuard":null,"tryCatchPattern":"try:\n  t.with_input_types(*args, **kwargs)\nexcept TypeCheckError:\n  t = MyTransform().with_input_types(*args)  # drop kwargs, override _type_check_inputs instead","preventionTips":["Stick to positional hints for inputs, keyword hints only for tagged outputs","Override _type_check_inputs for custom hint layouts"],"tags":["python","apache-beam","type-hints"],"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"}