{"record":{"id":"426553d0bba12dee","repo":"apache/beam","slug":"use-s-not-s","errorCode":null,"errorMessage":"Use %s() not %s.","messagePattern":"Use (.+?)\\(\\) not (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/ptransform.py","lineNumber":881,"sourceCode":"\n\nclass PTransformWithSideInputs(PTransform):\n  \"\"\"A superclass for any :class:`PTransform` (e.g.\n  :func:`~apache_beam.transforms.core.FlatMap` or\n  :class:`~apache_beam.transforms.core.CombineFn`)\n  invoking user code.\n\n  :class:`PTransform` s like :func:`~apache_beam.transforms.core.FlatMap`\n  invoke user-supplied code in some kind of package (e.g. a\n  :class:`~apache_beam.transforms.core.DoFn`) and optionally provide arguments\n  and side inputs to that code. This internal-use-only class contains common\n  functionality for :class:`PTransform` s that fit this model.\n  \"\"\"\n  def __init__(self, fn, *args, **kwargs):\n    # type: (WithTypeHints, *Any, **Any) -> None\n    if isinstance(fn, type) and issubclass(fn, WithTypeHints):\n      # Don't treat Fn class objects as callables.\n      raise ValueError('Use %s() not %s.' % (fn.__name__, fn.__name__))\n    self.fn = self.make_fn(fn, bool(args or kwargs))\n    # Now that we figure out the label, initialize the super-class.\n    super().__init__()\n\n    if (any(isinstance(v, pvalue.PCollection) for v in args) or\n        any(isinstance(v, pvalue.PCollection) for v in kwargs.values())):\n      raise error.SideInputError(\n          'PCollection used directly as side input argument. Specify '\n          'AsIter(pcollection) or AsSingleton(pcollection) to indicate how the '\n          'PCollection is to be used.')\n    self.args, self.kwargs, self.side_inputs = util.remove_objects_from_args(\n        args, kwargs, pvalue.AsSideInput)\n    self.raw_side_inputs = args, kwargs\n\n    # Prevent name collisions with fns of the form '<function <lambda> at ...>'\n    self._cached_fn = self.fn\n\n    # Ensure fn and side inputs are picklable for remote execution.","sourceCodeStart":863,"sourceCodeEnd":899,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/ptransform.py#L863-L899","documentation":"Beam's PTransform.__init__ rejects a PTransform class object passed instead of an instance. Class objects are deliberately not treated as callables, so passing e.g. Map instead of Map() raises ValueError immediately. The intent is that transforms must be instantiated before being applied to a pipeline.","triggerScenarios":"Constructing a PTransform subclass instance whose `fn` argument is itself a PTransform class (not an instance), e.g. `p | Map` or `ParDo(MapFn)` where MapFn is a class object and the outer transform wraps classes via `fn.__name__`.","commonSituations":"Forgetting parentheses on a transform (`beam.Map` instead of `beam.Map(lambda x: x)`); passing a DoFn class to a wrapper expecting an instance; older tutorials or snippets using class-passing style that Beam no longer accepts.","solutions":["Add parentheses and required arguments: use `beam.Map(...)` with a callable or an already-instantiated DoFn instead of the bare class.","If you meant to pass a DoFn class to ParDo, instantiate it first: `beam.ParDo(MyDoFn(args))`.","Check the exact failing expression in the traceback; the class name in the message is the object you passed without constructing it."],"exampleFix":"// before\nresult = beam.Map\n// after\nresult = beam.Map(lambda x: x * 2)","handlingStrategy":"validation","validationCode":"def ensure_transform_instance(t):\n  import inspect\n  if inspect.isclass(t):\n    raise TypeError(f'Pass an instance: {t.__name__}(...), not the class')\n  return t","typeGuard":"def is_ptransform_instance(t):\n  from apache_beam.transforms.ptransform import PTransform\n  return isinstance(t, PTransform) and not isinstance(t, type)","tryCatchPattern":null,"preventionTips":["Always instantiate transforms: `beam.Map(...)`, `beam.ParDo(MyDoFn())`.","Lint for bare beam transform classes followed by `|`.","When writing wrapper transforms, document that `fn` must be a callable or instance, not a class."],"tags":["python","apache-beam","transform-usage"],"backgroundTag":"invalid-constructor-argument","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"}