From ed157e4d17553813febcb91890bdf8fb279f0e2e Mon Sep 17 00:00:00 2001 From: Nick Schrock Date: Sun, 9 Jun 2024 20:52:17 -0400 Subject: [PATCH] add typing information to list_param variants --- .../dagster/dagster/_check/__init__.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/python_modules/dagster/dagster/_check/__init__.py b/python_modules/dagster/dagster/_check/__init__.py index 646d851879bfb..c272685ef8373 100644 --- a/python_modules/dagster/dagster/_check/__init__.py +++ b/python_modules/dagster/dagster/_check/__init__.py @@ -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: # @@ -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) @@ -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. @@ -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: ... @@ -788,7 +790,7 @@ 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]: ... @@ -796,9 +798,9 @@ def opt_nullable_list_param( 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 @@ -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,