onboarding: Use dictionary comprehension for dict initialization.

Initializing a dictionary from an iterable requires the each item to be
a tuple containg a key and a value. `mypy_django_plugin` cannot infer
the number of items in an queryset with annotated values, so we have to
explicitly unpack each row with a dictionary comprehension here.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li 2022-08-05 15:30:47 -04:00 committed by Tim Abbott
parent b908f0d204
commit 5ad515c560
1 changed files with 6 additions and 3 deletions

View File

@ -23,9 +23,12 @@ def missing_any_realm_internal_bots() -> bool:
bot["email_template"] % (settings.INTERNAL_BOT_DOMAIN,) bot["email_template"] % (settings.INTERNAL_BOT_DOMAIN,)
for bot in settings.REALM_INTERNAL_BOTS for bot in settings.REALM_INTERNAL_BOTS
] ]
bot_counts = dict( bot_counts = {
UserProfile.objects.filter(email__in=bot_emails).values_list("email").annotate(Count("id")) email: count
) for email, count in UserProfile.objects.filter(email__in=bot_emails)
.values_list("email")
.annotate(Count("id"))
}
realm_count = Realm.objects.count() realm_count = Realm.objects.count()
return any(bot_counts.get(email, 0) < realm_count for email in bot_emails) return any(bot_counts.get(email, 0) < realm_count for email in bot_emails)