typing: Do explicit type conversion when appropriate.

When calling some functions or assigning values to certain attributes,
the arguments/right operand do not match the exact type that the
functions/attributes expect, and thus we fix that by converting types
beforehand.
This commit is contained in:
PIG208 2021-07-26 22:46:53 +08:00 committed by Tim Abbott
parent cd678232bd
commit d2af20eb2a
5 changed files with 13 additions and 8 deletions

View File

@ -207,7 +207,11 @@ class TestGetChartData(ZulipTestCase):
client2 = Client.objects.create(name="client 2")
client3 = Client.objects.create(name="client 3")
client4 = Client.objects.create(name="client 4")
self.insert_data(stat, [client4.id, client3.id, client2.id], [client3.id, client1.id])
self.insert_data(
stat,
[str(client4.id), str(client3.id), str(client2.id)],
[str(client3.id), str(client1.id)],
)
result = self.client_get(
"/json/analytics/chart_data", {"chart_name": "messages_sent_by_client"}
)

View File

@ -110,7 +110,7 @@ def get_user_activity_summary(records: List[QuerySet]) -> Dict[str, Dict[str, An
for record in records:
client = record.client.name
query = record.query
query = str(record.query)
update("use", record)

View File

@ -3237,12 +3237,12 @@ class BillingHelpersTest(ZulipTestCase):
def test_get_realms_to_default_discount_dict(self) -> None:
Customer.objects.create(realm=get_realm("zulip"), stripe_customer_id="cus_1")
lear_customer = Customer.objects.create(realm=get_realm("lear"), stripe_customer_id="cus_2")
lear_customer.default_discount = 30
lear_customer.default_discount = Decimal(30)
lear_customer.save(update_fields=["default_discount"])
zephyr_customer = Customer.objects.create(
realm=get_realm("zephyr"), stripe_customer_id="cus_3"
)
zephyr_customer.default_discount = 0
zephyr_customer.default_discount = Decimal(0)
zephyr_customer.save(update_fields=["default_discount"])
self.assertEqual(

View File

@ -466,7 +466,7 @@ def process_new_human_user(
mit_beta_user = realm.is_zephyr_mirror_realm
if prereg_user is not None:
streams = prereg_user.streams.all()
streams: List[Stream] = list(prereg_user.streams.all())
acting_user: Optional[UserProfile] = prereg_user.referred_by
else:
streams = []

View File

@ -9,6 +9,7 @@ import bmemcached
import orjson
from django.conf import settings
from django.contrib.sessions.models import Session
from django.core.files.base import File
from django.core.management import call_command
from django.core.management.base import BaseCommand, CommandParser
from django.db import connection
@ -557,7 +558,7 @@ class Command(BaseCommand):
# across platforms.
subscriptions_list: List[Tuple[UserProfile, Recipient]] = []
profiles: Sequence[UserProfile] = (
profiles: Sequence[UserProfile] = list(
UserProfile.objects.select_related().filter(is_bot=False).order_by("email")
)
@ -716,7 +717,7 @@ class Command(BaseCommand):
# Create a test realm emoji.
IMAGE_FILE_PATH = static_path("images/test-images/checkbox.png")
with open(IMAGE_FILE_PATH, "rb") as fp:
check_add_realm_emoji(zulip_realm, "green_tick", iago, fp)
check_add_realm_emoji(zulip_realm, "green_tick", iago, File(fp))
if not options["test_suite"]:
# Populate users with some bar data
@ -1018,7 +1019,7 @@ def generate_and_send_messages(
elif message_type == Recipient.STREAM:
# Pick a random subscriber to the stream
message.sender = random.choice(
Subscription.objects.filter(recipient=message.recipient)
list(Subscription.objects.filter(recipient=message.recipient))
).user_profile
message.subject = random.choice(possible_topics[message.recipient.id])
saved_data["subject"] = message.subject