remove overlapping slots from app.Sanic, fix broken slots inherit of HTTPResponse (#2387)

This commit is contained in:
Arie Bovenberg 2022-02-24 16:45:23 +01:00 committed by GitHub
parent d4fb44e986
commit 7523e87937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 3 deletions

View File

@ -140,6 +140,7 @@ To maintain the code consistency, Sanic uses following tools.
#. `isort <https://github.com/timothycrosley/isort>`_ #. `isort <https://github.com/timothycrosley/isort>`_
#. `black <https://github.com/python/black>`_ #. `black <https://github.com/python/black>`_
#. `flake8 <https://github.com/PyCQA/flake8>`_ #. `flake8 <https://github.com/PyCQA/flake8>`_
#. `slotscheck <https://github.com/ariebovenberg/slotscheck>`_
isort isort
***** *****
@ -167,7 +168,13 @@ flake8
#. pycodestyle #. pycodestyle
#. Ned Batchelder's McCabe script #. 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. The **easiest** way to make your code conform is to run the following before committing.

View File

@ -142,7 +142,6 @@ class Sanic(BaseSanic, RunnerMixin, metaclass=TouchUpMeta):
"error_handler", "error_handler",
"go_fast", "go_fast",
"listeners", "listeners",
"name",
"named_request_middleware", "named_request_middleware",
"named_response_middleware", "named_response_middleware",
"request_class", "request_class",

View File

@ -50,6 +50,16 @@ class BaseHTTPResponse:
The base class for all HTTP Responses The base class for all HTTP Responses
""" """
__slots__ = (
"asgi",
"body",
"content_type",
"stream",
"status",
"headers",
"_cookies",
)
_dumps = json_dumps _dumps = json_dumps
def __init__(self): def __init__(self):
@ -156,7 +166,7 @@ class HTTPResponse(BaseHTTPResponse):
:type content_type: Optional[str] :type content_type: Optional[str]
""" """
__slots__ = ("body", "status", "content_type", "headers", "_cookies") __slots__ = ()
def __init__( def __init__(
self, self,

View File

@ -112,6 +112,7 @@ tests_require = [
"docutils", "docutils",
"pygments", "pygments",
"uvicorn<0.15.0", "uvicorn<0.15.0",
"slotscheck>=0.8.0,<1",
types_ujson, types_ujson,
] ]

View File

@ -21,6 +21,7 @@ commands =
flake8 sanic flake8 sanic
black --config ./.black.toml --check --verbose sanic/ black --config ./.black.toml --check --verbose sanic/
isort --check-only sanic --profile=black isort --check-only sanic --profile=black
slotscheck --verbose -m sanic
[testenv:type-checking] [testenv:type-checking]
commands = commands =