]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
web,util: Work around "initialize incompatible with superclass" errors
authorBen Darnell <ben@bendarnell.com>
Sun, 7 Oct 2018 04:19:52 +0000 (00:19 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 7 Oct 2018 04:19:52 +0000 (00:19 -0400)
There are still a few more of these, but they're internal-only.

tornado/httpserver.py
tornado/netutil.py
tornado/util.py
tornado/web.py

index 0552ec91b5271e7ed31abb19507da42b5c79a851..78945c10a32649b3e976060a408ff4a4d5a54671 100644 (file)
@@ -161,7 +161,7 @@ class HTTPServer(TCPServer, Configurable, httputil.HTTPServerConnectionDelegate)
         # completely)
         pass
 
-    def initialize(  # type: ignore
+    def initialize(
         self,
         request_callback: Union[
             httputil.HTTPServerConnectionDelegate,
index 5a92690fa9e8618d4c5d2a51c876c3416a718193..7c07c48ff61e89c3d3ad199c9992c5f4f1263c71 100644 (file)
@@ -525,7 +525,7 @@ class OverrideResolver(Resolver):
        Added support for host-port-family triplets.
     """
 
-    def initialize(self, resolver: Resolver, mapping: dict) -> None:  # type: ignore
+    def initialize(self, resolver: Resolver, mapping: dict) -> None:
         self.resolver = resolver
         self.mapping = mapping
 
index 4d0d656a3bc25c875993ef3d4244faa6d0d0bf96..c4c019961ac2eeeb53e056185af7321698c9d85c 100644 (file)
@@ -302,18 +302,17 @@ class Configurable(object):
         """Returns the implementation class to be used if none is configured."""
         raise NotImplementedError()
 
-    def initialize(self) -> None:
-        """Initialize a `Configurable` subclass instance.
+    def _initialize(self) -> None:
+        pass
 
-        Configurable classes should use `initialize` instead of ``__init__``.
+    initialize = _initialize  # type: Callable[..., None]
+    """Initialize a `Configurable` subclass instance.
 
-        When used with ``mypy``, subclasses will often need ``# type: ignore``
-        annotations on this method because ``mypy`` does not recognize that
-        its arguments may change in subclasses (as it does for ``__init__``).
+    Configurable classes should use `initialize` instead of ``__init__``.
 
-        .. versionchanged:: 4.2
-           Now accepts positional arguments in addition to keyword arguments.
-        """
+    .. versionchanged:: 4.2
+       Now accepts positional arguments in addition to keyword arguments.
+    """
 
     @classmethod
     def configure(cls, impl, **kwargs):
index 87e02308dc842136f6be67dcd727c2054fc50676..bbc977d7df7018010430d7a4b7b6e47243f54409 100644 (file)
@@ -227,26 +227,28 @@ class RequestHandler(object):
         )
         self.initialize(**kwargs)  # type: ignore
 
-    def initialize(self) -> None:
-        """Hook for subclass initialization. Called for each request.
+    def _initialize(self) -> None:
+        pass
 
-        A dictionary passed as the third argument of a url spec will be
-        supplied as keyword arguments to initialize().
+    initialize = _initialize  # type: Callable[..., None]
+    """Hook for subclass initialization. Called for each request.
 
-        Example::
+    A dictionary passed as the third argument of a url spec will be
+    supplied as keyword arguments to initialize().
 
-            class ProfileHandler(RequestHandler):
-                def initialize(self, database):
-                    self.database = database
+    Example::
 
-                def get(self, username):
-                    ...
+        class ProfileHandler(RequestHandler):
+            def initialize(self, database):
+                self.database = database
 
-            app = Application([
-                (r'/user/(.*)', ProfileHandler, dict(database=database)),
-                ])
-        """
-        pass
+            def get(self, username):
+                ...
+
+        app = Application([
+            (r'/user/(.*)', ProfileHandler, dict(database=database)),
+            ])
+    """
 
     @property
     def settings(self) -> Dict[str, Any]:
@@ -2425,7 +2427,7 @@ class MissingArgumentError(HTTPError):
 class ErrorHandler(RequestHandler):
     """Generates an error response with ``status_code`` for all requests."""
 
-    def initialize(self, status_code: int) -> None:  # type: ignore
+    def initialize(self, status_code: int) -> None:
         self.set_status(status_code)
 
     def prepare(self) -> None:
@@ -2471,7 +2473,7 @@ class RedirectHandler(RequestHandler):
        destination URL.
     """
 
-    def initialize(self, url: str, permanent: bool = True) -> None:  # type: ignore
+    def initialize(self, url: str, permanent: bool = True) -> None:
         self._url = url
         self._permanent = permanent
 
@@ -2558,7 +2560,7 @@ class StaticFileHandler(RequestHandler):
     _static_hashes = {}  # type: Dict[str, Optional[str]]
     _lock = threading.Lock()  # protects _static_hashes
 
-    def initialize(  # type: ignore
+    def initialize(
         self, path: str, default_filename: str = None
     ) -> None:
         self.root = path
@@ -3009,7 +3011,7 @@ class FallbackHandler(RequestHandler):
         ])
     """
 
-    def initialize(  # type: ignore
+    def initialize(
         self, fallback: Callable[[httputil.HTTPServerRequest], None]
     ) -> None:
         self.fallback = fallback