Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ jobs:
python -m pip install .
env:
AIOHTTP_NO_EXTENSIONS: 1
- name: Run linters
- name: Run mypy
run: |
make mypy
- name: Run slotscheck
run: |
# Some extra requirements are needed to ensure all modules
# can be scanned by slotscheck.
pip install -r requirements/base.txt -c requirements/constraints.txt
slotscheck -v -m aiohttp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dreamsorcerer I think we need to figure this out: #13466

- name: Install libenchant-dev
run: |
sudo apt install libenchant-dev
Expand Down
2 changes: 2 additions & 0 deletions CHANGES/6547.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove overlapping slots in ``RequestHandler``,
fix broken slots inheritance in :py:class:`~aiohttp.web.StreamResponse`.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Anes Abismail
Antoine Pietri
Anton Kasyanov
Anton Zhdan-Pushkin
Arie Bovenberg
Arseny Timoniq
Artem Yushkovskiy
Arthur Darcet
Expand Down
10 changes: 9 additions & 1 deletion aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,17 @@ def __repr__(self) -> str:


class CookieMixin:
# The `_cookies` slots is not defined here because non-empty slots cannot
# be combined with an Exception base class, as is done in HTTPException.
# CookieMixin subclasses with slots should define the `_cookies`
# slot themselves.
__slots__ = ()

def __init__(self) -> None:
super().__init__()
self._cookies: SimpleCookie[str] = SimpleCookie()
# Mypy doesn't like that _cookies isn't in __slots__.
# See the comment on this class's __slots__ for why this is OK.
self._cookies: SimpleCookie[str] = SimpleCookie() # type: ignore[misc]

@property
def cookies(self) -> "SimpleCookie[str]":
Expand Down
1 change: 0 additions & 1 deletion aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ class RequestHandler(BaseProtocol):
"_upgrade",
"_payload_parser",
"_request_parser",
"_reading_paused",
"logger",
"access_log",
"access_logger",
Expand Down
1 change: 1 addition & 0 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class StreamResponse(BaseClass, HeadersMixin, CookieMixin):
"_headers",
"_status",
"_reason",
"_cookies",
"__weakref__",
)

Expand Down
1 change: 1 addition & 0 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
mypy==0.931; implementation_name=="cpython"
pre-commit==2.17.0
pytest==6.2.5
slotscheck==0.8.0
16 changes: 11 additions & 5 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,14 @@ def test_is_expected_content_type_non_json_not_match():
)


# It's necessary to subclass CookieMixin before using it.
# See the comments on its __slots__.
class CookieImplementation(helpers.CookieMixin):
pass


def test_cookies_mixin():
sut = helpers.CookieMixin()
sut = CookieImplementation()

assert sut.cookies == {}
assert str(sut.cookies) == ""
Expand Down Expand Up @@ -880,7 +886,7 @@ def test_cookies_mixin():


def test_cookies_mixin_path():
sut = helpers.CookieMixin()
sut = CookieImplementation()

assert sut.cookies == {}

Expand Down Expand Up @@ -914,7 +920,7 @@ def test_cookies_mixin_path():


def test_sutonse_cookie__issue_del_cookie():
sut = helpers.CookieMixin()
sut = CookieImplementation()

assert sut.cookies == {}
assert str(sut.cookies) == ""
Expand All @@ -928,7 +934,7 @@ def test_sutonse_cookie__issue_del_cookie():


def test_cookie_set_after_del():
sut = helpers.CookieMixin()
sut = CookieImplementation()

sut.del_cookie("name")
sut.set_cookie("name", "val")
Expand All @@ -938,7 +944,7 @@ def test_cookie_set_after_del():


def test_populate_with_cookies():
cookies_mixin = helpers.CookieMixin()
cookies_mixin = CookieImplementation()
cookies_mixin.set_cookie("name", "value")
headers = CIMultiDict()

Expand Down