types - Define names for built-in types that aren't directly accessible as a builtin.
| Use Case | Command | Description |
|---|---|---|
| Check if an object is a function | isinstance(obj, types.FunctionType) | Test for user-defined functions |
| Check if an object is a lambda | isinstance(obj, types.LambdaType) | Alias for FunctionType |
| Create a coroutine | types.coroutine(gen_func) | Convert a generator function to an awaitable coroutine |
| Dynamically create a class | types.new_class(name, bases, kwds, exec_body) | Create a class object using the appropriate metaclass |
| Prepare a class namespace | types.prepare_class(name, bases, kwds) | Call __prepare__ of the metaclass, returns (metaclass, namespace, kwds) |
| Resolve MRO entries | types.resolve_bases(bases) | Resolve PEP 560 dynamic base classes |
| Wrap a dict as read-only | types.MappingProxyType(d) | Create a read-only view of a mapping |
| Create a simple namespace | types.SimpleNamespace(**kwargs) | Attribute-based namespace object |
| Represent a union type | int | str → types.UnionType | PEP 604 union type representation |
| Inspect a code object | types.CodeType(...) | Create or replace a code object |
https://docs.python.org/3.10/library/types.html
The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.
builtins.object
builtins.NoneType → types.NoneTypebuiltins.NotImplementedType → types.NotImplementedTypebuiltins.async_generator → types.AsyncGeneratorTypebuiltins.builtin_function_or_method → types.BuiltinFunctionType, types.BuiltinMethodTypebuiltins.cell → types.CellTypebuiltins.classmethod_descriptor → types.ClassMethodDescriptorTypebuiltins.code → types.CodeTypebuiltins.coroutine → types.CoroutineTypebuiltins.ellipsis → types.EllipsisTypebuiltins.frame → types.FrameTypebuiltins.function → types.FunctionType, types.LambdaTypebuiltins.generator → types.GeneratorTypebuiltins.getset_descriptor → types.GetSetDescriptorTypebuiltins.mappingproxy → types.MappingProxyTypebuiltins.member_descriptor → types.MemberDescriptorTypebuiltins.method → types.MethodTypebuiltins.method-wrapper → types.MethodWrapperTypebuiltins.method_descriptor → types.MethodDescriptorTypebuiltins.module → types.ModuleTypebuiltins.traceback → types.TracebackTypebuiltins.wrapper_descriptor → types.WrapperDescriptorTypeDynamicClassAttribute (descriptor)GenericAlias (PEP 585 generic)SimpleNamespaceUnionType (PEP 604 union)AsyncGeneratorType = class async_generator(object)
__aiter__(self, /) — Return an awaitable, that resolves in asynchronous iterator.__anext__(self, /) — Return a value or raise StopAsyncIteration.aclose(...) — aclose() -> raise GeneratorExit inside generator.asend(...) — asend(v) -> send 'v' in generator.athrow(...) — athrow(typ[,val[,tb]]) -> raise exception in generator.__class_getitem__(...) — See PEP 585 (class method)ag_await — object being awaited on, or Noneag_codeag_frameag_runningBuiltinFunctionType = class builtin_function_or_method(object)
__call__(self, /, *args, **kwargs) — Call self as a function.__eq__(self, value, /) — Return self==value.__ge__(self, value, /) — Return self>=value.__gt__(self, value, /) — Return self>value.__hash__(self, /) — Return hash(self).__le__(self, value, /) — Return self<=value.__lt__(self, value, /) — Return self<value.__ne__(self, value, /) — Return self!=value.__reduce__(...) — Helper for pickle.__repr__(self, /) — Return repr(self).__self__ (data descriptor)__text_signature__ (data descriptor)Same as BuiltinFunctionType (alias).
CellType = class cell(object) — Create a new cell object.
__new__(*args, **kwargs) — Create and return a new object. contents argument sets the cell contents.__eq__, __ge__, __gt__, __le__, __lt__, __ne__ — comparison operators__repr__ — Return repr(self).__hash__ = Nonecell_contents (data descriptor) — the contents of the cellClassMethodDescriptorType = class classmethod_descriptor(object)
__call__(self, /, *args, **kwargs) — Call self as a function.__get__(self, instance, owner=None, /) — Return an attribute of instance, which is of type owner.__repr__ — Return repr(self).__objclass__ (data descriptor)__text_signature__ (data descriptor)CodeType = class code(object)
CodeType(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, linetable, freevars=(), cellvars=(), /)
Create a code object. Not for the faint of heart.
replace(self, /, *, co_argcount=-1, ...) — Return a copy with new values for specified fields.co_lines(...)__sizeof__(...) — Size of object in memory, in bytes.__eq__, __ge__, __gt__, __le__, __lt__, __ne__, __hash__co_argcount, co_cellvars, co_code, co_consts, co_filename, co_firstlineno, co_flags, co_freevars, co_kwonlyargcount, co_linetable, co_lnotab, co_name, co_names, co_nlocals, co_posonlyargcount, co_stacksize, co_varnamesCoroutineType = class coroutine(object)
__await__(self, /) — Return an iterator to be used in await expression.close(...) — close() -> raise GeneratorExit inside coroutine.send(...) — send(arg) -> send 'arg' into coroutine, return next iterated value or raise StopIteration.throw(...) — throw(value) or throw(type[,value[,traceback]]) — Raise exception in coroutine, return next iterated value or raise StopIteration.cr_await (object being awaited on), cr_code, cr_frame, cr_origin, cr_runningDynamicClassAttribute(fget=None, fset=None, fdel=None, doc=None)
Route attribute access on a class to __getattr__. This is a descriptor, used to define attributes that act differently when accessed through an instance and through a class. Instance access remains normal, but access to an attribute through a class will be routed to the class's __getattr__ method; this is done by raising AttributeError.
This allows one to have properties active on an instance, and have virtual attributes on the class with the same name. (Enum used this between Python versions 3.4 - 3.9.)
Subclass from this to use a different method of accessing virtual atributes and still be treated properly by the inspect module. (Enum uses this since Python 3.10.)
__init__(self, fget=None, fset=None, fdel=None, doc=None) — Initialize self.__get__(self, instance, ownerclass=None)__set__(self, instance, value)__delete__(self, instance)deleter(self, fdel)getter(self, fget)setter(self, fset)__dict__ — dictionary for instance variables__weakref__ — list of weak referencesEllipsisType = class ellipsis(object)
__getattribute__(self, name, /) — Return getattr(self, name).__reduce__(...) — Helper for pickle.__repr__(self, /) — Return repr(self).FrameType = class frame(object)
clear(...) — F.clear(): clear most references held by the frame__delattr__, __setattr__ — attribute management__sizeof__ — F.__sizeof__() -> size of F in memory, in bytesf_back, f_builtins, f_code, f_globals, f_lasti, f_lineno, f_locals, f_trace, f_trace_lines, f_trace_opcodesFunctionType = class function(object)
FunctionType(code, globals, name=None, argdefs=None, closure=None)
Create a function object.
code — a code objectglobals — the globals dictionaryname — a string that overrides the name from the code objectargdefs — a tuple that specifies the default argument valuesclosure — a tuple that supplies the bindings for free variables__call__(self, /, *args, **kwargs) — Call self as a function.__get__(self, instance, owner=None, /) — Return an attribute of instance, which is of type owner.__repr__ — Return repr(self).__annotations__, __closure__, __code__, __defaults__, __dict__, __globals__, __kwdefaults__GeneratorType = class generator(object)
__iter__, __next__ — iterator protocolclose(...) — close() -> raise GeneratorExit inside generator.send(...) — send(arg) -> send 'arg' into generator, return next yielded value or raise StopIteration.throw(...) — throw(value) or throw(type[,value[,tb]]) — Raise exception in generator, return next yielded value or raise StopIteration.gi_code, gi_frame, gi_running, gi_yieldfrom (object being iterated by yield from, or None)GenericAlias — Represent a PEP 585 generic type
E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
__call__, __getitem__, __or__, __ror__ — operations__instancecheck__, __subclasscheck__ — type checking__mro_entries____reduce__, __repr____args__, __origin__, __parameters__ (Type variables in the GenericAlias)GetSetDescriptorType = class getset_descriptor(object)
__get__(self, instance, owner=None, /) — Return an attribute of instance, which is of type owner.__set__(self, instance, value, /) — Set an attribute of instance to value.__delete__(self, instance, /) — Delete an attribute of instance.__repr__ — Return repr(self).__objclass__ (data descriptor)Same as FunctionType (alias).
MappingProxyType = class mappingproxy(object) — A read-only view of a mapping.
__contains__, __getitem__, __iter__, __len__ — mapping protocol__or__, __ror__, __ior__ — union operators__reversed__ — D.__reversed__() -> reverse iteratorcopy() — D.copy() -> a shallow copy of Dget(k[,d]) — D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.items(), keys(), values() — view objects__class_getitem__ — See PEP 585 (class method)__hash__ = NoneMemberDescriptorType = class member_descriptor(object)
__get__, __set__, __delete__ — descriptor protocol__reduce__ — Helper for pickle.__repr__ — Return repr(self).__objclass__ (data descriptor)MethodDescriptorType = class method_descriptor(object)
__call__(self, /, *args, **kwargs) — Call self as a function.__get__(self, instance, owner=None, /) — Return an attribute of instance, which is of type owner.__reduce__, __repr____objclass__, __text_signature__MethodType = class method(object)
method(function, instance)
Create a bound instance method object.
__call__ — Call self as a function.__get__ — Return an attribute of instance, which is of type owner.__eq__, __ge__, __gt__, __le__, __lt__, __ne__, __hash__ — comparison operators__reduce__, __repr____func__ — the function (or other callable) implementing a method__self__ — the instance to which a method is boundMethodWrapperType = class method-wrapper(object)
__call__(self, /, *args, **kwargs) — Call self as a function.__eq__, __ge__, __gt__, __le__, __lt__, __ne__, __hash__ — comparison__reduce__, __repr____objclass__, __self__, __text_signature__ModuleType = class module(object)
ModuleType(name, doc=None)
Create a module object. The name must be a string; the optional doc argument can have any type.
__init__(self, /, *args, **kwargs) — Initialize self.__dir__() — specialized dir() implementation__delattr__, __setattr__ — attribute management__repr__ — Return repr(self).__annotations__, __dict__ (data descriptors)NoneType = class NoneType(object) — The type of None.
__bool__(self, /) — True if self else False (always False)__repr__ — Return repr(self).NotImplementedType = class NotImplementedType(object) — The type of NotImplemented.
__bool__ — True if self else False (always True)__reduce__, __repr__SimpleNamespace(**kwargs) — A simple attribute-based namespace.
__init__(self, /, *args, **kwargs) — Initialize self.__delattr__, __setattr__ — attribute management__eq__, __ge__, __gt__, __le__, __lt__, __ne__ — comparison operators__reduce__ — Return state information for pickling__repr__ — Return repr(self).__dict__ (data descriptor)__hash__ = NoneTracebackType = class traceback(object)
TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
Create a new traceback object.
__dir__ — Default dir() implementation.__getattribute__ — Return getattr(self, name).tb_frame, tb_lasti, tb_lineno, tb_nextUnionType — Represent a PEP 604 union type
E.g. for int | str.
__eq__, __ge__, __gt__, __le__, __lt__, __ne__, __hash__ — comparison__getitem__, __or__, __ror__ — operations__instancecheck__, __subclasscheck__ — type checking__repr__ — Return repr(self).__args__, __parameters__ (Type variables in the types.UnionType)WrapperDescriptorType = class wrapper_descriptor(object)
__call__(self, /, *args, **kwargs) — Call self as a function.__get__(self, instance, owner=None, /) — Return an attribute of instance, which is of type owner.__reduce__, __repr____objclass__, __text_signature__coroutine(func)
Convert regular generator function to a coroutine.
new_class(name, bases=(), kwds=None, exec_body=None)
Create a class object dynamically using the appropriate metaclass.
prepare_class(name, bases=(), kwds=None)
Call the __prepare__ method of the appropriate metaclass.
Returns (metaclass, namespace, kwds) as a 3-tuple
resolve_bases(bases)
Resolve MRO entries dynamically as specified by PEP 560.
__all__ = ['FunctionType', 'LambdaType', 'CodeType', 'MappingProxyType', 'SimpleNamespace', 'GenericAlias', 'UnionType', 'DynamicClassAttribute', 'coroutine', 'new_class', 'prepare_class', 'resolve_bases']
/usr/lib/python3.10/types.py
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 16:11 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format