22Define names for built-in types that aren't directly accessible as a builtin.
33"""
44
5- import sys
5+ import _types
66
77# Iterators in Python aren't a matter of type but of protocol. A large
88# and changing number of builtin types implement *some* flavor of
@@ -14,7 +14,7 @@ def _f(): pass
1414LambdaType = type (lambda : None ) # Same as FunctionType
1515CodeType = type (_f .__code__ )
1616MappingProxyType = type (type .__dict__ )
17- SimpleNamespace = type ( sys . implementation )
17+ SimpleNamespace = _types . SimpleNamespace
1818
1919def _cell_factory ():
2020 a = 1
@@ -49,7 +49,7 @@ def _m(self): pass
4949MethodDescriptorType = type (str .join )
5050ClassMethodDescriptorType = type (dict .__dict__ ['fromkeys' ])
5151
52- ModuleType = type (sys )
52+ ModuleType = type (_types )
5353
5454try :
5555 raise TypeError
@@ -60,7 +60,9 @@ def _m(self): pass
6060GetSetDescriptorType = type (FunctionType .__code__ )
6161MemberDescriptorType = type (FunctionType .__globals__ )
6262
63- del sys , _f , _g , _C , _c , _ag , _cell_factory # Not for export
63+ CapsuleType = _types .CapsuleType
64+
65+ del _types , _f , _g , _C , _c , _ag , _cell_factory # Not for export
6466
6567
6668# Provide a PEP 3115 compliant mechanism for class creation
@@ -331,11 +333,4 @@ def wrapped(*args, **kwargs):
331333NoneType = type (None )
332334NotImplementedType = type (NotImplemented )
333335
334- def __getattr__ (name ):
335- if name == 'CapsuleType' :
336- import _socket
337- return type (_socket .CAPI )
338- raise AttributeError (f"module { __name__ !r} has no attribute { name !r} " )
339-
340- __all__ = [n for n in globals () if n [:1 ] != '_' ]
341- __all__ += ['CapsuleType' ]
336+ __all__ = [n for n in globals () if not n .startswith ('_' )] # for pydoc
0 commit comments