pathwaycom/pathway · error · TypeError
You cannot instantiate `this` class.
Error message
You cannot instantiate `this` class.
What it means
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.
Source
Thrown at python/pathway/internals/thisclass.py:119
@trace_user_frame
def __iter__(self):
class subclass(self, iter_guard): # type: ignore[valid-type,misc]
@classmethod
def __iter__(self):
raise TypeError("You cannot iterate over mock class.")
subclass.__qualname__ = self.__qualname__ + "." + "__iter__" + "(...)"
subclass.__name__ = "__iter__"
return iter([subclass])
def keys(self):
# _key_guard_counter is necessary, otherwise key-collisions happen
return [f"{KEY_GUARD}_{next(_key_guard_counter)}"]
@trace_user_frame
def __call__(self):
raise TypeError("You cannot instantiate `this` class.")
def pointer_from(
self, *args: Any, optional=False, instance: expr.ColumnReference | None = None
):
return expr.PointerExpression(self, *args, optional=optional, instance=instance) # type: ignore[arg-type]
def _base_this(self) -> ThisMetaclass:
raise NotImplementedError
def _eval_table(self, table: Joinable) -> Joinable:
raise NotImplementedError
def _eval_substitution(
self, substitution: dict[ThisMetaclass, Joinable]
) -> Joinable:
base_this: ThisMetaclass = self._base_this()
if base_this not in substitution:
raise TypeError(f"Usage of {base_this} not supported here.")View on GitHub (pinned to fa2f74a464)
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
Example fix
# before value = pw.this().amount # TypeError: cannot instantiate `this` # after value = pw.this.amount
Defensive patterns
Strategy: type-guard
Validate before calling
import pathway as pw
# pw.this must never be called; guard callables at the boundary
def ensure_not_this(obj):
assert obj is not pw.this, "pw.this is not callable/instantiable" Type guard
def is_pathway_this(obj) -> bool:
import pathway as pw
return obj is pw.this Try / catch
try:
value = pw.this()
except TypeError as e:
if "instantiate" in str(e):
value = pw.this # use the proxy itself
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- You cannot iterate over mock class.
- Usage of {base_this} not supported here.
- TableSlice expects {repr(arg.name)} or this.{arg.name} argum
- {name} is a method name. It is discouraged to use it as a co
- Pathway does not support using unary operator {operator_fun.
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/ebbcba08718a7900.
Report an issue: GitHub.