Skip to content

Commit 7c59ec5

Browse files
committed
typecheck: Python 3.5 does not have typing.Collection
1 parent a883d89 commit 7c59ec5

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

unpythonic/typecheck.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@
2525
import typing
2626

2727
try:
28-
_MyGenericAlias = typing._GenericAlias
28+
_MyGenericAlias = typing._GenericAlias # Python 3.7+
2929
except AttributeError: # Python 3.6 and earlier
3030
class _MyGenericAlias: # unused, but must be a class to support isinstance() check.
3131
pass
3232

33+
try:
34+
_MyCollection = typing.Collection # Python 3.6+
35+
except AttributeError: # Python 3.5 and earlier
36+
class _MyCollection:
37+
pass
38+
3339
from .misc import safeissubclass
3440

3541
__all__ = ["isoftype"]
@@ -196,7 +202,7 @@ def get_args(tp):
196202
typing.Iterable, # can't non-destructively check element type
197203
typing.Reversible, # can't non-destructively check element type
198204
typing.Container, # can't check element type
199-
typing.Collection, # Sized Iterable Container; can't check element type
205+
_MyCollection, # Sized Iterable Container; can't check element type
200206
typing.Hashable,
201207
typing.Sized):
202208
if U is T:

0 commit comments

Comments
 (0)