From 5d524aa43d5e89664a1bb9c6b59333f99d997e8f Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Thu, 23 Jun 2022 16:00:19 -0400 Subject: [PATCH] custom_profile_fields: Use cast to assert non-optional items. The mypy django-stubs plugin incorrectly infers optional value for order, which makes the `value_list` to be typed as `Iterable[Optional[int]]`. We use a type cast here to ensure that `try_reorder_relam_custom_profile_fields` won't causes mypy to complain about it. TODO: Remove the cast when https://github.com/typeddjango/django-stubs/issues/444 gets resovled. Signed-off-by: Zixuan James Li --- zerver/tests/test_custom_profile_data.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.py index 6932a0bc6b..52253b7d52 100644 --- a/zerver/tests/test_custom_profile_data.py +++ b/zerver/tests/test_custom_profile_data.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Union +from typing import Any, Dict, Iterable, List, Union, cast from unittest import mock import orjson @@ -743,7 +743,10 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase): .order_by("-order") .values_list("order", flat=True) ) - try_reorder_realm_custom_profile_fields(realm, order) + # Until https://github.com/typeddjango/django-stubs/issues/444 gets resolved, + # we need the cast here to ensure the value list is correctly typed. + assert all(isinstance(item, int) for item in order) + try_reorder_realm_custom_profile_fields(realm, cast(Iterable[int], order)) result = self.client_get("/json/realm/profile_fields") content = self.assert_json_success(result) self.assertListEqual(