Skip to content

Commit

Permalink
add typing information to list_param variants (#22412)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Let's flow type information in `list_param` and friends

## How I Tested These Changes

Before:

![Screenshot 2024-06-09 at 8.49.23 PM.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/wS38mdcdU6aAeJobBdry/20c23ce1-3494-4672-8be8-21b744d5c64f.png)

![Screenshot 2024-06-09 at 8.51.31 PM.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/wS38mdcdU6aAeJobBdry/6e9927c1-86d4-4262-ad55-104be806b8f8.png)
  • Loading branch information
schrockn authored Jun 12, 2024
1 parent 5e22b73 commit 1c7ba44
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions python_modules/dagster/dagster/_check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
U = TypeVar("U")
V = TypeVar("V")

TTypeOrTupleOfTTypes = Union[Type[T], Tuple[Type[T], ...]]

# This module contains runtime type-checking code used throughout Dagster. It is divided into three
# sections:
#
Expand Down Expand Up @@ -740,9 +742,9 @@ def iterator_param(
def list_param(
obj: object,
param_name: str,
of_type: Optional[TypeOrTupleOfTypes] = None,
of_type: Optional[TTypeOrTupleOfTTypes[T]] = None,
additional_message: Optional[str] = None,
) -> List[Any]:
) -> List[T]:
if not isinstance(obj, list):
raise _param_type_mismatch_exception(obj, list, param_name, additional_message)

Expand All @@ -755,9 +757,9 @@ def list_param(
def opt_list_param(
obj: object,
param_name: str,
of_type: Optional[TypeOrTupleOfTypes] = None,
of_type: Optional[TTypeOrTupleOfTTypes[T]] = None,
additional_message: Optional[str] = None,
) -> List[Any]:
) -> List[T]:
"""Ensures argument obj is a list or None; in the latter case, instantiates an empty list
and returns it.
Expand All @@ -779,7 +781,7 @@ def opt_list_param(
def opt_nullable_list_param(
obj: None,
param_name: str,
of_type: Optional[TypeOrTupleOfTypes] = ...,
of_type: Optional[TTypeOrTupleOfTTypes[T]] = ...,
additional_message: Optional[str] = None,
) -> None: ...

Expand All @@ -788,17 +790,17 @@ def opt_nullable_list_param(
def opt_nullable_list_param(
obj: List[T],
param_name: str,
of_type: Optional[TypeOrTupleOfTypes] = ...,
of_type: Optional[TTypeOrTupleOfTTypes[T]] = ...,
additional_message: Optional[str] = None,
) -> List[T]: ...


def opt_nullable_list_param(
obj: object,
param_name: str,
of_type: Optional[TypeOrTupleOfTypes] = None,
of_type: Optional[TTypeOrTupleOfTTypes[T]] = None,
additional_message: Optional[str] = None,
) -> Optional[List]:
) -> Optional[List[T]]:
"""Ensures argument obj is a list or None. Returns None if input is None.
If the of_type argument is provided, also ensures that list items conform to the type specified
Expand Down Expand Up @@ -878,9 +880,6 @@ def opt_list_elem(
return _check_iterable_items(value, of_type, "list")


TTypeOrTupleOfTTypes = Union[Type[T], Tuple[Type[T], ...]]


def is_list(
obj: object,
of_type: Optional[TTypeOrTupleOfTTypes[T]] = None,
Expand Down

0 comments on commit 1c7ba44

Please sign in to comment.