summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-05-22 10:12:17 +0100
committerGitHub <noreply@github.com>2020-05-22 10:12:17 +0100
commitd84bdfe599aa47617d59c8e6eea5071463382c1c (patch)
tree6ee150055a285139e9d862e405bec14dcf0d3791
parentFix some DETECTED VIOLATIONS in the config file (#7550) (diff)
downloadsynapse-d84bdfe599aa47617d59c8e6eea5071463382c1c.tar.xz
mypy for synapse.http.site (#7553)
-rw-r--r--changelog.d/7553.misc1
-rw-r--r--synapse/http/site.py9
-rw-r--r--tox.ini1
3 files changed, 8 insertions, 3 deletions
diff --git a/changelog.d/7553.misc b/changelog.d/7553.misc
new file mode 100644
index 0000000000..90b9e8693a
--- /dev/null
+++ b/changelog.d/7553.misc
@@ -0,0 +1 @@
+Include `synapse.http.site` in type checking.
diff --git a/synapse/http/site.py b/synapse/http/site.py
index 514f2f1402..167293c46d 100644
--- a/synapse/http/site.py
+++ b/synapse/http/site.py
@@ -14,6 +14,7 @@
 import contextlib
 import logging
 import time
+from typing import Optional
 
 from twisted.python.failure import Failure
 from twisted.web.server import Request, Site
@@ -45,7 +46,7 @@ class SynapseRequest(Request):
     request even after the client has disconnected.
 
     Attributes:
-        logcontext(LoggingContext) : the log context for this request
+        logcontext: the log context for this request
     """
 
     def __init__(self, channel, *args, **kw):
@@ -53,10 +54,10 @@ class SynapseRequest(Request):
         self.site = channel.site
         self._channel = channel  # this is used by the tests
         self.authenticated_entity = None
-        self.start_time = 0
+        self.start_time = 0.0
 
         # we can't yet create the logcontext, as we don't know the method.
-        self.logcontext = None
+        self.logcontext = None  # type: Optional[LoggingContext]
 
         global _next_request_seq
         self.request_seq = _next_request_seq
@@ -182,6 +183,7 @@ class SynapseRequest(Request):
         self.finish_time = time.time()
         Request.finish(self)
         if not self._is_processing:
+            assert self.logcontext is not None
             with PreserveLoggingContext(self.logcontext):
                 self._finished_processing()
 
@@ -249,6 +251,7 @@ class SynapseRequest(Request):
     def _finished_processing(self):
         """Log the completion of this request and update the metrics
         """
+        assert self.logcontext is not None
         usage = self.logcontext.get_resource_usage()
 
         if self._processing_finished_time is None:
diff --git a/tox.ini b/tox.ini
index 3bb4d45e2a..9fefcb72b5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -193,6 +193,7 @@ commands = mypy \
             synapse/handlers/saml_handler.py \
             synapse/handlers/sync.py \
             synapse/handlers/ui_auth \
+            synapse/http/site.py \
             synapse/logging/ \
             synapse/metrics \
             synapse/module_api \