add type annotations in run and create_server
This commit is contained in:
parent
a86a10b128
commit
b7a6f36e95
90
sanic/app.py
90
sanic/app.py
|
@ -2,13 +2,15 @@ import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import typing
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from asyncio import CancelledError, ensure_future, get_event_loop
|
from asyncio import CancelledError, ensure_future, get_event_loop, Protocol
|
||||||
from collections import defaultdict, deque
|
from collections import defaultdict, deque
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from inspect import getmodulename, isawaitable, signature, stack
|
from inspect import getmodulename, isawaitable, signature, stack
|
||||||
from ssl import Purpose, create_default_context
|
from socket import socket
|
||||||
|
from ssl import Purpose, create_default_context, SSLContext
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from urllib.parse import urlencode, urlunparse
|
from urllib.parse import urlencode, urlunparse
|
||||||
|
|
||||||
|
@ -967,34 +969,46 @@ class Sanic:
|
||||||
|
|
||||||
def run(
|
def run(
|
||||||
self,
|
self,
|
||||||
host=None,
|
host: typing.Optional[str]=None,
|
||||||
port=None,
|
port: typing.Optional[int]=None,
|
||||||
debug=False,
|
debug: bool=False,
|
||||||
ssl=None,
|
ssl: typing.Union[dict, SSLContext, None]=None,
|
||||||
sock=None,
|
sock: typing.Optional[socket]=None,
|
||||||
workers=1,
|
workers: int=1,
|
||||||
protocol=None,
|
protocol: typing.Type[Protocol]=None,
|
||||||
backlog=100,
|
backlog: int=100,
|
||||||
stop_event=None,
|
stop_event: typing.Any=None,
|
||||||
register_sys_signals=True,
|
register_sys_signals: bool=True,
|
||||||
access_log=None,
|
access_log: bool=None,
|
||||||
**kwargs
|
**kwargs: typing.Any
|
||||||
):
|
) -> None:
|
||||||
"""Run the HTTP Server and listen until keyboard interrupt or term
|
"""Run the HTTP Server and listen until keyboard interrupt or term
|
||||||
signal. On termination, drain connections before closing.
|
signal. On termination, drain connections before closing.
|
||||||
|
|
||||||
:param host: Address to host on
|
:param host: Address to host on
|
||||||
|
:type host: str
|
||||||
:param port: Port to host on
|
:param port: Port to host on
|
||||||
|
:type port: int
|
||||||
:param debug: Enables debug output (slows server)
|
:param debug: Enables debug output (slows server)
|
||||||
|
:type debug: bool
|
||||||
:param ssl: SSLContext, or location of certificate and key
|
:param ssl: SSLContext, or location of certificate and key
|
||||||
for SSL encryption of worker(s)
|
for SSL encryption of worker(s)
|
||||||
|
:type ssl:SSLContext or dict
|
||||||
:param sock: Socket for the server to accept connections from
|
:param sock: Socket for the server to accept connections from
|
||||||
|
:type sock: socket
|
||||||
:param workers: Number of processes received before it is respected
|
:param workers: Number of processes received before it is respected
|
||||||
|
:type workers: int
|
||||||
|
:param protocol: Subclass of asyncio Protocol class
|
||||||
|
:type protocol: type[Protocol]
|
||||||
:param backlog: a number of unaccepted connections that the system
|
:param backlog: a number of unaccepted connections that the system
|
||||||
will allow before refusing new connections
|
will allow before refusing new connections
|
||||||
:param stop_event: event to be triggered before stopping the app
|
:type backlog: int
|
||||||
|
:param stop_event: event to be triggered before stopping the app - deprecated
|
||||||
|
:type stop_event: None
|
||||||
:param register_sys_signals: Register SIG* events
|
:param register_sys_signals: Register SIG* events
|
||||||
:param protocol: Subclass of asyncio protocol class
|
:type register_sys_signals: bool
|
||||||
|
:param access_log: Enables writing access logs (slows server)
|
||||||
|
:type access_log: bool
|
||||||
:return: Nothing
|
:return: Nothing
|
||||||
"""
|
"""
|
||||||
if "loop" in kwargs:
|
if "loop" in kwargs:
|
||||||
|
@ -1085,16 +1099,16 @@ class Sanic:
|
||||||
|
|
||||||
async def create_server(
|
async def create_server(
|
||||||
self,
|
self,
|
||||||
host=None,
|
host: typing.Optional[str] = None,
|
||||||
port=None,
|
port: typing.Optional[int] = None,
|
||||||
debug=False,
|
debug: bool = False,
|
||||||
ssl=None,
|
ssl: typing.Union[dict, SSLContext, None] = None,
|
||||||
sock=None,
|
sock: typing.Optional[socket] = None,
|
||||||
protocol=None,
|
protocol: typing.Type[Protocol] = None,
|
||||||
backlog=100,
|
backlog: int = 100,
|
||||||
stop_event=None,
|
stop_event: typing.Any = None,
|
||||||
access_log=None,
|
access_log: bool = None,
|
||||||
):
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Asynchronous version of :func:`run`.
|
Asynchronous version of :func:`run`.
|
||||||
|
|
||||||
|
@ -1105,6 +1119,28 @@ class Sanic:
|
||||||
.. note::
|
.. note::
|
||||||
This does not support multiprocessing and is not the preferred
|
This does not support multiprocessing and is not the preferred
|
||||||
way to run a :class:`Sanic` application.
|
way to run a :class:`Sanic` application.
|
||||||
|
|
||||||
|
:param host: Address to host on
|
||||||
|
:type host: str
|
||||||
|
:param port: Port to host on
|
||||||
|
:type port: int
|
||||||
|
:param debug: Enables debug output (slows server)
|
||||||
|
:type debug: bool
|
||||||
|
:param ssl: SSLContext, or location of certificate and key
|
||||||
|
for SSL encryption of worker(s)
|
||||||
|
:type ssl:SSLContext or dict
|
||||||
|
:param sock: Socket for the server to accept connections from
|
||||||
|
:type sock: socket
|
||||||
|
:param protocol: Subclass of asyncio Protocol class
|
||||||
|
:type protocol: type[Protocol]
|
||||||
|
:param backlog: a number of unaccepted connections that the system
|
||||||
|
will allow before refusing new connections
|
||||||
|
:type backlog: int
|
||||||
|
:param stop_event: event to be triggered before stopping the app - deprecated
|
||||||
|
:type stop_event: None
|
||||||
|
:param access_log: Enables writing access logs (slows server)
|
||||||
|
:type access_log: bool
|
||||||
|
:return: Nothing
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if sock is None:
|
if sock is None:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import types
|
import types
|
||||||
|
from distutils.util import strtobool
|
||||||
|
|
||||||
from sanic.exceptions import PyFileError
|
from sanic.exceptions import PyFileError
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ class Config(dict):
|
||||||
try:
|
try:
|
||||||
self[config_key] = float(v)
|
self[config_key] = float(v)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if v in ["True", "False"]:
|
try:
|
||||||
self[config_key] = v == "True"
|
self[config_key] = bool(strtobool(v))
|
||||||
else:
|
except ValueError:
|
||||||
self[config_key] = v
|
self[config_key] = v
|
||||||
|
|
Loading…
Reference in New Issue
Block a user