Skip to content

Commit

Permalink
Abandon attempts to support protocols in 3.5.0 and 3.5.1, see python#195
Browse files Browse the repository at this point in the history
  • Loading branch information
ilevkivskyi committed Aug 19, 2017
1 parent a4e68ff commit c8076ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
14 changes: 13 additions & 1 deletion typing_extensions/src_py3/test_typing_extensions.py
Expand Up @@ -11,7 +11,11 @@
from typing import Generic
from typing import get_type_hints
from typing import no_type_check
from typing_extensions import NoReturn, ClassVar, Type, NewType, Protocol, runtime
from typing_extensions import NoReturn, ClassVar, Type, NewType
try:
from typing_extensions import Protocol, runtime
except ImportError:
pass
import typing
import typing_extensions
import collections.abc as collections_abc
Expand Down Expand Up @@ -48,6 +52,10 @@
# For checks reliant on Python 3.6 syntax changes (e.g. classvar)
PY36 = sys.version_info[:2] >= (3, 6)

# It is very difficult to backport Protocols to these versions due to
# different generics system. See https://github.com/python/typing/pull/195
NO_PROTOCOL = sys.version_info[:3] in [(3, 5, 0), (3, 5, 1)]


class BaseTestCase(TestCase):
def assertIsSubclass(self, cls, class_or_tuple, msg=None):
Expand Down Expand Up @@ -1087,6 +1095,10 @@ class E:
self.assertIsInstance(E(), D)


if NO_PROTOCOL:
ProtocolTests = None


class AllTests(BaseTestCase):
def test_typing_extensions_includes_standard(self):
a = typing_extensions.__all__
Expand Down
19 changes: 14 additions & 5 deletions typing_extensions/src_py3/typing_extensions.py
Expand Up @@ -8,11 +8,12 @@
# These are used by Protocol implementation
# We use internal typing helpers here, but this significantly reduces
# code duplication. (Also this is only until Protocol is in typing.)
from typing import (
GenericMeta, TypingMeta, Generic, Callable, TypeVar, Tuple,
_type_vars, _next_in_mro, _type_check,
_make_subclasshook, _check_generic
)
from typing import GenericMeta, TypingMeta, Generic, Callable, TypeVar, Tuple
NO_PROTOCOL = False
try:
from typing import _type_vars, _next_in_mro, _type_check, _check_generic
except ImportError:
NO_PROTOCOL = True
try:
from typing import _no_slots_copy
except ImportError:
Expand All @@ -31,6 +32,10 @@ def _no_slots_copy(dct):
except ImportError:
class _TypingEllipsis: pass
class _TypingEmpty: pass
try:
from typing import _make_subclasshook
except ImportError:
_make_subclasshook = None

if hasattr(typing, '_generic_new'):
_generic_new = typing._generic_new
Expand Down Expand Up @@ -908,3 +913,7 @@ def runtime(cls):
' got %r' % cls)
cls._is_runtime_protocol = True
return cls


if NO_PROTOCOL:
del Protocol, runtime

0 comments on commit c8076ee

Please sign in to comment.