summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Ftypes.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/python~3.12/library%2Ftypes.html')
-rw-r--r--devdocs/python~3.12/library%2Ftypes.html200
1 files changed, 200 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Ftypes.html b/devdocs/python~3.12/library%2Ftypes.html
new file mode 100644
index 00000000..1e51ac44
--- /dev/null
+++ b/devdocs/python~3.12/library%2Ftypes.html
@@ -0,0 +1,200 @@
+ <span id="types-dynamic-type-creation-and-names-for-built-in-types"></span><h1>types — Dynamic type creation and names for built-in types</h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/types.py">Lib/types.py</a></p> <p>This module defines utility functions to assist in dynamic creation of new types.</p> <p>It also defines names for some object types that are used by the standard Python interpreter, but not exposed as builtins like <a class="reference internal" href="functions#int" title="int"><code>int</code></a> or <a class="reference internal" href="stdtypes#str" title="str"><code>str</code></a> are.</p> <p>Finally, it provides some additional type-related utility classes and functions that are not fundamental enough to be builtins.</p> <section id="dynamic-type-creation"> <h2>Dynamic Type Creation</h2> <dl class="py function"> <dt class="sig sig-object py" id="types.new_class">
+<code>types.new_class(name, bases=(), kwds=None, exec_body=None)</code> </dt> <dd>
+<p>Creates a class object dynamically using the appropriate metaclass.</p> <p>The first three arguments are the components that make up a class definition header: the class name, the base classes (in order), the keyword arguments (such as <code>metaclass</code>).</p> <p>The <em>exec_body</em> argument is a callback that is used to populate the freshly created class namespace. It should accept the class namespace as its sole argument and update the namespace directly with the class contents. If no callback is provided, it has the same effect as passing in <code>lambda ns: None</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="types.prepare_class">
+<code>types.prepare_class(name, bases=(), kwds=None)</code> </dt> <dd>
+<p>Calculates the appropriate metaclass and creates the class namespace.</p> <p>The arguments are the components that make up a class definition header: the class name, the base classes (in order) and the keyword arguments (such as <code>metaclass</code>).</p> <p>The return value is a 3-tuple: <code>metaclass, namespace, kwds</code></p> <p><em>metaclass</em> is the appropriate metaclass, <em>namespace</em> is the prepared class namespace and <em>kwds</em> is an updated copy of the passed in <em>kwds</em> argument with any <code>'metaclass'</code> entry removed. If no <em>kwds</em> argument is passed in, this will be an empty dict.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.6: </span>The default value for the <code>namespace</code> element of the returned tuple has changed. Now an insertion-order-preserving mapping is used when the metaclass does not have a <code>__prepare__</code> method.</p> </div> </dd>
+</dl> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt><a class="reference internal" href="../reference/datamodel#metaclasses"><span class="std std-ref">Metaclasses</span></a></dt>
+<dd>
+<p>Full details of the class creation process supported by these functions</p> </dd> <dt>
+<span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-3115/"><strong>PEP 3115</strong></a> - Metaclasses in Python 3000</dt>
+<dd>
+<p>Introduced the <code>__prepare__</code> namespace hook</p> </dd> </dl> </div> <dl class="py function"> <dt class="sig sig-object py" id="types.resolve_bases">
+<code>types.resolve_bases(bases)</code> </dt> <dd>
+<p>Resolve MRO entries dynamically as specified by <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0560/"><strong>PEP 560</strong></a>.</p> <p>This function looks for items in <em>bases</em> that are not instances of <a class="reference internal" href="functions#type" title="type"><code>type</code></a>, and returns a tuple where each such object that has an <a class="reference internal" href="../reference/datamodel#object.__mro_entries__" title="object.__mro_entries__"><code>__mro_entries__()</code></a> method is replaced with an unpacked result of calling this method. If a <em>bases</em> item is an instance of <a class="reference internal" href="functions#type" title="type"><code>type</code></a>, or it doesn’t have an <code>__mro_entries__()</code> method, then it is included in the return tuple unchanged.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="types.get_original_bases">
+<code>types.get_original_bases(cls, /)</code> </dt> <dd>
+<p>Return the tuple of objects originally given as the bases of <em>cls</em> before the <a class="reference internal" href="../reference/datamodel#object.__mro_entries__" title="object.__mro_entries__"><code>__mro_entries__()</code></a> method has been called on any bases (following the mechanisms laid out in <span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0560/"><strong>PEP 560</strong></a>). This is useful for introspecting <a class="reference internal" href="typing#user-defined-generics"><span class="std std-ref">Generics</span></a>.</p> <p>For classes that have an <code>__orig_bases__</code> attribute, this function returns the value of <code>cls.__orig_bases__</code>. For classes without the <code>__orig_bases__</code> attribute, <code>cls.__bases__</code> is returned.</p> <p>Examples:</p> <pre data-language="python">from typing import TypeVar, Generic, NamedTuple, TypedDict
+
+T = TypeVar("T")
+class Foo(Generic[T]): ...
+class Bar(Foo[int], float): ...
+class Baz(list[str]): ...
+Eggs = NamedTuple("Eggs", [("a", int), ("b", str)])
+Spam = TypedDict("Spam", {"a": int, "b": str})
+
+assert Bar.__bases__ == (Foo, float)
+assert get_original_bases(Bar) == (Foo[int], float)
+
+assert Baz.__bases__ == (list,)
+assert get_original_bases(Baz) == (list[str],)
+
+assert Eggs.__bases__ == (tuple,)
+assert get_original_bases(Eggs) == (NamedTuple,)
+
+assert Spam.__bases__ == (dict,)
+assert get_original_bases(Spam) == (TypedDict,)
+
+assert int.__bases__ == (object,)
+assert get_original_bases(int) == (object,)
+</pre> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.12.</span></p> </div> </dd>
+</dl> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0560/"><strong>PEP 560</strong></a> - Core support for typing module and generic types</p> </div> </section> <section id="standard-interpreter-types"> <h2>Standard Interpreter Types</h2> <p>This module provides names for many of the types that are required to implement a Python interpreter. It deliberately avoids including some of the types that arise only incidentally during processing such as the <code>listiterator</code> type.</p> <p>Typical use of these names is for <a class="reference internal" href="functions#isinstance" title="isinstance"><code>isinstance()</code></a> or <a class="reference internal" href="functions#issubclass" title="issubclass"><code>issubclass()</code></a> checks.</p> <p>If you instantiate any of these types, note that signatures may vary between Python versions.</p> <p>Standard names are defined for the following types:</p> <dl class="py data"> <dt class="sig sig-object py" id="types.NoneType">
+<code>types.NoneType</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="constants#None" title="None"><code>None</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.FunctionType">
+<code>types.FunctionType</code> </dt> <dt class="sig sig-object py" id="types.LambdaType">
+<code>types.LambdaType</code> </dt> <dd>
+<p>The type of user-defined functions and functions created by <a class="reference internal" href="../reference/expressions#lambda"><code>lambda</code></a> expressions.</p> <p class="audit-hook">Raises an <a class="reference internal" href="sys#auditing"><span class="std std-ref">auditing event</span></a> <code>function.__new__</code> with argument <code>code</code>.</p> <p>The audit event only occurs for direct instantiation of function objects, and is not raised for normal compilation.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.GeneratorType">
+<code>types.GeneratorType</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="../glossary#term-generator"><span class="xref std std-term">generator</span></a>-iterator objects, created by generator functions.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.CoroutineType">
+<code>types.CoroutineType</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="../glossary#term-coroutine"><span class="xref std std-term">coroutine</span></a> objects, created by <a class="reference internal" href="../reference/compound_stmts#async-def"><code>async def</code></a> functions.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.AsyncGeneratorType">
+<code>types.AsyncGeneratorType</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="../glossary#term-asynchronous-generator"><span class="xref std std-term">asynchronous generator</span></a>-iterator objects, created by asynchronous generator functions.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.6.</span></p> </div> </dd>
+</dl> <dl class="py class"> <dt class="sig sig-object py" id="types.CodeType">
+<code>class types.CodeType(**kwargs)</code> </dt> <dd>
+<p id="index-4">The type for code objects such as returned by <a class="reference internal" href="functions#compile" title="compile"><code>compile()</code></a>.</p> <p class="audit-hook">Raises an <a class="reference internal" href="sys#auditing"><span class="std std-ref">auditing event</span></a> <code>code.__new__</code> with arguments <code>code</code>, <code>filename</code>, <code>name</code>, <code>argcount</code>, <code>posonlyargcount</code>, <code>kwonlyargcount</code>, <code>nlocals</code>, <code>stacksize</code>, <code>flags</code>.</p> <p>Note that the audited arguments may not match the names or positions required by the initializer. The audit event only occurs for direct instantiation of code objects, and is not raised for normal compilation.</p> <dl class="py method"> <dt class="sig sig-object py" id="types.CodeType.replace">
+<code>replace(**kwargs)</code> </dt> <dd>
+<p>Return a copy of the code object with new values for the specified fields.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd>
+</dl> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.CellType">
+<code>types.CellType</code> </dt> <dd>
+<p>The type for cell objects: such objects are used as containers for a function’s free variables.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.MethodType">
+<code>types.MethodType</code> </dt> <dd>
+<p>The type of methods of user-defined class instances.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.BuiltinFunctionType">
+<code>types.BuiltinFunctionType</code> </dt> <dt class="sig sig-object py" id="types.BuiltinMethodType">
+<code>types.BuiltinMethodType</code> </dt> <dd>
+<p>The type of built-in functions like <a class="reference internal" href="functions#len" title="len"><code>len()</code></a> or <a class="reference internal" href="sys#sys.exit" title="sys.exit"><code>sys.exit()</code></a>, and methods of built-in classes. (Here, the term “built-in” means “written in C”.)</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.WrapperDescriptorType">
+<code>types.WrapperDescriptorType</code> </dt> <dd>
+<p>The type of methods of some built-in data types and base classes such as <a class="reference internal" href="../reference/datamodel#object.__init__" title="object.__init__"><code>object.__init__()</code></a> or <a class="reference internal" href="../reference/datamodel#object.__lt__" title="object.__lt__"><code>object.__lt__()</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.MethodWrapperType">
+<code>types.MethodWrapperType</code> </dt> <dd>
+<p>The type of <em>bound</em> methods of some built-in data types and base classes. For example it is the type of <code>object().__str__</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.NotImplementedType">
+<code>types.NotImplementedType</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="constants#NotImplemented" title="NotImplemented"><code>NotImplemented</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.MethodDescriptorType">
+<code>types.MethodDescriptorType</code> </dt> <dd>
+<p>The type of methods of some built-in data types such as <a class="reference internal" href="stdtypes#str.join" title="str.join"><code>str.join()</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.ClassMethodDescriptorType">
+<code>types.ClassMethodDescriptorType</code> </dt> <dd>
+<p>The type of <em>unbound</em> class methods of some built-in data types such as <code>dict.__dict__['fromkeys']</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> </dd>
+</dl> <dl class="py class"> <dt class="sig sig-object py" id="types.ModuleType">
+<code>class types.ModuleType(name, doc=None)</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="../glossary#term-module"><span class="xref std std-term">modules</span></a>. The constructor takes the name of the module to be created and optionally its <a class="reference internal" href="../glossary#term-docstring"><span class="xref std std-term">docstring</span></a>.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Use <a class="reference internal" href="importlib#importlib.util.module_from_spec" title="importlib.util.module_from_spec"><code>importlib.util.module_from_spec()</code></a> to create a new module if you wish to set the various import-controlled attributes.</p> </div> <dl class="py attribute"> <dt class="sig sig-object py" id="types.ModuleType.__doc__">
+<code>__doc__</code> </dt> <dd>
+<p>The <a class="reference internal" href="../glossary#term-docstring"><span class="xref std std-term">docstring</span></a> of the module. Defaults to <code>None</code>.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="types.ModuleType.__loader__">
+<code>__loader__</code> </dt> <dd>
+<p>The <a class="reference internal" href="../glossary#term-loader"><span class="xref std std-term">loader</span></a> which loaded the module. Defaults to <code>None</code>.</p> <p>This attribute is to match <a class="reference internal" href="importlib#importlib.machinery.ModuleSpec.loader" title="importlib.machinery.ModuleSpec.loader"><code>importlib.machinery.ModuleSpec.loader</code></a> as stored in the <a class="reference internal" href="../reference/import#spec__" title="__spec__"><code>__spec__</code></a> object.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>A future version of Python may stop setting this attribute by default. To guard against this potential change, preferably read from the <a class="reference internal" href="../reference/import#spec__" title="__spec__"><code>__spec__</code></a> attribute instead or use <code>getattr(module, "__loader__", None)</code> if you explicitly need to use this attribute.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.4: </span>Defaults to <code>None</code>. Previously the attribute was optional.</p> </div> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="types.ModuleType.__name__">
+<code>__name__</code> </dt> <dd>
+<p>The name of the module. Expected to match <a class="reference internal" href="importlib#importlib.machinery.ModuleSpec.name" title="importlib.machinery.ModuleSpec.name"><code>importlib.machinery.ModuleSpec.name</code></a>.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="types.ModuleType.__package__">
+<code>__package__</code> </dt> <dd>
+<p>Which <a class="reference internal" href="../glossary#term-package"><span class="xref std std-term">package</span></a> a module belongs to. If the module is top-level (i.e. not a part of any specific package) then the attribute should be set to <code>''</code>, else it should be set to the name of the package (which can be <a class="reference internal" href="../reference/import#name__" title="__name__"><code>__name__</code></a> if the module is a package itself). Defaults to <code>None</code>.</p> <p>This attribute is to match <a class="reference internal" href="importlib#importlib.machinery.ModuleSpec.parent" title="importlib.machinery.ModuleSpec.parent"><code>importlib.machinery.ModuleSpec.parent</code></a> as stored in the <a class="reference internal" href="../reference/import#spec__" title="__spec__"><code>__spec__</code></a> object.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>A future version of Python may stop setting this attribute by default. To guard against this potential change, preferably read from the <a class="reference internal" href="../reference/import#spec__" title="__spec__"><code>__spec__</code></a> attribute instead or use <code>getattr(module, "__package__", None)</code> if you explicitly need to use this attribute.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.4: </span>Defaults to <code>None</code>. Previously the attribute was optional.</p> </div> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="types.ModuleType.__spec__">
+<code>__spec__</code> </dt> <dd>
+<p>A record of the module’s import-system-related state. Expected to be an instance of <a class="reference internal" href="importlib#importlib.machinery.ModuleSpec" title="importlib.machinery.ModuleSpec"><code>importlib.machinery.ModuleSpec</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.EllipsisType">
+<code>types.EllipsisType</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="constants#Ellipsis" title="Ellipsis"><code>Ellipsis</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd>
+</dl> <dl class="py class"> <dt class="sig sig-object py" id="types.GenericAlias">
+<code>class types.GenericAlias(t_origin, t_args)</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="stdtypes#types-genericalias"><span class="std std-ref">parameterized generics</span></a> such as <code>list[int]</code>.</p> <p><code>t_origin</code> should be a non-parameterized generic class, such as <code>list</code>, <code>tuple</code> or <code>dict</code>. <code>t_args</code> should be a <a class="reference internal" href="stdtypes#tuple" title="tuple"><code>tuple</code></a> (possibly of length 1) of types which parameterize <code>t_origin</code>:</p> <pre data-language="python">&gt;&gt;&gt; from types import GenericAlias
+
+&gt;&gt;&gt; list[int] == GenericAlias(list, (int,))
+True
+&gt;&gt;&gt; dict[str, int] == GenericAlias(dict, (str, int))
+True
+</pre> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.9.2: </span>This type can now be subclassed.</p> </div> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt><a class="reference internal" href="stdtypes#types-genericalias"><span class="std std-ref">Generic Alias Types</span></a></dt>
+<dd>
+<p>In-depth documentation on instances of <code>types.GenericAlias</code></p> </dd> <dt>
+<span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0585/"><strong>PEP 585</strong></a> - Type Hinting Generics In Standard Collections</dt>
+<dd>
+<p>Introducing the <code>types.GenericAlias</code> class</p> </dd> </dl> </div> </dd>
+</dl> <dl class="py class"> <dt class="sig sig-object py" id="types.UnionType">
+<code>class types.UnionType</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="stdtypes#types-union"><span class="std std-ref">union type expressions</span></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd>
+</dl> <dl class="py class"> <dt class="sig sig-object py" id="types.TracebackType">
+<code>class types.TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)</code> </dt> <dd>
+<p>The type of traceback objects such as found in <code>sys.exception().__traceback__</code>.</p> <p>See <a class="reference internal" href="../reference/datamodel#traceback-objects"><span class="std std-ref">the language reference</span></a> for details of the available attributes and operations, and guidance on creating tracebacks dynamically.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.FrameType">
+<code>types.FrameType</code> </dt> <dd>
+<p>The type of <a class="reference internal" href="../reference/datamodel#frame-objects"><span class="std std-ref">frame objects</span></a> such as found in <a class="reference internal" href="../reference/datamodel#traceback.tb_frame" title="traceback.tb_frame"><code>tb.tb_frame</code></a> if <code>tb</code> is a traceback object.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.GetSetDescriptorType">
+<code>types.GetSetDescriptorType</code> </dt> <dd>
+<p>The type of objects defined in extension modules with <code>PyGetSetDef</code>, such as <a class="reference internal" href="../reference/datamodel#frame.f_locals" title="frame.f_locals"><code>FrameType.f_locals</code></a> or <code>array.array.typecode</code>. This type is used as descriptor for object attributes; it has the same purpose as the <a class="reference internal" href="functions#property" title="property"><code>property</code></a> type, but for classes defined in extension modules.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="types.MemberDescriptorType">
+<code>types.MemberDescriptorType</code> </dt> <dd>
+<p>The type of objects defined in extension modules with <code>PyMemberDef</code>, such as <code>datetime.timedelta.days</code>. This type is used as descriptor for simple C data members which use standard conversion functions; it has the same purpose as the <a class="reference internal" href="functions#property" title="property"><code>property</code></a> type, but for classes defined in extension modules.</p> <div class="impl-detail compound"> <p><strong>CPython implementation detail:</strong> In other implementations of Python, this type may be identical to <code>GetSetDescriptorType</code>.</p> </div> </dd>
+</dl> <dl class="py class"> <dt class="sig sig-object py" id="types.MappingProxyType">
+<code>class types.MappingProxyType(mapping)</code> </dt> <dd>
+<p>Read-only proxy of a mapping. It provides a dynamic view on the mapping’s entries, which means that when the mapping changes, the view reflects these changes.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.9: </span>Updated to support the new union (<code>|</code>) operator from <span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0584/"><strong>PEP 584</strong></a>, which simply delegates to the underlying mapping.</p> </div> <dl class="describe"> <dt class="sig sig-object"> <span class="sig-name descname">key in proxy</span>
+</dt> <dd>
+<p>Return <code>True</code> if the underlying mapping has a key <em>key</em>, else <code>False</code>.</p> </dd>
+</dl> <dl class="describe"> <dt class="sig sig-object"> <span class="sig-name descname">proxy[key]</span>
+</dt> <dd>
+<p>Return the item of the underlying mapping with key <em>key</em>. Raises a <a class="reference internal" href="exceptions#KeyError" title="KeyError"><code>KeyError</code></a> if <em>key</em> is not in the underlying mapping.</p> </dd>
+</dl> <dl class="describe"> <dt class="sig sig-object"> <span class="sig-name descname">iter(proxy)</span>
+</dt> <dd>
+<p>Return an iterator over the keys of the underlying mapping. This is a shortcut for <code>iter(proxy.keys())</code>.</p> </dd>
+</dl> <dl class="describe"> <dt class="sig sig-object"> <span class="sig-name descname">len(proxy)</span>
+</dt> <dd>
+<p>Return the number of items in the underlying mapping.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="types.MappingProxyType.copy">
+<code>copy()</code> </dt> <dd>
+<p>Return a shallow copy of the underlying mapping.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="types.MappingProxyType.get">
+<code>get(key[, default])</code> </dt> <dd>
+<p>Return the value for <em>key</em> if <em>key</em> is in the underlying mapping, else <em>default</em>. If <em>default</em> is not given, it defaults to <code>None</code>, so that this method never raises a <a class="reference internal" href="exceptions#KeyError" title="KeyError"><code>KeyError</code></a>.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="types.MappingProxyType.items">
+<code>items()</code> </dt> <dd>
+<p>Return a new view of the underlying mapping’s items (<code>(key, value)</code> pairs).</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="types.MappingProxyType.keys">
+<code>keys()</code> </dt> <dd>
+<p>Return a new view of the underlying mapping’s keys.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="types.MappingProxyType.values">
+<code>values()</code> </dt> <dd>
+<p>Return a new view of the underlying mapping’s values.</p> </dd>
+</dl> <dl class="describe"> <dt class="sig sig-object"> <span class="sig-name descname">reversed(proxy)</span>
+</dt> <dd>
+<p>Return a reverse iterator over the keys of the underlying mapping.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd>
+</dl> <dl class="describe"> <dt class="sig sig-object"> <span class="sig-name descname">hash(proxy)</span>
+</dt> <dd>
+<p>Return a hash of the underlying mapping.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.12.</span></p> </div> </dd>
+</dl> </dd>
+</dl> </section> <section id="additional-utility-classes-and-functions"> <h2>Additional Utility Classes and Functions</h2> <dl class="py class"> <dt class="sig sig-object py" id="types.SimpleNamespace">
+<code>class types.SimpleNamespace</code> </dt> <dd>
+<p>A simple <a class="reference internal" href="functions#object" title="object"><code>object</code></a> subclass that provides attribute access to its namespace, as well as a meaningful repr.</p> <p>Unlike <a class="reference internal" href="functions#object" title="object"><code>object</code></a>, with <code>SimpleNamespace</code> you can add and remove attributes. If a <code>SimpleNamespace</code> object is initialized with keyword arguments, those are directly added to the underlying namespace.</p> <p>The type is roughly equivalent to the following code:</p> <pre data-language="python">class SimpleNamespace:
+ def __init__(self, /, **kwargs):
+ self.__dict__.update(kwargs)
+
+ def __repr__(self):
+ items = (f"{k}={v!r}" for k, v in self.__dict__.items())
+ return "{}({})".format(type(self).__name__, ", ".join(items))
+
+ def __eq__(self, other):
+ if isinstance(self, SimpleNamespace) and isinstance(other, SimpleNamespace):
+ return self.__dict__ == other.__dict__
+ return NotImplemented
+</pre> <p><code>SimpleNamespace</code> may be useful as a replacement for <code>class NS: pass</code>. However, for a structured record type use <a class="reference internal" href="collections#collections.namedtuple" title="collections.namedtuple"><code>namedtuple()</code></a> instead.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.9: </span>Attribute order in the repr changed from alphabetical to insertion (like <code>dict</code>).</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="types.DynamicClassAttribute">
+<code>types.DynamicClassAttribute(fget=None, fset=None, fdel=None, doc=None)</code> </dt> <dd>
+<p>Route attribute access on a class to __getattr__.</p> <p>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.</p> <p>This allows one to have properties active on an instance, and have virtual attributes on the class with the same name (see <a class="reference internal" href="enum#enum.Enum" title="enum.Enum"><code>enum.Enum</code></a> for an example).</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> </section> <section id="coroutine-utility-functions"> <h2>Coroutine Utility Functions</h2> <dl class="py function"> <dt class="sig sig-object py" id="types.coroutine">
+<code>types.coroutine(gen_func)</code> </dt> <dd>
+<p>This function transforms a <a class="reference internal" href="../glossary#term-generator"><span class="xref std std-term">generator</span></a> function into a <a class="reference internal" href="../glossary#term-coroutine-function"><span class="xref std std-term">coroutine function</span></a> which returns a generator-based coroutine. The generator-based coroutine is still a <a class="reference internal" href="../glossary#term-generator-iterator"><span class="xref std std-term">generator iterator</span></a>, but is also considered to be a <a class="reference internal" href="../glossary#term-coroutine"><span class="xref std std-term">coroutine</span></a> object and is <a class="reference internal" href="../glossary#term-awaitable"><span class="xref std std-term">awaitable</span></a>. However, it may not necessarily implement the <a class="reference internal" href="../reference/datamodel#object.__await__" title="object.__await__"><code>__await__()</code></a> method.</p> <p>If <em>gen_func</em> is a generator function, it will be modified in-place.</p> <p>If <em>gen_func</em> is not a generator function, it will be wrapped. If it returns an instance of <a class="reference internal" href="collections.abc#collections.abc.Generator" title="collections.abc.Generator"><code>collections.abc.Generator</code></a>, the instance will be wrapped in an <em>awaitable</em> proxy object. All other types of objects will be returned as is.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd>
+</dl> </section> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
+ <a href="https://docs.python.org/3.12/library/types.html" class="_attribution-link">https://docs.python.org/3.12/library/types.html</a>
+ </p>
+</div>