mirror of https://github.com/zulip/zulip.git
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:
parent
13f62da4ce
commit
aceee3da11
|
@ -17,7 +17,7 @@ import logging
|
||||||
# http://blog.domaintools.com/2013/04/rate-limiting-with-redis/
|
# http://blog.domaintools.com/2013/04/rate-limiting-with-redis/
|
||||||
|
|
||||||
client = get_redis_client()
|
client = get_redis_client()
|
||||||
rules = settings.RATE_LIMITING_RULES
|
rules = settings.RATE_LIMITING_RULES # type: List[Tuple[int, int]]
|
||||||
def _rules_for_user(user):
|
def _rules_for_user(user):
|
||||||
# type: (UserProfile) -> List[Tuple[int, int]]
|
# type: (UserProfile) -> List[Tuple[int, int]]
|
||||||
if user.rate_limits != "":
|
if user.rate_limits != "":
|
||||||
|
@ -49,7 +49,7 @@ def add_ratelimit_rule(range_seconds, num_requests):
|
||||||
global rules
|
global rules
|
||||||
|
|
||||||
rules.append((range_seconds, num_requests))
|
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):
|
def remove_ratelimit_rule(range_seconds, num_requests):
|
||||||
# type: (int , int) -> None
|
# type: (int , int) -> None
|
||||||
|
|
Loading…
Reference in New Issue