Mypy: Ensure consistency of QuerySet return types in models.py.

Other functions took the form of returning Sequence[T] when the QuerySet
functionality is unused beyond the function, with T being the objects
filtered for in the function body; this commit follows that practice for the
one remaining python2 comment-annotated function, completing the transition
of models.py to py3.5 function annotations.

A note is also added to another function regarding a need to return a
QuerySet, and ideally a QuerySet[T] in line with the other functions, as and
when QuerySet becomes annotated as a generic.
This commit is contained in:
neiljp (Neil Pilgrim)
2018-03-14 23:02:39 +00:00
committed by Tim Abbott
parent a4a8527ec5
commit ce4ac0d2cf
2 changed files with 3 additions and 3 deletions

View File

@@ -480,7 +480,6 @@ def build_custom_checkers(by_lang):
'zerver/lib/cache.py', 'zerver/lib/cache.py',
'zerver/lib/request.py', 'zerver/lib/request.py',
'zerver/lib/stream_subscription.py', 'zerver/lib/stream_subscription.py',
'zerver/models.py',
'zerver/tornado/descriptors.py', 'zerver/tornado/descriptors.py',
'zerver/views/streams.py', 'zerver/views/streams.py',
# thumbor is (currently) python2 only # thumbor is (currently) python2 only

View File

@@ -1036,6 +1036,8 @@ def stream_name_in_use(stream_name: Text, realm_id: int) -> bool:
).exists() ).exists()
def get_active_streams(realm: Optional[Realm]) -> QuerySet: def get_active_streams(realm: Optional[Realm]) -> QuerySet:
# TODO: Change return type to QuerySet[Stream]
# NOTE: Return value is used as a QuerySet, so cannot currently be Sequence[QuerySet]
""" """
Return all streams (including invite-only streams) that have not been deactivated. Return all streams (including invite-only streams) that have not been deactivated.
""" """
@@ -1249,8 +1251,7 @@ def pre_save_message(sender: Any, **kwargs: Any) -> None:
message = kwargs['instance'] message = kwargs['instance']
message.update_calculated_fields() message.update_calculated_fields()
def get_context_for_message(message): def get_context_for_message(message: Message) -> Sequence[Message]:
# type: (Message) -> QuerySet[Message]
# TODO: Change return type to QuerySet[Message] # TODO: Change return type to QuerySet[Message]
return Message.objects.filter( return Message.objects.filter(
recipient_id=message.recipient_id, recipient_id=message.recipient_id,