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 imports of typing_extensions #5374

Merged
merged 11 commits into from
Mar 15, 2021
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
1 change: 1 addition & 0 deletions CHANGES/5107.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only depend on typing_extensions for Python <3.8
3 changes: 1 addition & 2 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import attr
from multidict import CIMultiDict, MultiDict, MultiDictProxy, istr
from typing_extensions import Final
from yarl import URL

from . import hdrs, http, payload
Expand Down Expand Up @@ -86,7 +85,7 @@
from .http_websocket import WSHandshakeError, WSMessage, ws_ext_gen, ws_ext_parse
from .streams import FlowControlDataQueue
from .tracing import Trace, TraceConfig
from .typedefs import JSONEncoder, LooseCookies, LooseHeaders, StrOrURL
from .typedefs import Final, JSONEncoder, LooseCookies, LooseHeaders, StrOrURL

__all__ = (
# client_exceptions
Expand Down
7 changes: 6 additions & 1 deletion aiohttp/hdrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

# After changing the file content call ./tools/gen.py
# to regenerate the headers parser
import sys
from typing import Set

from multidict import istr
from typing_extensions import Final

if sys.version_info >= (3, 8):
from typing import Final
else:
from typing_extensions import Final

METH_ANY: Final[str] = "*"
METH_CONNECT: Final[str] = "CONNECT"
Expand Down
9 changes: 2 additions & 7 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from typing import (
Any,
Callable,
ContextManager,
Dict,
Generator,
Generic,
Expand All @@ -45,12 +46,11 @@
import async_timeout
import attr
from multidict import MultiDict, MultiDictProxy
from typing_extensions import Protocol
from yarl import URL

from . import hdrs
from .log import client_logger, internal_logger
from .typedefs import PathLike # noqa
from .typedefs import PathLike, Protocol # noqa

__all__ = ("BasicAuth", "ChainMapProxy")

Expand All @@ -63,11 +63,6 @@

idna_ssl.patch_match_hostname()

try:
from typing import ContextManager
except ImportError:
from typing_extensions import ContextManager


def all_tasks(
loop: Optional[asyncio.AbstractEventLoop] = None,
Expand Down
3 changes: 1 addition & 2 deletions aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
)

from multidict import CIMultiDict, CIMultiDictProxy, istr
from typing_extensions import Final
from yarl import URL

from . import hdrs
Expand All @@ -39,7 +38,7 @@
from .http_writer import HttpVersion, HttpVersion10
from .log import internal_logger
from .streams import EMPTY_PAYLOAD, StreamReader
from .typedefs import RawHeaders
from .typedefs import Final, RawHeaders

try:
import brotli
Expand Down
3 changes: 1 addition & 2 deletions aiohttp/http_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
from struct import Struct
from typing import Any, Callable, List, Optional, Pattern, Set, Tuple, Union, cast

from typing_extensions import Final

from .base_protocol import BaseProtocol
from .helpers import NO_EXTENSIONS
from .streams import DataQueue
from .typedefs import Final

__all__ = (
"WS_CLOSED_MESSAGE",
Expand Down
7 changes: 1 addition & 6 deletions aiohttp/locks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import asyncio
import collections
from typing import Any, Optional

try:
from typing import Deque
except ImportError:
from typing_extensions import Deque
from typing import Any, Deque, Optional


class EventResultOrError:
Expand Down
3 changes: 1 addition & 2 deletions aiohttp/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
)

from multidict import CIMultiDict
from typing_extensions import Final

from . import hdrs
from .abc import AbstractStreamWriter
Expand All @@ -35,7 +34,7 @@
sentinel,
)
from .streams import StreamReader
from .typedefs import JSONEncoder, _CIMultiDict
from .typedefs import Final, JSONEncoder, _CIMultiDict

__all__ = (
"PAYLOAD_REGISTRY",
Expand Down
10 changes: 2 additions & 8 deletions aiohttp/streams.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import asyncio
import collections
import warnings
from typing import Awaitable, Callable, Generic, List, Optional, Tuple, TypeVar

from typing_extensions import Final
from typing import Awaitable, Callable, Deque, Generic, List, Optional, Tuple, TypeVar

from .base_protocol import BaseProtocol
from .helpers import BaseTimerContext, set_exception, set_result
from .log import internal_logger

try: # pragma: no cover
from typing import Deque
except ImportError:
from typing_extensions import Deque
from .typedefs import Final

__all__ = (
"EMPTY_PAYLOAD",
Expand Down
3 changes: 1 addition & 2 deletions aiohttp/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
from .client_reqrep import ClientResponse

if TYPE_CHECKING: # pragma: no cover
from typing_extensions import Protocol

from .client import ClientSession
from .typedefs import Protocol

_ParamT_contra = TypeVar("_ParamT_contra", contravariant=True)

Expand Down
10 changes: 10 additions & 0 deletions aiohttp/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
from multidict import CIMultiDict, CIMultiDictProxy, MultiDict, MultiDictProxy, istr
from yarl import URL

# These are for other modules to use (to avoid repeating the conditional import).
if sys.version_info >= (3, 8):
from typing import Final as Final, Protocol as Protocol, TypedDict as TypedDict
else:
from typing_extensions import ( # noqa: F401
Final,
Protocol as Protocol,
TypedDict as TypedDict,
)

DEFAULT_JSON_ENCODER = json.dumps
DEFAULT_JSON_DECODER = json.loads

Expand Down
4 changes: 1 addition & 3 deletions aiohttp/web_fileresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
cast,
)

from typing_extensions import Final

from . import hdrs
from .abc import AbstractStreamWriter
from .typedefs import LooseHeaders
from .typedefs import Final, LooseHeaders
from .web_exceptions import (
HTTPNotModified,
HTTPPartialContent,
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import attr
from multidict import CIMultiDict, CIMultiDictProxy, MultiDict, MultiDictProxy
from typing_extensions import Final
from yarl import URL

from . import hdrs
Expand All @@ -39,6 +38,7 @@
from .streams import EmptyStreamReader, StreamReader
from .typedefs import (
DEFAULT_JSON_DECODER,
Final,
JSONDecoder,
LooseHeaders,
RawHeaders,
Expand Down
3 changes: 1 addition & 2 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
cast,
)

from typing_extensions import Final, TypedDict
from yarl import URL, __version__ as yarl_version # type: ignore[attr-defined]

from . import hdrs
from .abc import AbstractMatchInfo, AbstractRouter, AbstractView
from .helpers import DEBUG
from .http import HttpVersion11
from .typedefs import PathLike
from .typedefs import Final, PathLike, TypedDict
from .web_exceptions import (
HTTPException,
HTTPExpectationFailed,
Expand Down
3 changes: 1 addition & 2 deletions aiohttp/web_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import async_timeout
import attr
from multidict import CIMultiDict
from typing_extensions import Final

from . import hdrs
from .abc import AbstractStreamWriter
Expand All @@ -28,7 +27,7 @@
)
from .log import ws_logger
from .streams import EofStream, FlowControlDataQueue
from .typedefs import JSONDecoder, JSONEncoder
from .typedefs import Final, JSONDecoder, JSONEncoder
from .web_exceptions import HTTPBadRequest, HTTPException
from .web_request import BaseRequest
from .web_response import StreamResponse
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def build_extension(self, ext):
'asynctest==0.13.0; python_version<"3.8"',
"yarl>=1.0,<2.0",
'idna-ssl>=1.0; python_version<"3.7"',
"typing_extensions>=3.7.4",
'typing_extensions>=3.7.4; python_version<"3.8"',
"frozenlist>=1.1.1",
"aiosignal>=1.1.2",
]
Expand Down