From 955628e273e86a208416f6a79b2a1c69fb817343 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Wed, 9 Jan 2019 12:15:03 +0000 Subject: [PATCH] [3.5] Allow run_app(access_log=None) (#3504) * Mark access_log as optional * Make access_log=None work in debug mode (cherry picked from commit c562ffe3) Co-authored-by: Hynek Schlawack --- CHANGES/3504.bugfix | 1 + aiohttp/web.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 CHANGES/3504.bugfix diff --git a/CHANGES/3504.bugfix b/CHANGES/3504.bugfix new file mode 100644 index 00000000000..8ffa3e907a6 --- /dev/null +++ b/CHANGES/3504.bugfix @@ -0,0 +1 @@ +Fix type stubs for ``aiohttp.web.run_app(access_log=True)`` and fix edge case of ``access_log=True`` and the event loop being in debug mode. diff --git a/aiohttp/web.py b/aiohttp/web.py index 0c3b6374d0f..fa66658feed 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -269,7 +269,7 @@ async def _run_app(app: Union[Application, Awaitable[Application]], *, backlog: int=128, access_log_class: Type[AbstractAccessLogger]=AccessLogger, access_log_format: str=AccessLogger.LOG_FORMAT, - access_log: logging.Logger=access_logger, + access_log: Optional[logging.Logger]=access_logger, handle_signals: bool=True, reuse_address: Optional[bool]=None, reuse_port: Optional[bool]=None) -> None: @@ -383,7 +383,7 @@ def run_app(app: Union[Application, Awaitable[Application]], *, backlog: int=128, access_log_class: Type[AbstractAccessLogger]=AccessLogger, access_log_format: str=AccessLogger.LOG_FORMAT, - access_log: logging.Logger=access_logger, + access_log: Optional[logging.Logger]=access_logger, handle_signals: bool=True, reuse_address: Optional[bool]=None, reuse_port: Optional[bool]=None) -> None: @@ -391,7 +391,7 @@ def run_app(app: Union[Application, Awaitable[Application]], *, loop = asyncio.get_event_loop() # Configure if and only if in debugging mode and using the default logger - if loop.get_debug() and access_log.name == 'aiohttp.access': + if loop.get_debug() and access_log and access_log.name == 'aiohttp.access': if access_log.level == logging.NOTSET: access_log.setLevel(logging.DEBUG) if not access_log.hasHandlers():