mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 17:36:27 +00:00
Add type annotation to mention.py, redis_utils.py, timestamp.py, user_agent.py
Some functions in models.py had input typed as int when they needed to be typed as datetime.datetime
This commit is contained in:
@@ -7,4 +7,5 @@ find_mentions = r'(?<![^\s\'\"\(,:<])@(?:\*\*([^\*]+)\*\*|(\w+))'
|
||||
wildcards = ['all', 'everyone']
|
||||
|
||||
def user_mention_matches_wildcard(mention):
|
||||
# type: (str) -> bool
|
||||
return mention in wildcards
|
||||
|
||||
@@ -5,4 +5,5 @@ from django.conf import settings
|
||||
import redis
|
||||
|
||||
def get_redis_client():
|
||||
# type: () -> redis.StrictRedis
|
||||
return redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0)
|
||||
|
||||
@@ -5,7 +5,9 @@ import calendar
|
||||
from django.utils.timezone import utc
|
||||
|
||||
def timestamp_to_datetime(timestamp):
|
||||
# type: (float) -> datetime.datetime
|
||||
return datetime.datetime.utcfromtimestamp(float(timestamp)).replace(tzinfo=utc)
|
||||
|
||||
def datetime_to_timestamp(datetime_object):
|
||||
# type: (datetime.datetime) -> int
|
||||
return calendar.timegm(datetime_object.timetuple())
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import re
|
||||
from typing import Optional, Dict
|
||||
|
||||
# Warning: If you change this parsing, please test using
|
||||
# tools/test_user_agent_parsing.py
|
||||
# And extend tools/user_agents_unique with any new test cases
|
||||
def parse_user_agent(user_agent):
|
||||
# type: (str) -> Optional[Dict[str, str]]
|
||||
match = re.match("^(?P<name>[^/ ]*[^0-9/(]*)(/(?P<version>[^/ ]*))?([ /].*)?$", user_agent)
|
||||
if match is None:
|
||||
return None
|
||||
|
||||
@@ -923,7 +923,7 @@ class Message(models.Model):
|
||||
recipient_type,
|
||||
recipient_type_id,
|
||||
):
|
||||
# type: (bool, Message, int, int, str, str, str, int, str, int, int, str, str, str, str, str, bool, str, int, int, int) -> Dict[str, Any]
|
||||
# type: (bool, Message, int, datetime.datetime, str, str, str, datetime.datetime, str, int, int, str, str, str, str, str, bool, str, int, int, int) -> Dict[str, Any]
|
||||
global bugdown
|
||||
if bugdown is None:
|
||||
from zerver.lib import bugdown
|
||||
@@ -1395,7 +1395,7 @@ class UserPresence(models.Model):
|
||||
@staticmethod
|
||||
def to_presence_dict(client_name=None, status=None, dt=None, push_enabled=None,
|
||||
has_push_devices=None, is_mirror_dummy=None):
|
||||
# type: (Optional[str], Optional[int], Optional[int], Optional[bool], Optional[bool], Optional[bool]) -> Dict[str, Any]
|
||||
# type: (Optional[str], Optional[int], Optional[datetime.datetime], Optional[bool], Optional[bool], Optional[bool]) -> Dict[str, Any]
|
||||
presence_val = UserPresence.status_to_string(status)
|
||||
|
||||
timestamp = datetime_to_timestamp(dt)
|
||||
|
||||
Reference in New Issue
Block a user