49
49
except ImportError :
50
50
typing_extensions = None # type: ignore
51
51
52
- try :
53
- from typing import GenericMeta as _GenericMeta # python < 3.7
54
- except ImportError :
55
- _GenericMeta = () # type: ignore
56
-
57
52
try :
58
53
from typing import _GenericAlias # type: ignore # python >= 3.7
59
54
except ImportError :
62
57
try :
63
58
from typing import _AnnotatedAlias # type: ignore
64
59
except ImportError :
65
- try :
66
- from typing_extensions import _AnnotatedAlias
67
- except ImportError :
68
- try :
69
- from typing_extensions import ( # type: ignore
70
- AnnotatedMeta as _AnnotatedAlias ,
71
- )
72
-
73
- assert sys .version_info [:2 ] == (3 , 6 )
74
- except ImportError :
75
- _AnnotatedAlias = ()
60
+ from typing_extensions import _AnnotatedAlias
76
61
77
62
78
63
def type_sorting_key (t ):
@@ -111,9 +96,7 @@ def try_issubclass(thing, superclass):
111
96
getattr (superclass , "__origin__" , None ) or superclass ,
112
97
):
113
98
superclass_args = getattr (superclass , "__args__" , None )
114
- if sys .version_info [:2 ] == (3 , 6 ) or not superclass_args :
115
- # Python 3.6 doesn't have PEP-560 semantics or __orig_bases__,
116
- # so there's no point continuing; we therefore stop early.
99
+ if not superclass_args :
117
100
# The superclass is not generic, so we're definitely a subclass.
118
101
return True
119
102
# Sadly this is just some really fiddly logic to handle all the cases
@@ -157,11 +140,7 @@ def is_typing_literal(thing):
157
140
hasattr (typing , "Literal" )
158
141
and getattr (thing , "__origin__" , None ) == typing .Literal
159
142
or hasattr (typing_extensions , "Literal" )
160
- and (
161
- getattr (thing , "__origin__" , None ) == typing_extensions .Literal
162
- or sys .version_info [:2 ] == (3 , 6 )
163
- and isinstance (thing , type (typing_extensions .Literal [None ]))
164
- )
143
+ and getattr (thing , "__origin__" , None ) == typing_extensions .Literal
165
144
)
166
145
167
146
@@ -190,7 +169,7 @@ def find_annotated_strategy(annotated_type): # pragma: no cover
190
169
def has_type_arguments (type_ ):
191
170
"""Decides whethere or not this type has applied type arguments."""
192
171
args = getattr (type_ , "__args__" , None )
193
- if args and isinstance (type_ , ( _GenericAlias , _GenericMeta ) ):
172
+ if args and isinstance (type_ , _GenericAlias ):
194
173
# There are some cases when declared types do already have type arguments
195
174
# Like `Sequence`, that is `_GenericAlias(abc.Sequence[T])[T]`
196
175
parameters = getattr (type_ , "__parameters__" , None )
@@ -202,8 +181,7 @@ def has_type_arguments(type_):
202
181
def is_generic_type (type_ ):
203
182
"""Decides whether a given type is generic or not."""
204
183
# The ugly truth is that `MyClass`, `MyClass[T]`, and `MyClass[int]` are very different.
205
- # In different python versions they might have the same type (3.6)
206
- # or it can be regular type vs `_GenericAlias` (3.7+)
184
+ # In different python versions it can be regular type vs `_GenericAlias` (3.7+)
207
185
# We check for `MyClass[T]` and `MyClass[int]` with the first condition,
208
186
# while the second condition is for `MyClass` in `python3.7+`.
209
187
return isinstance (type_ , typing_root_type ) or (
@@ -222,14 +200,6 @@ def _try_import_forward_ref(thing, bound): # pragma: no cover
222
200
try :
223
201
return typing ._eval_type (bound , vars (sys .modules [thing .__module__ ]), None )
224
202
except (KeyError , AttributeError , NameError ):
225
- if (
226
- isinstance (thing , typing .TypeVar )
227
- and getattr (thing , "__module__" , None ) == "typing"
228
- ):
229
- raise ResolutionFailed (
230
- "It looks like you're using a TypeVar bound to a ForwardRef on Python "
231
- "3.6, which is not supported - try ugrading to Python 3.7 or later."
232
- ) from None
233
203
# We fallback to `ForwardRef` instance, you can register it as a type as well:
234
204
# >>> from typing import ForwardRef
235
205
# >>> from hypothesis import strategies as st
@@ -289,7 +259,6 @@ def from_typing_type(thing):
289
259
290
260
# Some "generic" classes are not generic *in* anything - for example both
291
261
# Hashable and Sized have `__args__ == ()` on Python 3.7 or later.
292
- # (In 3.6 they're just aliases for the collections.abc classes)
293
262
origin = getattr (thing , "__origin__" , thing )
294
263
if (
295
264
typing .Hashable is not collections .abc .Hashable
@@ -310,9 +279,6 @@ def from_typing_type(thing):
310
279
# ItemsView can cause test_lookup.py::test_specialised_collection_types
311
280
# to fail, due to weird isinstance behaviour around the elements.
312
281
mapping .pop (typing .ItemsView , None )
313
- if sys .version_info [:2 ] == (3 , 6 ): # pragma: no cover
314
- # `isinstance(dict().values(), Container) is False` on py36 only -_-
315
- mapping .pop (typing .ValuesView , None )
316
282
if typing .Deque in mapping and len (mapping ) > 1 :
317
283
# Resolving generic sequences to include a deque is more trouble for e.g.
318
284
# the ghostwriter than it's worth, via undefined names in the repr.
@@ -495,12 +461,10 @@ def _networks(bits):
495
461
_global_type_lookup [type ] = st .sampled_from (
496
462
[type (None )] + sorted (_global_type_lookup , key = str )
497
463
)
498
-
499
- if sys .version_info [:2 ] >= (3 , 7 ): # pragma: no branch
500
- _global_type_lookup [re .Match ] = (
501
- st .text ().map (lambda c : re .match ("." , c , flags = re .DOTALL )).filter (bool )
502
- )
503
- _global_type_lookup [re .Pattern ] = st .builds (re .compile , st .sampled_from (["" , b"" ]))
464
+ _global_type_lookup [re .Match ] = (
465
+ st .text ().map (lambda c : re .match ("." , c , flags = re .DOTALL )).filter (bool )
466
+ )
467
+ _global_type_lookup [re .Pattern ] = st .builds (re .compile , st .sampled_from (["" , b"" ]))
504
468
if sys .version_info [:2 ] >= (3 , 9 ): # pragma: no cover
505
469
# subclass of MutableMapping, and in Python 3.9 we resolve to a union
506
470
# which includes this... but we don't actually ever want to build one.
0 commit comments