diff --git a/python/pathway/internals/schema.py b/python/pathway/internals/schema.py index 069d07fb..60a25b05 100644 --- a/python/pathway/internals/schema.py +++ b/python/pathway/internals/schema.py @@ -11,7 +11,7 @@ from os import PathLike from pydoc import locate from types import MappingProxyType -from typing import TYPE_CHECKING, Any, get_type_hints +from typing import TYPE_CHECKING, Any, NoReturn, get_type_hints from warnings import warn import numpy as np @@ -270,6 +270,11 @@ def __init__(self, *args, append_only: bool | None = None, **kwargs) -> None: } self.__types__ = {k: v.typehint for k, v in self.__dtypes__.items()} + def __call__(self) -> NoReturn: + raise TypeError( + "Schemas should not be called. Use `table.schema` not `table.schema()." + ) + def __or__(self, other: type[Schema]) -> type[Schema]: # type: ignore return schema_add(self, other) # type: ignore diff --git a/python/pathway/tests/test_schema.py b/python/pathway/tests/test_schema.py index 0d947992..da0d9188 100644 --- a/python/pathway/tests/test_schema.py +++ b/python/pathway/tests/test_schema.py @@ -338,3 +338,13 @@ class D(pw.Schema, append_only=True): pass assert D.universe_properties.append_only is True + + +def test_schemas_not_to_be_called(): + with pytest.raises(TypeError): + pw.Table.empty().schema() + + +def test_advanced_schemas_not_to_be_called(): + with pytest.raises(TypeError): + (pw.Table.empty().schema | pw.Table.empty().schema)()