zerver/lib/rate_limiter.py: Annotate rate_limiter.rules.

After annotating rate_limiter.rules, mypy complained that rules does
not support cmp.  So use key to customize sort instead of cmp.
Python docs also recommend using key over cmp.
This commit is contained in:
Eklavya Sharma 2016-06-17 21:20:52 +05:30 committed by Tim Abbott
parent 13f62da4ce
commit aceee3da11
1 changed files with 2 additions and 2 deletions

View File

@ -17,7 +17,7 @@ import logging
# http://blog.domaintools.com/2013/04/rate-limiting-with-redis/
client = get_redis_client()
rules = settings.RATE_LIMITING_RULES
rules = settings.RATE_LIMITING_RULES # type: List[Tuple[int, int]]
def _rules_for_user(user):
# type: (UserProfile) -> List[Tuple[int, int]]
if user.rate_limits != "":
@ -49,7 +49,7 @@ def add_ratelimit_rule(range_seconds, num_requests):
global rules
rules.append((range_seconds, num_requests))
rules.sort(cmp=lambda x, y: x[0] < y[0])
rules.sort(key=lambda x: x[0])
def remove_ratelimit_rule(range_seconds, num_requests):
# type: (int , int) -> None