Type hints for the remaining two files in synapse.http. (#11164)

* Teach MyPy that the sentinel context is False

This means that if `ctx: LoggingContextOrSentinel`
then `bool(ctx)` narrows us to `ctx:LoggingContext`, which is a really
neat find!

* Annotate RequestMetrics

- Raise errors for sentry if we use the sentinel context
- Ensure we don't raise an error and carry on, but not recording stats
- Include stack trace in the error case to lower Sean's blood pressure

* Make mypy pass for synapse.http.request_metrics

* Make synapse.http.connectproxyclient pass mypy

Co-authored-by: reivilibre <oliverw@matrix.org>
This commit is contained in:
David Robertson 2021-10-28 14:14:42 +01:00 committed by GitHub
parent a19bf32a03
commit 1bfd141205
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 37 deletions

View file

@ -220,7 +220,7 @@ class _Sentinel:
self.scope = None
self.tag = None
def __str__(self):
def __str__(self) -> str:
return "sentinel"
def copy_to(self, record):
@ -241,7 +241,7 @@ class _Sentinel:
def record_event_fetch(self, event_count):
pass
def __bool__(self):
def __bool__(self) -> Literal[False]:
return False