From 1f40e26efdb2b011ff1490ead6d90933a709f9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Uzna=C5=84ski?= Date: Thu, 8 Feb 2024 11:59:25 +0100 Subject: [PATCH] not calling schemas (#5641) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * not calling schemas * Update public/pathway/python/pathway/internals/schema.py Co-authored-by: Michał Bartoszkiewicz * import --------- Co-authored-by: Michał Bartoszkiewicz GitOrigin-RevId: 48b344f718a691fcb23fe0fd3a237e361e69131a --- python/pathway/internals/schema.py | 7 ++++++- python/pathway/tests/test_schema.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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)()