Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type of SSLContext for some static type checkers #10099

Merged
merged 41 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
dd4d0d9
Update web.py
AlanBogarin Dec 4, 2024
b6f89bd
Update worker.py
AlanBogarin Dec 4, 2024
38f0bbc
Update web_runner.py
AlanBogarin Dec 4, 2024
e50b0b5
Update connector.py
AlanBogarin Dec 4, 2024
30b48a7
Update client_reqrep.py
AlanBogarin Dec 4, 2024
1ca2f2b
Update client_exceptions.py
AlanBogarin Dec 4, 2024
cdc0ae8
Update CONTRIBUTORS.txt
AlanBogarin Dec 4, 2024
1a5682b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
aa0983a
Create 10099.bugfix.rst
AlanBogarin Dec 4, 2024
588924e
Update client_exceptions.py
AlanBogarin Dec 4, 2024
833de6e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
8162374
Update connector.py
AlanBogarin Dec 4, 2024
d784612
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
40f52db
Update client_exceptions.py
AlanBogarin Dec 4, 2024
ba3986f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
8bb9230
Update connector.py
AlanBogarin Dec 4, 2024
3fdb194
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
e25d358
Update worker.py
AlanBogarin Dec 4, 2024
ec84856
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
43c5e67
Merge branch 'master' into patch-1
AlanBogarin Dec 4, 2024
2d7c529
Merge branch 'master' into patch-1
AlanBogarin Dec 5, 2024
ae9f417
Merge branch 'master' into patch-1
AlanBogarin Dec 5, 2024
03f5d3b
Merge branch 'master' into patch-1
AlanBogarin Dec 5, 2024
377b7f3
Update CHANGES/10099.bugfix.rst
AlanBogarin Dec 5, 2024
8f000ce
Merge branch 'master' into patch-1
AlanBogarin Dec 5, 2024
76dbad7
Update client_exceptions.py
AlanBogarin Dec 6, 2024
8c7f0d5
Update client_reqrep.py
AlanBogarin Dec 6, 2024
00af2cf
Update connector.py
AlanBogarin Dec 6, 2024
ece65d4
Update web.py
AlanBogarin Dec 6, 2024
d7a4f31
Update web_runner.py
AlanBogarin Dec 6, 2024
9ae8b02
Update worker.py
AlanBogarin Dec 6, 2024
78fc62a
Merge branch 'master' into patch-1
AlanBogarin Dec 6, 2024
e8a7598
Update client_exceptions.py
AlanBogarin Dec 6, 2024
bed5d25
Update client_reqrep.py
AlanBogarin Dec 6, 2024
f8d4404
Update connector.py
AlanBogarin Dec 6, 2024
d1eb102
Update web.py
AlanBogarin Dec 6, 2024
1ce4aa2
Update web_runner.py
AlanBogarin Dec 6, 2024
53dbb9b
Update worker.py
AlanBogarin Dec 6, 2024
e71f744
Allow pyright
Dreamsorcerer Dec 6, 2024
9b92c88
Merge branch 'master' into patch-1
AlanBogarin Dec 6, 2024
2183fa2
Merge branch 'master' into patch-1
AlanBogarin Dec 6, 2024
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
1 change: 1 addition & 0 deletions CHANGES/10099.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed type of ``SSLContext`` for some static type checkers (e.g. pyright).
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Adam Mills
Adrian Krupa
Adrián Chaves
Ahmed Tahri
Alan Bogarin
Alan Tse
Alec Hanefeld
Alejandro Gómez
Expand Down
10 changes: 7 additions & 3 deletions aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

from .typedefs import StrOrURL

try:
if TYPE_CHECKING:
import ssl

SSLContext = ssl.SSLContext
except ImportError: # pragma: no cover
ssl = SSLContext = None # type: ignore[assignment]
else:
try:
import ssl

SSLContext = ssl.SSLContext
except ImportError: # pragma: no cover
ssl = SSLContext = None # type: ignore[assignment]

if TYPE_CHECKING:
from .client_reqrep import ClientResponse, ConnectionKey, Fingerprint, RequestInfo
Expand Down
12 changes: 8 additions & 4 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@
RawHeaders,
)

try:
if TYPE_CHECKING:
import ssl
from ssl import SSLContext
except ImportError: # pragma: no cover
ssl = None # type: ignore[assignment]
SSLContext = object # type: ignore[misc,assignment]
else:
try:
import ssl
from ssl import SSLContext
except ImportError: # pragma: no cover
ssl = None # type: ignore[assignment]
SSLContext = object # type: ignore[misc,assignment]


__all__ = ("ClientRequest", "ClientResponse", "RequestInfo", "Fingerprint")
Expand Down
14 changes: 9 additions & 5 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@
)
from .resolver import DefaultResolver

try:
if TYPE_CHECKING:
import ssl

SSLContext = ssl.SSLContext
except ImportError: # pragma: no cover
ssl = None # type: ignore[assignment]
SSLContext = object # type: ignore[misc,assignment]

else:
try:
import ssl

SSLContext = ssl.SSLContext
except ImportError: # pragma: no cover
ssl = None # type: ignore[assignment]
SSLContext = object # type: ignore[misc,assignment]

EMPTY_SCHEMA_SET = frozenset({""})
HTTP_SCHEMA_SET = frozenset({"http", "https"})
Expand Down
10 changes: 7 additions & 3 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from contextlib import suppress
from importlib import import_module
from typing import (
TYPE_CHECKING,
Any,
Awaitable,
Callable,
Expand Down Expand Up @@ -267,10 +268,13 @@
)


try:
if TYPE_CHECKING:
from ssl import SSLContext
except ImportError: # pragma: no cover
SSLContext = Any # type: ignore[misc,assignment]
else:
try:
from ssl import SSLContext
except ImportError: # pragma: no cover
SSLContext = object # type: ignore[misc,assignment]

# Only display warning when using -Wdefault, -We, -X dev or similar.
warnings.filterwarnings("ignore", category=NotAppKeyWarning, append=True)
Expand Down
12 changes: 7 additions & 5 deletions aiohttp/web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import signal
import socket
from abc import ABC, abstractmethod
from typing import Any, Generic, List, Optional, Set, Type, TypeVar
from typing import TYPE_CHECKING, Any, Generic, List, Optional, Set, Type, TypeVar

from yarl import URL

Expand All @@ -16,11 +16,13 @@
from .web_request import BaseRequest, Request
from .web_server import Server

try:
if TYPE_CHECKING:
from ssl import SSLContext
except ImportError:
SSLContext = object # type: ignore[misc,assignment]

else:
try:
from ssl import SSLContext
except ImportError: # pragma: no cover
SSLContext = object # type: ignore[misc,assignment]

__all__ = (
"BaseSite",
Expand Down
15 changes: 10 additions & 5 deletions aiohttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import signal
import sys
from types import FrameType
from typing import Any, Awaitable, Callable, Optional, Union # noqa
from typing import TYPE_CHECKING, Any, Optional

from gunicorn.config import AccessLogFormat as GunicornAccessLogFormat
from gunicorn.workers import base
Expand All @@ -17,13 +17,18 @@
from .web_app import Application
from .web_log import AccessLogger

try:
if TYPE_CHECKING:
import ssl

SSLContext = ssl.SSLContext
except ImportError: # pragma: no cover
ssl = None # type: ignore[assignment]
SSLContext = object # type: ignore[misc,assignment]
else:
try:
import ssl

SSLContext = ssl.SSLContext
except ImportError: # pragma: no cover
ssl = None # type: ignore[assignment]
SSLContext = object # type: ignore[misc,assignment]


__all__ = ("GunicornWebWorker", "GunicornUVLoopWebWorker")
Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ py
pydantic
pyenv
pyflakes
pyright
pytest
Pytest
Quickstart
Expand Down
Loading