Skip to content

Commit

Permalink
Make is_list typed
Browse files Browse the repository at this point in the history
  • Loading branch information
schrockn committed Jun 9, 2024
1 parent d7b5a78 commit d7d3123
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions python_modules/dagster-graphql/dagster_graphql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ def execute_query(
if "errors" in result_dict:
result_dict_errors = check.list_elem(result_dict, "errors", of_type=Exception)
result_errors = check.is_list(result.errors, of_type=Exception)
check.invariant(len(result_dict_errors) == len(result_errors)) #
check.invariant(len(result_dict_errors) == len(result_errors))
for python_error, error_dict in zip(result_errors, result_dict_errors):
if hasattr(python_error, "original_error") and python_error.original_error:
error_dict["stack_trace"] = get_stack_trace_array(python_error.original_error)
# Typing errors caught by making is_list typed -- schrockn 2024-06-09
if hasattr(python_error, "original_error") and python_error.original_error: # type: ignore
error_dict["stack_trace"] = get_stack_trace_array(python_error.original_error) # type: ignore

return result_dict

Expand Down
9 changes: 6 additions & 3 deletions python_modules/dagster/dagster/_check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,18 +878,21 @@ 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[TypeOrTupleOfTypes] = None,
of_type: Optional[TTypeOrTupleOfTTypes[T]] = None,
additional_message: Optional[str] = None,
) -> List:
) -> List[T]:
if not isinstance(obj, list):
raise _type_mismatch_error(obj, list, additional_message)

if not of_type:
return obj

return _check_iterable_items(obj, of_type, "list")
return list(_check_iterable_items(obj, of_type, "list"))


# ########################
Expand Down
3 changes: 2 additions & 1 deletion python_modules/dagster/dagster/_config/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def has_field(self, name: str) -> bool:
@property
def field_names(self) -> Sequence[str]:
fields = check.is_list(self.fields, of_type=ConfigFieldSnap)
return [fs.name for fs in fields]
# Typing error caught by making is_list typed -- schrockn 2024-06-09
return [fs.name for fs in fields] # type: ignore

def get_child_type_keys(self) -> Sequence[str]:
if ConfigTypeKind.is_closed_generic(self.kind):
Expand Down

0 comments on commit d7d3123

Please sign in to comment.