Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add types to synapse.util. #10601

Merged
merged 41 commits into from
Sep 10, 2021
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ff8f94d
fairly mechanical changes
reivilibre Aug 13, 2021
6deee28
stranger changes (REVIEW)
reivilibre Aug 13, 2021
3c2b4dd
Newsfile & mypy.ini
reivilibre Aug 13, 2021
1d0b435
Put the switch back in to the 'more magic' position
reivilibre Aug 16, 2021
22df193
Fix up some more types
reivilibre Aug 16, 2021
e36db3f
Update annotations in util
reivilibre Aug 18, 2021
db57064
Fix fallout (related annotations and assertions around codebase)
reivilibre Aug 18, 2021
cd15b4b
Merge remote-tracking branch 'origin/develop' into rei/types1
reivilibre Aug 18, 2021
348f9ff
antilint
reivilibre Aug 18, 2021
d081c83
add type parameters for Deferreds
reivilibre Aug 18, 2021
76c3b6b
Fix circular import of HomeServer
reivilibre Aug 23, 2021
30ffee4
Quote deferreds in method signatures
reivilibre Aug 23, 2021
10bd84f
Annotate more types
reivilibre Sep 1, 2021
0c26b7f
Use attrs class and fix ignored fields [WANTS REVIEW]
reivilibre Sep 1, 2021
715bfdc
Ignore import issues [WANTS REVIEW]
reivilibre Sep 1, 2021
1e4632f
Annotate more types
reivilibre Sep 1, 2021
05cc10c
Annotate more types
reivilibre Sep 2, 2021
1c6704c
Annotate types and ignore Twisted issues [WANTS REVIEW]
reivilibre Sep 2, 2021
c384373
Add IReactorThreads as parent of ISynapseReactor
reivilibre Sep 2, 2021
884a8b6
Annotate more types
reivilibre Sep 2, 2021
a22f4c0
Add type annotation fixes to fix CI
reivilibre Sep 2, 2021
029bf34
Merge remote-tracking branch 'origin/develop' into rei/types1
reivilibre Sep 2, 2021
9444ca1
Resolve type issue that arose from merge
reivilibre Sep 2, 2021
a0aef0b
Back out of generics due to python-attrs/attrs#313
reivilibre Sep 2, 2021
289df40
Quote return types with Deferreds
reivilibre Sep 3, 2021
8e719ed
Fix use of None as default
reivilibre Sep 6, 2021
34e327d
Use a cast to work around Mocks not working with isinstance
reivilibre Sep 6, 2021
cd9a68d
Fix up parameters which were previously silently ignored
reivilibre Sep 6, 2021
b4cded1
Apply suggestions
reivilibre Sep 8, 2021
6f7fac0
Use `cast` to IReactorTime [WANTS REVIEW]
reivilibre Sep 8, 2021
d4afbca
Add types and casts to `__exit__` [REVIEW]
reivilibre Sep 8, 2021
f5cee54
Fix adherence to Jinja2's interface [REVIEW]
reivilibre Sep 8, 2021
12cfb9a
Annotate `WheelTimer`, notably `bucket_size`
reivilibre Sep 8, 2021
e69a3d6
Update Newsfile
reivilibre Sep 8, 2021
9f301ae
Note that code was lifted from CPython
reivilibre Sep 8, 2021
e6618d7
Add more type annotations
reivilibre Sep 8, 2021
b1b4f1b
Enable stricter checking on applicable modules
reivilibre Sep 8, 2021
ea4f7e0
Merge remote-tracking branch 'origin/develop' into rei/types1
reivilibre Sep 8, 2021
8871674
Correct types used in `__exit__`
reivilibre Sep 8, 2021
20d63a0
Fix up manhole types after merge [REVIEW, SEE DESC]
reivilibre Sep 8, 2021
19a602e
Avoid using evil typecasts
reivilibre Sep 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions synapse/util/retryutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import logging
import random
from types import TracebackType
from typing import Any, Optional
from typing import Any, Optional, Type, TypeVar, cast

import synapse.logging.context
from synapse.api.errors import CodeMessageException
Expand All @@ -33,6 +33,9 @@
MAX_RETRY_INTERVAL = 2 ** 62


T = TypeVar("T")


class NotRetryingDestination(Exception):
def __init__(self, retry_last_ts: int, retry_interval: int, destination: str):
"""Raised by the limiter (and federation client) to indicate that we are
Expand Down Expand Up @@ -163,7 +166,9 @@ def __init__(
def __enter__(self) -> None:
pass

def __exit__(self, exc_type, exc_val, exc_tb: TracebackType) -> None:
def __exit__(
self, exc_type: Optional[Type[T]], exc_val: T, exc_tb: TracebackType
) -> None:
valid_err_code = False
if exc_type is None:
valid_err_code = True
Expand All @@ -172,6 +177,7 @@ def __exit__(self, exc_type, exc_val, exc_tb: TracebackType) -> None:
# failures; this is mostly so as not to catch defer._DefGen.
valid_err_code = True
elif issubclass(exc_type, CodeMessageException):
exc_val_cme = cast(CodeMessageException, exc_val)
reivilibre marked this conversation as resolved.
Show resolved Hide resolved
# Some error codes are perfectly fine for some APIs, whereas other
# APIs may expect to never received e.g. a 404. It's important to
# handle 404 as some remote servers will return a 404 when the HS
Expand All @@ -180,11 +186,11 @@ def __exit__(self, exc_type, exc_val, exc_tb: TracebackType) -> None:
# won't accept our requests for at least a while.
# 429 is us being aggressively rate limited, so lets rate limit
# ourselves.
if exc_val.code == 404 and self.backoff_on_404:
if exc_val_cme.code == 404 and self.backoff_on_404:
valid_err_code = False
elif exc_val.code in (401, 429):
elif exc_val_cme.code in (401, 429):
valid_err_code = False
elif exc_val.code < 500:
elif exc_val_cme.code < 500:
valid_err_code = True
else:
valid_err_code = False
Expand Down