Skip to content

Commit

Permalink
Import Protocol from typing_extensions
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.
  • Loading branch information
layday committed Oct 24, 2020
1 parent e633968 commit 6d22a98
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 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`.
7 changes: 1 addition & 6 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import async_timeout
import attr
from multidict import MultiDict, MultiDictProxy
from typing_extensions import final
from typing_extensions import Protocol, final
from yarl import URL

from . import hdrs
Expand All @@ -67,11 +67,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 6d22a98

Please sign in to comment.