diff --git a/sanic/app.py b/sanic/app.py index 46ba8cd5..dfe047e9 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -5,12 +5,12 @@ import re import typing import warnings -from asyncio import CancelledError, ensure_future, get_event_loop, Protocol +from asyncio import CancelledError, Protocol, ensure_future, get_event_loop from collections import defaultdict, deque from functools import partial from inspect import getmodulename, isawaitable, signature, stack from socket import socket -from ssl import Purpose, create_default_context, SSLContext +from ssl import Purpose, SSLContext, create_default_context from traceback import format_exc from urllib.parse import urlencode, urlunparse @@ -969,17 +969,17 @@ class Sanic: def run( self, - host: typing.Optional[str]=None, - port: typing.Optional[int]=None, - debug: bool=False, - ssl: typing.Union[dict, SSLContext, None]=None, - sock: typing.Optional[socket]=None, - workers: int=1, - protocol: typing.Type[Protocol]=None, - backlog: int=100, - stop_event: typing.Any=None, - register_sys_signals: bool=True, - access_log: bool=None, + host: typing.Optional[str] = None, + port: typing.Optional[int] = None, + debug: bool = False, + ssl: typing.Union[dict, SSLContext, None] = None, + sock: typing.Optional[socket] = None, + workers: int = 1, + protocol: typing.Type[Protocol] = None, + backlog: int = 100, + stop_event: typing.Any = None, + register_sys_signals: bool = True, + access_log: typing.Optional[bool] = None, **kwargs: typing.Any ) -> None: """Run the HTTP Server and listen until keyboard interrupt or term @@ -1003,7 +1003,8 @@ class Sanic: :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 + :param stop_event: event to be triggered + before stopping the app - deprecated :type stop_event: None :param register_sys_signals: Register SIG* events :type register_sys_signals: bool @@ -1043,12 +1044,7 @@ class Sanic: ) # if access_log is passed explicitly change config.ACCESS_LOG if access_log is not None: - if isinstance(access_log, bool): - self.config.ACCESS_LOG = access_log - else: - raise ServerError( - ("'access_log' passed in 'run' should be boolean") - ) + self.config.ACCESS_LOG = access_log server_settings = self._helper( host=host, @@ -1107,7 +1103,7 @@ class Sanic: protocol: typing.Type[Protocol] = None, backlog: int = 100, stop_event: typing.Any = None, - access_log: bool = None, + access_log: typing.Optional[bool] = None, ) -> None: """ Asynchronous version of :func:`run`. @@ -1136,7 +1132,8 @@ class Sanic: :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 + :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 @@ -1159,15 +1156,7 @@ class Sanic: ) # if access_log is passed explicitly change config.ACCESS_LOG if access_log is not None: - if isinstance(access_log, bool): - self.config.ACCESS_LOG = access_log - else: - raise ServerError( - ( - "'access_log' passed in 'create_server' " - "should be boolean" - ) - ) + self.config.ACCESS_LOG = access_log server_settings = self._helper( host=host, diff --git a/sanic/config.py b/sanic/config.py index f1c6c26f..a7183d77 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -1,5 +1,6 @@ import os import types + from distutils.util import strtobool from sanic.exceptions import PyFileError diff --git a/tests/test_config.py b/tests/test_config.py index 575800e3..fe4b97b9 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -7,7 +7,7 @@ import pytest from sanic import Sanic from sanic.config import Config, DEFAULT_CONFIG -from sanic.exceptions import PyFileError, ServerError +from sanic.exceptions import PyFileError @contextmanager @@ -223,10 +223,6 @@ def test_config_access_log_passing_in_run(app): app.run(port=1340, access_log=True) assert app.config.ACCESS_LOG == True - with pytest.raises(ServerError) as e: - app.run(port=1340, access_log='string') - assert str(e.value) == ("'access_log' passed in 'run' should be boolean") - async def test_config_access_log_passing_in_create_server(app): assert app.config.ACCESS_LOG == True @@ -241,10 +237,6 @@ async def test_config_access_log_passing_in_create_server(app): await app.create_server(port=1342, access_log=True) assert app.config.ACCESS_LOG == True - with pytest.raises(ServerError) as e: - await app.create_server(port=1343, access_log='somestring') - assert str(e.value) == ("'access_log' passed in 'create_server' should be boolean") - def test_config_rewrite_keep_alive(): config = Config()