Skip to content

Commit

Permalink
[3.7] Import Protocol from typing_extensions (#5111) (#5113)
Browse files Browse the repository at this point in the history
Conditional imports must reference `sys.version_info` directly
for type checkers to be able to narrow them.  If a type checker
cannot tell whether `PY_38` is true, it will combine the imports
from both clauses in a `Union`.
However, `typing.Protocol` and `typing_extensions.Protocol` are
incompatible with each other - they do not inherit from the same class.
This produces a type error which is reported to users of aiohttp
depending on their type checking configuration..
(cherry picked from commit fb8037a)

Co-authored-by: layday <31134424+layday@users.noreply.github.com>

Co-authored-by: layday <31134424+layday@users.noreply.github.com>
  • Loading branch information
asvetlov and layday committed Oct 24, 2020
1 parent 9b211e2 commit 6c0a873
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES/5111.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a type error with reified properties caused by the
conditional import of `Protocol`.
6 changes: 1 addition & 5 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import async_timeout
import attr
from multidict import MultiDict, MultiDictProxy
from typing_extensions import Protocol
from yarl import URL

from . import hdrs
Expand All @@ -67,11 +68,6 @@
except ImportError:
from typing_extensions import ContextManager

if PY_38:
from typing import Protocol
else:
from typing_extensions import Protocol # type: ignore


def all_tasks(
loop: Optional[asyncio.AbstractEventLoop] = None,
Expand Down

0 comments on commit 6c0a873

Please sign in to comment.