Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aio-libs/aiohttp-sse
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.2.0
Choose a base ref
...
head repository: aio-libs/aiohttp-sse
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 56 additions and 64 deletions.
  1. +1 −1 .github/workflows/auto-merge.yml
  2. +2 −2 .github/workflows/ci.yml
  3. +6 −6 .pre-commit-config.yaml
  4. +1 −1 CHANGES.rst
  5. +6 −5 aiohttp_sse/__init__.py
  6. +3 −10 aiohttp_sse/helpers.py
  7. +2 −3 examples/chat.py
  8. +4 −3 examples/graceful_shutdown.py
  9. +2 −2 requirements-dev.txt
  10. +5 −5 requirements.txt
  11. +4 −4 setup.py
  12. +20 −22 tests/test_sse.py
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
uses: dependabot/fetch-metadata@v2.3.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Enable auto-merge for Dependabot PRs
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ jobs:
name: Test
strategy:
matrix:
pyver: ['3.8', '3.9', '3.10', '3.11', '3.12']
pyver: ['3.9', '3.10', '3.11', '3.12', '3.13']
os: [ubuntu, macos, windows]
runs-on: ${{ matrix.os }}-latest
timeout-minutes: 10
@@ -62,7 +62,7 @@ jobs:
COLOR: 'yes'
- run: python -m coverage xml
- name: Upload coverage
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.5.0'
rev: 'v5.0.0'
hooks:
- id: check-merge-conflict
- repo: https://github.com/asottile/yesqa
@@ -12,12 +12,12 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: '24.2.0'
rev: '24.10.0'
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.5.0'
rev: 'v5.0.0'
hooks:
- id: end-of-file-fixer
- id: requirements-txt-fixer
@@ -43,12 +43,12 @@ repos:
- id: detect-private-key
exclude: ^examples/
- repo: https://github.com/asottile/pyupgrade
rev: 'v3.15.1'
rev: 'v3.19.0'
hooks:
- id: pyupgrade
args: ['--py38-plus']
args: ['--py39-plus']
- repo: https://github.com/PyCQA/flake8
rev: '7.0.0'
rev: '7.1.1'
hooks:
- id: flake8
exclude: "^docs/"
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ CHANGES

- Added typing support.
- Added ``EventSourceResponse.is_connected()`` method.
- Added ``EventSourceResponse.last_event_id()`` method.
- Added ``EventSourceResponse.last_event_id`` attribute.
- Added support for SSE with HTTP methods other than GET.
- Added support for float ping intervals.
- Fixed (on Python 3.11+) ``EventSourceResponse.wait()`` swallowing user cancellation.
11 changes: 6 additions & 5 deletions aiohttp_sse/__init__.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@
import io
import re
import sys
from collections.abc import Mapping
from types import TracebackType
from typing import Any, Mapping, Optional, Type, TypeVar, Union, overload
from typing import Any, Optional, TypeVar, Union, overload

from aiohttp.abc import AbstractStreamWriter
from aiohttp.web import BaseRequest, ContentCoding, Request, StreamResponse
@@ -162,7 +163,7 @@ def stop_streaming(self) -> None:
self._ping_task.cancel()

def enable_compression(
self, force: Union[bool, ContentCoding, None] = False
self, force: Union[bool, ContentCoding, None] = False, strategy: int = 0
) -> None:
raise NotImplementedError

@@ -213,7 +214,7 @@ async def __aenter__(self) -> "EventSourceResponse":

async def __aexit__(
self,
exc_type: Optional[Type[BaseException]],
exc_type: Optional[type[BaseException]],
exc: Optional[BaseException],
traceback: Optional[TracebackType],
) -> None:
@@ -244,7 +245,7 @@ def sse_response(
reason: Optional[str] = None,
headers: Optional[Mapping[str, str]] = None,
sep: Optional[str] = None,
response_cls: Type[ESR],
response_cls: type[ESR],
) -> _ContextManager[ESR]: ...


@@ -255,7 +256,7 @@ def sse_response(
reason: Optional[str] = None,
headers: Optional[Mapping[str, str]] = None,
sep: Optional[str] = None,
response_cls: Type[EventSourceResponse] = EventSourceResponse,
response_cls: type[EventSourceResponse] = EventSourceResponse,
) -> Any:
if not issubclass(response_cls, EventSourceResponse):
raise TypeError(
13 changes: 3 additions & 10 deletions aiohttp_sse/helpers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
from collections.abc import Coroutine, Generator
from types import TracebackType
from typing import (
Any,
AsyncContextManager,
Coroutine,
Generator,
Optional,
Type,
TypeVar,
)
from typing import Any, AsyncContextManager, Optional, TypeVar

T = TypeVar("T", bound=AsyncContextManager["T"]) # type: ignore[misc]

@@ -52,7 +45,7 @@ async def __aenter__(self) -> T:

async def __aexit__(
self,
exc_type: Optional[Type[BaseException]],
exc_type: Optional[type[BaseException]],
exc: Optional[BaseException],
tb: Optional[TracebackType],
) -> Optional[bool]:
5 changes: 2 additions & 3 deletions examples/chat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import asyncio
import json
from typing import Set

from aiohttp import web

from aiohttp_sse import EventSourceResponse, sse_response

channels = web.AppKey("channels", Set[asyncio.Queue[str]])
channels = web.AppKey("channels", set[asyncio.Queue[str]])


async def chat(_request: web.Request) -> web.Response:
@@ -111,7 +110,7 @@ async def subscribe(request: web.Request) -> EventSourceResponse:

if __name__ == "__main__":
app = web.Application()
app[channels] = set() # type: ignore[misc]
app[channels] = set()

app.router.add_route("GET", "/", chat)
app.router.add_route("POST", "/everyone", message)
7 changes: 4 additions & 3 deletions examples/graceful_shutdown.py
Original file line number Diff line number Diff line change
@@ -2,10 +2,11 @@
import json
import logging
import weakref
from collections.abc import Callable
from contextlib import suppress
from datetime import datetime
from functools import partial
from typing import Any, Callable, Dict, Optional
from typing import Any, Optional

from aiohttp import web

@@ -18,7 +19,7 @@
class SSEResponse(EventSourceResponse):
async def send_json(
self,
data: Dict[str, Any],
data: dict[str, Any],
id: Optional[str] = None,
event: Optional[str] = None,
retry: Optional[int] = None,
@@ -29,7 +30,7 @@ async def send_json(

async def send_event(
stream: SSEResponse,
data: Dict[str, Any],
data: dict[str, Any],
event_id: str,
) -> None:
try:
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r requirements.txt
mypy==1.8.0
mypy==1.15.0

pre-commit==3.6.2
pre-commit==4.1.0
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-e .
aiohttp==3.9.3
pytest==8.0.2
pytest-aiohttp==1.0.5
pytest-asyncio==0.23.5
pytest-cov==4.1.0
aiohttp==3.11.13
pytest==8.3.5
pytest-aiohttp==1.1.0
pytest-asyncio==0.25.3
pytest-cov==6.0.0
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@

PY_VER = sys.version_info

if not PY_VER >= (3, 8):
raise RuntimeError("aiohttp-sse doesn't support Python earlier than 3.8")
if PY_VER < (3, 9):
raise RuntimeError("aiohttp-sse doesn't support Python earlier than 3.9")


def read(f):
@@ -51,11 +51,11 @@ def read_version():
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Internet :: WWW/HTTP",
"Framework :: AsyncIO",
"Framework :: aiohttp",
@@ -64,7 +64,7 @@ def read_version():
author_email="nickolainovik@gmail.com",
url="https://github.com/aio-libs/aiohttp_sse/",
license="Apache 2",
python_requires=">=3.8",
python_requires=">=3.9",
packages=find_packages(),
install_requires=install_requires,
include_package_data=True,
Loading