Skip to content

Commit

Permalink
add typing information to list_param variants
Browse files Browse the repository at this point in the history
  • Loading branch information
schrockn committed Jun 10, 2024
1 parent 0ef3766 commit ed157e4
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 ed157e4

Please sign in to comment.