Skip to content

Commit

Permalink
support Callable annotations on record fields (#23677)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
sryza authored Aug 15, 2024
1 parent b6f91e1 commit deed3d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python_modules/dagster/dagster/_check/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
TYPE_CHECKING,
AbstractSet,
Any,
Callable,
Dict,
Iterable,
List,
Expand Down Expand Up @@ -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()]),
Expand Down

0 comments on commit deed3d4

Please sign in to comment.