summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/c-api%2Ftypehints.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/python~3.12/c-api%2Ftypehints.html
new repository
Diffstat (limited to 'devdocs/python~3.12/c-api%2Ftypehints.html')
-rw-r--r--devdocs/python~3.12/c-api%2Ftypehints.html19
1 files changed, 19 insertions, 0 deletions
diff --git a/devdocs/python~3.12/c-api%2Ftypehints.html b/devdocs/python~3.12/c-api%2Ftypehints.html
new file mode 100644
index 00000000..8ba681f1
--- /dev/null
+++ b/devdocs/python~3.12/c-api%2Ftypehints.html
@@ -0,0 +1,19 @@
+ <span id="typehintobjects"></span><h1>Objects for Type Hinting</h1> <p>Various built-in types for type hinting are provided. Currently, two types exist – <a class="reference internal" href="../library/stdtypes#types-genericalias"><span class="std std-ref">GenericAlias</span></a> and <a class="reference internal" href="../library/stdtypes#types-union"><span class="std std-ref">Union</span></a>. Only <code>GenericAlias</code> is exposed to C.</p> <dl class="c function"> <dt class="sig sig-object c" id="c.Py_GenericAlias">
+<code>PyObject *Py_GenericAlias(PyObject *origin, PyObject *args)</code> </dt> <dd>
+<em class="stableabi"> Part of the <a class="reference internal" href="stable#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.9.</em><p>Create a <a class="reference internal" href="../library/stdtypes#types-genericalias"><span class="std std-ref">GenericAlias</span></a> object. Equivalent to calling the Python class <a class="reference internal" href="../library/types#types.GenericAlias" title="types.GenericAlias"><code>types.GenericAlias</code></a>. The <em>origin</em> and <em>args</em> arguments set the <code>GenericAlias</code>‘s <code>__origin__</code> and <code>__args__</code> attributes respectively. <em>origin</em> should be a <span class="c-expr sig sig-inline c"><a class="reference internal" href="type#c.PyTypeObject" title="PyTypeObject"><span class="n">PyTypeObject</span></a><span class="p">*</span></span>, and <em>args</em> can be a <span class="c-expr sig sig-inline c"><a class="reference internal" href="tuple#c.PyTupleObject" title="PyTupleObject"><span class="n">PyTupleObject</span></a><span class="p">*</span></span> or any <code>PyObject*</code>. If <em>args</em> passed is not a tuple, a 1-tuple is automatically constructed and <code>__args__</code> is set to <code>(args,)</code>. Minimal checking is done for the arguments, so the function will succeed even if <em>origin</em> is not a type. The <code>GenericAlias</code>‘s <code>__parameters__</code> attribute is constructed lazily from <code>__args__</code>. On failure, an exception is raised and <code>NULL</code> is returned.</p> <p>Here’s an example of how to make an extension type generic:</p> <pre data-language="c">...
+static PyMethodDef my_obj_methods[] = {
+ // Other methods.
+ ...
+ {"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, "See PEP 585"}
+ ...
+}
+</pre> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p>The data model method <a class="reference internal" href="../reference/datamodel#object.__class_getitem__" title="object.__class_getitem__"><code>__class_getitem__()</code></a>.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd>
+</dl> <dl class="c var"> <dt class="sig sig-object c" id="c.Py_GenericAliasType">
+<code>PyTypeObject Py_GenericAliasType</code> </dt> <dd>
+<em class="stableabi"> Part of the <a class="reference internal" href="stable#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.9.</em><p>The C type of the object returned by <a class="reference internal" href="#c.Py_GenericAlias" title="Py_GenericAlias"><code>Py_GenericAlias()</code></a>. Equivalent to <a class="reference internal" href="../library/types#types.GenericAlias" title="types.GenericAlias"><code>types.GenericAlias</code></a> in Python.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd>
+</dl> <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/c-api/typehints.html" class="_attribution-link">https://docs.python.org/3.12/c-api/typehints.html</a>
+ </p>
+</div>