From 7523e87937b8e40fffc006408e71f7c3fc51d734 Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Thu, 24 Feb 2022 16:45:23 +0100 Subject: [PATCH] remove overlapping slots from app.Sanic, fix broken slots inherit of HTTPResponse (#2387) --- CONTRIBUTING.rst | 9 ++++++++- sanic/app.py | 1 - sanic/response.py | 12 +++++++++++- setup.py | 1 + tox.ini | 1 + 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 74dee22f..ab58c8fe 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -140,6 +140,7 @@ To maintain the code consistency, Sanic uses following tools. #. `isort `_ #. `black `_ #. `flake8 `_ +#. `slotscheck `_ isort ***** @@ -167,7 +168,13 @@ flake8 #. pycodestyle #. Ned Batchelder's McCabe script -``isort``\ , ``black`` and ``flake8`` checks are performed during ``tox`` lint checks. +slotscheck +********** + +``slotscheck`` ensures that there are no problems with ``__slots__`` +(e.g. overlaps, or missing slots in base classes). + +``isort``\ , ``black``\ , ``flake8`` and ``slotscheck`` checks are performed during ``tox`` lint checks. The **easiest** way to make your code conform is to run the following before committing. diff --git a/sanic/app.py b/sanic/app.py index 625962a7..95517f7a 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -142,7 +142,6 @@ class Sanic(BaseSanic, RunnerMixin, metaclass=TouchUpMeta): "error_handler", "go_fast", "listeners", - "name", "named_request_middleware", "named_response_middleware", "request_class", diff --git a/sanic/response.py b/sanic/response.py index 8525d381..b85d20de 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -50,6 +50,16 @@ class BaseHTTPResponse: The base class for all HTTP Responses """ + __slots__ = ( + "asgi", + "body", + "content_type", + "stream", + "status", + "headers", + "_cookies", + ) + _dumps = json_dumps def __init__(self): @@ -156,7 +166,7 @@ class HTTPResponse(BaseHTTPResponse): :type content_type: Optional[str] """ - __slots__ = ("body", "status", "content_type", "headers", "_cookies") + __slots__ = () def __init__( self, diff --git a/setup.py b/setup.py index ea6f285a..a30750f9 100644 --- a/setup.py +++ b/setup.py @@ -112,6 +112,7 @@ tests_require = [ "docutils", "pygments", "uvicorn<0.15.0", + "slotscheck>=0.8.0,<1", types_ujson, ] diff --git a/tox.ini b/tox.ini index 68919e59..0eeb2561 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,7 @@ commands = flake8 sanic black --config ./.black.toml --check --verbose sanic/ isort --check-only sanic --profile=black + slotscheck --verbose -m sanic [testenv:type-checking] commands =