"""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):
)
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]:
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:
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
_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
])
"""
- def initialize( # type: ignore
+ def initialize(
self, fallback: Callable[[httputil.HTTPServerRequest], None]
) -> None:
self.fallback = fallback