{"record":{"id":"ebbcba08718a7900","repo":"pathwaycom/pathway","slug":"you-cannot-instantiate-this-class","errorCode":null,"errorMessage":"You cannot instantiate `this` class.","messagePattern":"You cannot instantiate `this` class\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/thisclass.py","lineNumber":119,"sourceCode":"\n    @trace_user_frame\n    def __iter__(self):\n        class subclass(self, iter_guard):  # type: ignore[valid-type,misc]\n            @classmethod\n            def __iter__(self):\n                raise TypeError(\"You cannot iterate over mock class.\")\n\n        subclass.__qualname__ = self.__qualname__ + \".\" + \"__iter__\" + \"(...)\"\n        subclass.__name__ = \"__iter__\"\n        return iter([subclass])\n\n    def keys(self):\n        # _key_guard_counter is necessary, otherwise key-collisions happen\n        return [f\"{KEY_GUARD}_{next(_key_guard_counter)}\"]\n\n    @trace_user_frame\n    def __call__(self):\n        raise TypeError(\"You cannot instantiate `this` class.\")\n\n    def pointer_from(\n        self, *args: Any, optional=False, instance: expr.ColumnReference | None = None\n    ):\n        return expr.PointerExpression(self, *args, optional=optional, instance=instance)  # type: ignore[arg-type]\n\n    def _base_this(self) -> ThisMetaclass:\n        raise NotImplementedError\n\n    def _eval_table(self, table: Joinable) -> Joinable:\n        raise NotImplementedError\n\n    def _eval_substitution(\n        self, substitution: dict[ThisMetaclass, Joinable]\n    ) -> Joinable:\n        base_this: ThisMetaclass = self._base_this()\n        if base_this not in substitution:\n            raise TypeError(f\"Usage of {base_this} not supported here.\")","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/thisclass.py#L101-L137","documentation":"Pathway's global this object is a singleton proxy used to build column references; it is not a class you can instantiate. __call__ is explicitly blocked with a TypeError so mistakes like pw.this() fail fast instead of producing a broken object.","triggerScenarios":"Writing pw.this() (usually a typo when intending pw.this.col or a schema class); attempting PathwayThis(); passing this to APIs that call their argument, e.g. map(this) or functools.partial patterns.","commonSituations":"Confusion between this and schema classes (users coming from pandas/ORM APIs who reflexively call constructors); copy-paste from code that instantiates custom Schema classes next to this usage.","solutions":["Remove the call: use pw.this.column_name or pw.this['column_name'] directly","If you meant to define a schema, declare a class inheriting pw.Schema and instantiate that instead","If a callable is required by an API, wrap it: lambda: pw.this.x"],"exampleFix":"# before\nvalue = pw.this().amount  # TypeError: cannot instantiate `this`\n\n# after\nvalue = pw.this.amount","handlingStrategy":"type-guard","validationCode":"import pathway as pw\n\n# pw.this must never be called; guard callables at the boundary\ndef ensure_not_this(obj):\n    assert obj is not pw.this, \"pw.this is not callable/instantiable\"","typeGuard":"def is_pathway_this(obj) -> bool:\n    import pathway as pw\n    return obj is pw.this","tryCatchPattern":"try:\n    value = pw.this()\nexcept TypeError as e:\n    if \"instantiate\" in str(e):\n        value = pw.this  # use the proxy itself\n    else:\n        raise","preventionTips":["Write pw.this.column without parentheses","Keep Schema classes and pw.this visually distinct in code review","Lint for the literal pattern 'pw.this(' in CI"],"tags":["pathway","this","instantiation","typeerror"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}