3939from hypothesis .strategies ._internal .lazy import unwrap_strategies
4040from hypothesis .strategies ._internal .strategies import OneOfStrategy
4141
42+ GenericAlias : typing .Any
4243UnionType : typing .Any
4344try :
4445 # The type of PEP-604 unions (`int | str`), added in Python 3.10
45- from types import UnionType
46+ from types import GenericAlias , UnionType
4647except ImportError :
48+ GenericAlias = ()
4749 UnionType = ()
4850
4951try :
5052 import typing_extensions
5153except ImportError :
5254 typing_extensions = None # type: ignore
5355
54- try :
55- from typing import _GenericAlias # type: ignore # python >= 3.7
56- except ImportError :
57- _GenericAlias = ()
58-
5956try :
6057 from typing import _AnnotatedAlias # type: ignore
6158except ImportError :
@@ -298,7 +295,7 @@ def find_annotated_strategy(annotated_type): # pragma: no cover
298295def has_type_arguments (type_ ):
299296 """Decides whethere or not this type has applied type arguments."""
300297 args = getattr (type_ , "__args__" , None )
301- if args and isinstance (type_ , _GenericAlias ):
298+ if args and isinstance (type_ , ( typing . _GenericAlias , GenericAlias ) ):
302299 # There are some cases when declared types do already have type arguments
303300 # Like `Sequence`, that is `_GenericAlias(abc.Sequence[T])[T]`
304301 parameters = getattr (type_ , "__parameters__" , None )
@@ -312,7 +309,7 @@ def is_generic_type(type_):
312309 # The ugly truth is that `MyClass`, `MyClass[T]`, and `MyClass[int]` are very different.
313310 # We check for `MyClass[T]` and `MyClass[int]` with the first condition,
314311 # while the second condition is for `MyClass`.
315- return isinstance (type_ , typing_root_type ) or (
312+ return isinstance (type_ , typing_root_type + ( GenericAlias ,) ) or (
316313 isinstance (type_ , type ) and typing .Generic in type_ .__mro__
317314 )
318315
0 commit comments