@@ -4223,46 +4223,52 @@ def evaluate_forward_ref(
4223
4223
4224
4224
4225
4225
# Aliases for items that are in typing in all supported versions.
4226
- # Explicitly assign these (rather than using `from typing import *` at the top),
4227
- # so that we get a CI error if one of these is deleted from typing.py
4228
- # in a future version of Python
4229
- AbstractSet = typing .AbstractSet
4230
- Annotated = typing .Annotated
4231
- AnyStr = typing .AnyStr
4232
- BinaryIO = typing .BinaryIO
4233
- Callable = typing .Callable
4234
- Collection = typing .Collection
4235
- Container = typing .Container
4236
- Dict = typing .Dict
4237
- ForwardRef = typing .ForwardRef
4238
- FrozenSet = typing .FrozenSet
4226
+ # We use hasattr() checks so this library will continue to import on
4227
+ # future versions of Python that may remove these names.
4228
+ _typing_names = [
4229
+ "AbstractSet" ,
4230
+ "AnyStr" ,
4231
+ "BinaryIO" ,
4232
+ "Callable" ,
4233
+ "Collection" ,
4234
+ "Container" ,
4235
+ "Dict" ,
4236
+ "FrozenSet" ,
4237
+ "Hashable" ,
4238
+ "IO" ,
4239
+ "ItemsView" ,
4240
+ "Iterable" ,
4241
+ "Iterator" ,
4242
+ "KeysView" ,
4243
+ "List" ,
4244
+ "Mapping" ,
4245
+ "MappingView" ,
4246
+ "Match" ,
4247
+ "MutableMapping" ,
4248
+ "MutableSequence" ,
4249
+ "MutableSet" ,
4250
+ "Optional" ,
4251
+ "Pattern" ,
4252
+ "Reversible" ,
4253
+ "Sequence" ,
4254
+ "Set" ,
4255
+ "Sized" ,
4256
+ "TextIO" ,
4257
+ "Tuple" ,
4258
+ "Union" ,
4259
+ "ValuesView" ,
4260
+ "cast" ,
4261
+ "no_type_check" ,
4262
+ "no_type_check_decorator" ,
4263
+ # This is private, but it was defined by typing_extensions for a long time
4264
+ # and some users rely on it.
4265
+ "_AnnotatedAlias" ,
4266
+ ]
4267
+ globals ().update (
4268
+ {name : getattr (typing , name ) for name in _typing_names if hasattr (typing , name )}
4269
+ )
4270
+ # These are defined unconditionally because they are used in
4271
+ # typing-extensions itself.
4239
4272
Generic = typing .Generic
4240
- Hashable = typing .Hashable
4241
- IO = typing .IO
4242
- ItemsView = typing .ItemsView
4243
- Iterable = typing .Iterable
4244
- Iterator = typing .Iterator
4245
- KeysView = typing .KeysView
4246
- List = typing .List
4247
- Mapping = typing .Mapping
4248
- MappingView = typing .MappingView
4249
- Match = typing .Match
4250
- MutableMapping = typing .MutableMapping
4251
- MutableSequence = typing .MutableSequence
4252
- MutableSet = typing .MutableSet
4253
- Optional = typing .Optional
4254
- Pattern = typing .Pattern
4255
- Reversible = typing .Reversible
4256
- Sequence = typing .Sequence
4257
- Set = typing .Set
4258
- Sized = typing .Sized
4259
- TextIO = typing .TextIO
4260
- Tuple = typing .Tuple
4261
- Union = typing .Union
4262
- ValuesView = typing .ValuesView
4263
- cast = typing .cast
4264
- no_type_check = typing .no_type_check
4265
- no_type_check_decorator = typing .no_type_check_decorator
4266
- # This is private, but it was defined by typing_extensions for a long time
4267
- # and some users rely on it.
4268
- _AnnotatedAlias = typing ._AnnotatedAlias
4273
+ ForwardRef = typing .ForwardRef
4274
+ Annotated = typing .Annotated
0 commit comments