From deed3d4b6954b9b59b89416fb3eb1008d950c962 Mon Sep 17 00:00:00 2001 From: Sandy Ryza Date: Thu, 15 Aug 2024 13:25:17 -0700 Subject: [PATCH] support Callable annotations on record fields (#23677) ## Summary & Motivation A further step would be to check the args passed to `Callable`, but I think this is a useful start on its own. ## How I Tested These Changes --- python_modules/dagster/dagster/_check/builder.py | 2 ++ .../dagster_tests/general_tests/check_tests/test_check.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/python_modules/dagster/dagster/_check/builder.py b/python_modules/dagster/dagster/_check/builder.py index 4d1a7fd553915..2eb188dce7cc2 100644 --- a/python_modules/dagster/dagster/_check/builder.py +++ b/python_modules/dagster/dagster/_check/builder.py @@ -288,6 +288,8 @@ def build_check_call_str( return name # no-op elif origin is Literal: return f'check.literal_param({name}, "{name}", {args})' + elif origin is Callable or origin is collections.abc.Callable: + return f'check.callable_param({name}, "{name}")' else: if _is_annotated(origin, args): _process_annotated(ttype, args, eval_ctx) diff --git a/python_modules/dagster/dagster_tests/general_tests/check_tests/test_check.py b/python_modules/dagster/dagster_tests/general_tests/check_tests/test_check.py index 8bd44ff6c8791..5efc3fa4388b9 100644 --- a/python_modules/dagster/dagster_tests/general_tests/check_tests/test_check.py +++ b/python_modules/dagster/dagster_tests/general_tests/check_tests/test_check.py @@ -7,6 +7,7 @@ TYPE_CHECKING, AbstractSet, Any, + Callable, Dict, Iterable, List, @@ -1650,6 +1651,8 @@ class Bar: ... (TypeVar("T"), [Foo(), None], []), (Literal["apple"], ["apple"], ["banana"]), (Literal["apple", "manzana"], ["apple", "manzana"], ["banana"]), + (Callable, [lambda x: x, int], [4]), + (Callable[[], int], [lambda x: x, int], [4]), # fwd refs ("Foo", [Foo()], [Bar()]), (Optional["Foo"], [Foo()], [Bar()]),