CINXE.COM

PEP 473 – Adding structured data to built-in exceptions | peps.python.org

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="color-scheme" content="light dark"> <title>PEP 473 – Adding structured data to built-in exceptions | peps.python.org</title> <link rel="shortcut icon" href="../_static/py.png"> <link rel="canonical" href="https://peps.python.org/pep-0473/"> <link rel="stylesheet" href="../_static/style.css" type="text/css"> <link rel="stylesheet" href="../_static/mq.css" type="text/css"> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" media="(prefers-color-scheme: light)" id="pyg-light"> <link rel="stylesheet" href="../_static/pygments_dark.css" type="text/css" media="(prefers-color-scheme: dark)" id="pyg-dark"> <link rel="alternate" type="application/rss+xml" title="Latest PEPs" href="https://peps.python.org/peps.rss"> <meta property="og:title" content='PEP 473 – Adding structured data to built-in exceptions | peps.python.org'> <meta property="og:description" content="Exceptions like AttributeError, IndexError, KeyError, LookupError, NameError, TypeError, and ValueError do not provide all information required by programmers to debug and better understand what caused them. Furthermore, in some cases the messages even ..."> <meta property="og:type" content="website"> <meta property="og:url" content="https://peps.python.org/pep-0473/"> <meta property="og:site_name" content="Python Enhancement Proposals (PEPs)"> <meta property="og:image" content="https://peps.python.org/_static/og-image.png"> <meta property="og:image:alt" content="Python PEPs"> <meta property="og:image:width" content="200"> <meta property="og:image:height" content="200"> <meta name="description" content="Exceptions like AttributeError, IndexError, KeyError, LookupError, NameError, TypeError, and ValueError do not provide all information required by programmers to debug and better understand what caused them. Furthermore, in some cases the messages even ..."> <meta name="theme-color" content="#3776ab"> </head> <body> <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> <symbol id="svg-sun-half" viewBox="0 0 24 24" pointer-events="all"> <title>Following system colour scheme</title> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <circle cx="12" cy="12" r="9"></circle> <path d="M12 3v18m0-12l4.65-4.65M12 14.3l7.37-7.37M12 19.6l8.85-8.85"></path> </svg> </symbol> <symbol id="svg-moon" viewBox="0 0 24 24" pointer-events="all"> <title>Selected dark colour scheme</title> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z"></path> </svg> </symbol> <symbol id="svg-sun" viewBox="0 0 24 24" pointer-events="all"> <title>Selected light colour scheme</title> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <circle cx="12" cy="12" r="5"></circle> <line x1="12" y1="1" x2="12" y2="3"></line> <line x1="12" y1="21" x2="12" y2="23"></line> <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line> <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line> <line x1="1" y1="12" x2="3" y2="12"></line> <line x1="21" y1="12" x2="23" y2="12"></line> <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line> <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line> </svg> </symbol> </svg> <script> document.documentElement.dataset.colour_scheme = localStorage.getItem("colour_scheme") || "auto" </script> <section id="pep-page-section"> <header> <h1>Python Enhancement Proposals</h1> <ul class="breadcrumbs"> <li><a href="https://www.python.org/" title="The Python Programming Language">Python</a> &raquo; </li> <li><a href="../pep-0000/">PEP Index</a> &raquo; </li> <li>PEP 473</li> </ul> <button id="colour-scheme-cycler" onClick="setColourScheme(nextColourScheme())"> <svg aria-hidden="true" class="colour-scheme-icon-when-auto"><use href="#svg-sun-half"></use></svg> <svg aria-hidden="true" class="colour-scheme-icon-when-dark"><use href="#svg-moon"></use></svg> <svg aria-hidden="true" class="colour-scheme-icon-when-light"><use href="#svg-sun"></use></svg> <span class="visually-hidden">Toggle light / dark / auto colour theme</span> </button> </header> <article> <section id="pep-content"> <h1 class="page-title">PEP 473 – Adding structured data to built-in exceptions</h1> <dl class="rfc2822 field-list simple"> <dt class="field-odd">Author<span class="colon">:</span></dt> <dd class="field-odd">Sebastian Kreft &lt;skreft&#32;&#97;t&#32;deezer.com&gt;</dd> <dt class="field-even">Status<span class="colon">:</span></dt> <dd class="field-even"><abbr title="Formally declined and will not be accepted">Rejected</abbr></dd> <dt class="field-odd">Type<span class="colon">:</span></dt> <dd class="field-odd"><abbr title="Normative PEP with a new feature for Python, implementation change for CPython or interoperability standard for the ecosystem">Standards Track</abbr></dd> <dt class="field-even">Created<span class="colon">:</span></dt> <dd class="field-even">29-Mar-2014</dd> <dt class="field-odd">Post-History<span class="colon">:</span></dt> <dd class="field-odd"><p></p></dd> <dt class="field-even">Resolution<span class="colon">:</span></dt> <dd class="field-even"><a class="reference external" href="https://mail.python.org/pipermail/python-dev/2019-March/156692.html">Python-Dev message</a></dd> </dl> <hr class="docutils" /> <section id="contents"> <details><summary>Table of Contents</summary><ul class="simple"> <li><a class="reference internal" href="#abstract">Abstract</a></li> <li><a class="reference internal" href="#rationale">Rationale</a></li> <li><a class="reference internal" href="#examples">Examples</a><ul> <li><a class="reference internal" href="#indexerror">IndexError</a></li> <li><a class="reference internal" href="#keyerror">KeyError</a></li> <li><a class="reference internal" href="#attributeerror">AttributeError</a></li> <li><a class="reference internal" href="#nameerror">NameError</a></li> <li><a class="reference internal" href="#other-cases">Other Cases</a></li> </ul> </li> <li><a class="reference internal" href="#proposal">Proposal</a></li> <li><a class="reference internal" href="#potential-uses">Potential Uses</a></li> <li><a class="reference internal" href="#performance">Performance</a></li> <li><a class="reference internal" href="#references">References</a></li> <li><a class="reference internal" href="#copyright">Copyright</a></li> </ul> </details></section> <section id="abstract"> <h2><a class="toc-backref" href="#abstract" role="doc-backlink">Abstract</a></h2> <p>Exceptions like <code class="docutils literal notranslate"><span class="pre">AttributeError</span></code>, <code class="docutils literal notranslate"><span class="pre">IndexError</span></code>, <code class="docutils literal notranslate"><span class="pre">KeyError</span></code>, <code class="docutils literal notranslate"><span class="pre">LookupError</span></code>, <code class="docutils literal notranslate"><span class="pre">NameError</span></code>, <code class="docutils literal notranslate"><span class="pre">TypeError</span></code>, and <code class="docutils literal notranslate"><span class="pre">ValueError</span></code> do not provide all information required by programmers to debug and better understand what caused them. Furthermore, in some cases the messages even have slightly different formats, which makes it really difficult for tools to automatically provide additional information to diagnose the problem. To tackle the former and to lay ground for the latter, it is proposed to expand these exceptions so to hold both the offending and affected entities.</p> </section> <section id="rationale"> <h2><a class="toc-backref" href="#rationale" role="doc-backlink">Rationale</a></h2> <p>The main issue this PEP aims to solve is the fact that currently error messages are not that expressive and lack some key information to resolve the exceptions. Additionally, the information present on the error message is not always in the same format, which makes it very difficult for third-party libraries to provide automated diagnosis of the error.</p> <p>These automated tools could, for example, detect typos or display or log extra debug information. These could be particularly useful when running tests or in a long running application.</p> <p>Although it is in theory possible to have such libraries, they need to resort to hacks in order to achieve the goal. One such example is python-improved-exceptions <a class="footnote-reference brackets" href="#id27" id="id1">[1]</a>, which modifies the byte-code to keep references to the possibly interesting objects and also parses the error messages to extract information like types or names. Unfortunately, such approach is extremely fragile and not portable.</p> <p>A similar proposal <a class="footnote-reference brackets" href="#id28" id="id2">[2]</a> has been implemented for <code class="docutils literal notranslate"><span class="pre">ImportError</span></code> and in the same fashion this idea has received support <a class="footnote-reference brackets" href="#id29" id="id3">[3]</a>. Additionally, almost 10 years ago Guido asked in <a class="footnote-reference brackets" href="#id37" id="id4">[11]</a> to have a clean API to access the affected objects in Exceptions like <code class="docutils literal notranslate"><span class="pre">KeyError</span></code>, <code class="docutils literal notranslate"><span class="pre">AttributeError</span></code>, <code class="docutils literal notranslate"><span class="pre">NameError</span></code>, and <code class="docutils literal notranslate"><span class="pre">IndexError</span></code>. Similar issues and proposals ideas have been written in the last year. Some other issues have been created, but despite receiving support they finally get abandoned. References to the created issues are listed below:</p> <ul class="simple"> <li><code class="docutils literal notranslate"><span class="pre">AttributeError</span></code>: <a class="footnote-reference brackets" href="#id37" id="id5">[11]</a>, <a class="footnote-reference brackets" href="#id36" id="id6">[10]</a>, <a class="footnote-reference brackets" href="#id31" id="id7">[5]</a>, <a class="footnote-reference brackets" href="#id30" id="id8">[4]</a>, <a class="footnote-reference brackets" href="#id29" id="id9">[3]</a></li> <li><code class="docutils literal notranslate"><span class="pre">IndexError</span></code>: <a class="footnote-reference brackets" href="#id37" id="id10">[11]</a>, <a class="footnote-reference brackets" href="#id32" id="id11">[6]</a>, <a class="footnote-reference brackets" href="#id29" id="id12">[3]</a></li> <li><code class="docutils literal notranslate"><span class="pre">KeyError</span></code>: <a class="footnote-reference brackets" href="#id37" id="id13">[11]</a>, <a class="footnote-reference brackets" href="#id33" id="id14">[7]</a>, <a class="footnote-reference brackets" href="#id29" id="id15">[3]</a></li> <li><code class="docutils literal notranslate"><span class="pre">LookupError</span></code>: <a class="footnote-reference brackets" href="#id37" id="id16">[11]</a></li> <li><code class="docutils literal notranslate"><span class="pre">NameError</span></code>: <a class="footnote-reference brackets" href="#id37" id="id17">[11]</a>, <a class="footnote-reference brackets" href="#id36" id="id18">[10]</a>, <a class="footnote-reference brackets" href="#id29" id="id19">[3]</a></li> <li><code class="docutils literal notranslate"><span class="pre">TypeError</span></code>: <a class="footnote-reference brackets" href="#id34" id="id20">[8]</a></li> <li><code class="docutils literal notranslate"><span class="pre">ValueError</span></code>: <a class="footnote-reference brackets" href="#id35" id="id21">[9]</a></li> </ul> <p>To move forward with the development and to centralize the information and discussion, this PEP aims to be a meta-issue summarizing all the above discussions and ideas.</p> </section> <section id="examples"> <h2><a class="toc-backref" href="#examples" role="doc-backlink">Examples</a></h2> <section id="indexerror"> <h3><a class="toc-backref" href="#indexerror" role="doc-backlink">IndexError</a></h3> <p>The error message does not reference the list’s length nor the index used.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span> <span class="n">a</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> <span class="ne">IndexError</span><span class="p">:</span> <span class="nb">list</span> <span class="n">index</span> <span class="n">out</span> <span class="n">of</span> <span class="nb">range</span> </pre></div> </div> </section> <section id="keyerror"> <h3><a class="toc-backref" href="#keyerror" role="doc-backlink">KeyError</a></h3> <p>By convention the key is the first element of the error’s argument, but there’s no other information regarding the affected dictionary (keys types, size, etc.)</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">b</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;foo&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">}</span> <span class="n">b</span><span class="p">[</span><span class="s1">&#39;fo&#39;</span><span class="p">]</span> <span class="ne">KeyError</span><span class="p">:</span> <span class="s1">&#39;fo&#39;</span> </pre></div> </div> </section> <section id="attributeerror"> <h3><a class="toc-backref" href="#attributeerror" role="doc-backlink">AttributeError</a></h3> <p>The object’s type and the offending attribute are part of the error message. However, there are some different formats and the information is not always available. Furthermore, although the object type is useful in some cases, given the dynamic nature of Python, it would be much more useful to have a reference to the object itself. Additionally the reference to the type is not fully qualified and in some cases the type is just too generic to provide useful information, for example in case of accessing a module’s attribute.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">c</span> <span class="o">=</span> <span class="nb">object</span><span class="p">()</span> <span class="n">c</span><span class="o">.</span><span class="n">foo</span> <span class="ne">AttributeError</span><span class="p">:</span> <span class="s1">&#39;object&#39;</span> <span class="nb">object</span> <span class="n">has</span> <span class="n">no</span> <span class="n">attribute</span> <span class="s1">&#39;foo&#39;</span> <span class="kn">import</span><span class="w"> </span><span class="nn">string</span> <span class="n">string</span><span class="o">.</span><span class="n">foo</span> <span class="ne">AttributeError</span><span class="p">:</span> <span class="s1">&#39;module&#39;</span> <span class="nb">object</span> <span class="n">has</span> <span class="n">no</span> <span class="n">attribute</span> <span class="s1">&#39;foo&#39;</span> <span class="n">a</span> <span class="o">=</span> <span class="n">string</span><span class="o">.</span><span class="n">Formatter</span><span class="p">()</span> <span class="n">a</span><span class="o">.</span><span class="n">foo</span> <span class="ne">AttributeError</span><span class="p">:</span> <span class="s1">&#39;Formatter&#39;</span> <span class="nb">object</span> <span class="n">has</span> <span class="n">no</span> <span class="n">attribute</span> <span class="s1">&#39;foo&#39;</span> </pre></div> </div> </section> <section id="nameerror"> <h3><a class="toc-backref" href="#nameerror" role="doc-backlink">NameError</a></h3> <p>The error message provides typically the name.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">foo</span> <span class="o">=</span> <span class="mi">1</span> <span class="n">fo</span> <span class="ne">NameError</span><span class="p">:</span> <span class="k">global</span> <span class="n">name</span> <span class="s1">&#39;fo&#39;</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">defined</span> </pre></div> </div> </section> <section id="other-cases"> <h3><a class="toc-backref" href="#other-cases" role="doc-backlink">Other Cases</a></h3> <p>Issues are even harder to debug when the target object is the result of another expression, for example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">a</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="n">c</span><span class="p">[</span><span class="mi">0</span><span class="p">]]]</span> </pre></div> </div> <p>This issue is also related to the fact that opcodes only have line number information and not the offset. This proposal would help in this case but not as much as having offsets.</p> </section> </section> <section id="proposal"> <h2><a class="toc-backref" href="#proposal" role="doc-backlink">Proposal</a></h2> <p>Extend the exceptions <code class="docutils literal notranslate"><span class="pre">AttributeError</span></code>, <code class="docutils literal notranslate"><span class="pre">IndexError</span></code>, <code class="docutils literal notranslate"><span class="pre">KeyError</span></code>, <code class="docutils literal notranslate"><span class="pre">LookupError</span></code>, <code class="docutils literal notranslate"><span class="pre">NameError</span></code>, <code class="docutils literal notranslate"><span class="pre">TypeError</span></code>, and <code class="docutils literal notranslate"><span class="pre">ValueError</span></code> with the following:</p> <ul class="simple"> <li><code class="docutils literal notranslate"><span class="pre">AttributeError</span></code>: target <sup>w</sup>, attribute</li> <li><code class="docutils literal notranslate"><span class="pre">IndexError</span></code>: target <sup>w</sup>, key <sup>w</sup>, index (just an alias to key)</li> <li><code class="docutils literal notranslate"><span class="pre">KeyError</span></code>: target <sup>w</sup>, key <sup>w</sup></li> <li><code class="docutils literal notranslate"><span class="pre">LookupError</span></code>: target <sup>w</sup>, key <sup>w</sup></li> <li><code class="docutils literal notranslate"><span class="pre">NameError</span></code>: name, scope?</li> <li><code class="docutils literal notranslate"><span class="pre">TypeError</span></code>: unexpected_type</li> <li><code class="docutils literal notranslate"><span class="pre">ValueError</span></code>: unexpected_value <sup>w</sup></li> </ul> <p>Attributes with the superscript <sup>w</sup> may need to be weak references <a class="footnote-reference brackets" href="#id38" id="id22">[12]</a> to prevent any memory cycles. However, this may add an unnecessary extra complexity as noted by R. David Murray <a class="footnote-reference brackets" href="#id39" id="id23">[13]</a>. This is specially true given that builtin types do not support being weak referenced.</p> <p>TODO(skreft): expand this with examples of corner cases.</p> <p>To remain backwards compatible these new attributes will be optional and keyword only.</p> <p>It is proposed to add this information, rather than just improve the error, as the former would allow new debugging frameworks and tools and also in the future to switch to a lazy generated message. Generated messages are discussed in <a class="footnote-reference brackets" href="#id28" id="id24">[2]</a>, although they are not implemented at the moment. They would not only save some resources, but also uniform the messages.</p> <p>The stdlib will be then gradually changed so to start using these new attributes.</p> </section> <section id="potential-uses"> <h2><a class="toc-backref" href="#potential-uses" role="doc-backlink">Potential Uses</a></h2> <p>An automated tool could for example search for similar keys within the object, allowing to display the following::</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>a = {&#39;foo&#39;: 1} a[&#39;fo&#39;] KeyError: &#39;fo&#39;. Did you mean &#39;foo&#39;? foo = 1 fo NameError: global name &#39;fo&#39; is not defined. Did you mean &#39;foo&#39;? </pre></div> </div> <p>See <a class="footnote-reference brackets" href="#id29" id="id25">[3]</a> for the output a TestRunner could display.</p> </section> <section id="performance"> <h2><a class="toc-backref" href="#performance" role="doc-backlink">Performance</a></h2> <p>Filling these new attributes would only require two extra parameters with data already available so the impact should be marginal. However, it may need special care for <code class="docutils literal notranslate"><span class="pre">KeyError</span></code> as the following pattern is already widespread.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span> <span class="n">a</span><span class="p">[</span><span class="n">foo</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="n">foo</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span> <span class="k">except</span><span class="p">:</span> <span class="n">a</span><span class="p">[</span><span class="n">foo</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span> </pre></div> </div> <p>Note as well that storing these objects into the error itself would allow the lazy generation of the error message, as discussed in <a class="footnote-reference brackets" href="#id28" id="id26">[2]</a>.</p> </section> <section id="references"> <h2><a class="toc-backref" href="#references" role="doc-backlink">References</a></h2> <aside class="footnote-list brackets"> <aside class="footnote brackets" id="id27" role="doc-footnote"> <dt class="label" id="id27">[<a href="#id1">1</a>]</dt> <dd>Python Exceptions Improved (<a class="reference external" href="https://www.github.com/sk-/python-exceptions-improved">https://www.github.com/sk-/python-exceptions-improved</a>)</aside> <aside class="footnote brackets" id="id28" role="doc-footnote"> <dt class="label" id="id28">[2]<em> (<a href='#id2'>1</a>, <a href='#id24'>2</a>, <a href='#id26'>3</a>) </em></dt> <dd>ImportError needs attributes for module and file name (<a class="reference external" href="http://bugs.python.org/issue1559549">http://bugs.python.org/issue1559549</a>)</aside> <aside class="footnote brackets" id="id29" role="doc-footnote"> <dt class="label" id="id29">[3]<em> (<a href='#id3'>1</a>, <a href='#id9'>2</a>, <a href='#id12'>3</a>, <a href='#id15'>4</a>, <a href='#id19'>5</a>, <a href='#id25'>6</a>) </em></dt> <dd>Enhance exceptions by attaching some more information to them (<a class="reference external" href="https://mail.python.org/pipermail/python-ideas/2014-February/025601.html">https://mail.python.org/pipermail/python-ideas/2014-February/025601.html</a>)</aside> <aside class="footnote brackets" id="id30" role="doc-footnote"> <dt class="label" id="id30">[<a href="#id8">4</a>]</dt> <dd>Specificity in AttributeError (<a class="reference external" href="https://mail.python.org/pipermail/python-ideas/2013-April/020308.html">https://mail.python.org/pipermail/python-ideas/2013-April/020308.html</a>)</aside> <aside class="footnote brackets" id="id31" role="doc-footnote"> <dt class="label" id="id31">[<a href="#id7">5</a>]</dt> <dd>Add an ‘attr’ attribute to AttributeError (<a class="reference external" href="http://bugs.python.org/issue18156">http://bugs.python.org/issue18156</a>)</aside> <aside class="footnote brackets" id="id32" role="doc-footnote"> <dt class="label" id="id32">[<a href="#id11">6</a>]</dt> <dd>Add index attribute to IndexError (<a class="reference external" href="http://bugs.python.org/issue18162">http://bugs.python.org/issue18162</a>)</aside> <aside class="footnote brackets" id="id33" role="doc-footnote"> <dt class="label" id="id33">[<a href="#id14">7</a>]</dt> <dd>Add a ‘key’ attribute to KeyError (<a class="reference external" href="http://bugs.python.org/issue18163">http://bugs.python.org/issue18163</a>)</aside> <aside class="footnote brackets" id="id34" role="doc-footnote"> <dt class="label" id="id34">[<a href="#id20">8</a>]</dt> <dd>Add ‘unexpected_type’ to TypeError (<a class="reference external" href="http://bugs.python.org/issue18165">http://bugs.python.org/issue18165</a>)</aside> <aside class="footnote brackets" id="id35" role="doc-footnote"> <dt class="label" id="id35">[<a href="#id21">9</a>]</dt> <dd>‘value’ attribute for ValueError (<a class="reference external" href="http://bugs.python.org/issue18166">http://bugs.python.org/issue18166</a>)</aside> <aside class="footnote brackets" id="id36" role="doc-footnote"> <dt class="label" id="id36">[10]<em> (<a href='#id6'>1</a>, <a href='#id18'>2</a>) </em></dt> <dd>making builtin exceptions more informative (<a class="reference external" href="http://bugs.python.org/issue1182143">http://bugs.python.org/issue1182143</a>)</aside> <aside class="footnote brackets" id="id37" role="doc-footnote"> <dt class="label" id="id37">[11]<em> (<a href='#id4'>1</a>, <a href='#id5'>2</a>, <a href='#id10'>3</a>, <a href='#id13'>4</a>, <a href='#id16'>5</a>, <a href='#id17'>6</a>) </em></dt> <dd>LookupError etc. need API to get the key (<a class="reference external" href="http://bugs.python.org/issue614557">http://bugs.python.org/issue614557</a>)</aside> <aside class="footnote brackets" id="id38" role="doc-footnote"> <dt class="label" id="id38">[<a href="#id22">12</a>]</dt> <dd>weakref - Weak References (<a class="reference external" href="https://docs.python.org/3/library/weakref.html">https://docs.python.org/3/library/weakref.html</a>)</aside> <aside class="footnote brackets" id="id39" role="doc-footnote"> <dt class="label" id="id39">[<a href="#id23">13</a>]</dt> <dd>Message by R. David Murray: Weak refs on exceptions? (<a class="reference external" href="http://bugs.python.org/issue18163#msg190791">http://bugs.python.org/issue18163#msg190791</a>)</aside> </aside> </section> <section id="copyright"> <h2><a class="toc-backref" href="#copyright" role="doc-backlink">Copyright</a></h2> <p>This document has been placed in the public domain.</p> </section> </section> <hr class="docutils" /> <p>Source: <a class="reference external" href="https://github.com/python/peps/blob/main/peps/pep-0473.rst">https://github.com/python/peps/blob/main/peps/pep-0473.rst</a></p> <p>Last modified: <a class="reference external" href="https://github.com/python/peps/commits/main/peps/pep-0473.rst">2025-02-01 08:59:27 GMT</a></p> </article> <nav id="pep-sidebar"> <h2>Contents</h2> <ul> <li><a class="reference internal" href="#abstract">Abstract</a></li> <li><a class="reference internal" href="#rationale">Rationale</a></li> <li><a class="reference internal" href="#examples">Examples</a><ul> <li><a class="reference internal" href="#indexerror">IndexError</a></li> <li><a class="reference internal" href="#keyerror">KeyError</a></li> <li><a class="reference internal" href="#attributeerror">AttributeError</a></li> <li><a class="reference internal" href="#nameerror">NameError</a></li> <li><a class="reference internal" href="#other-cases">Other Cases</a></li> </ul> </li> <li><a class="reference internal" href="#proposal">Proposal</a></li> <li><a class="reference internal" href="#potential-uses">Potential Uses</a></li> <li><a class="reference internal" href="#performance">Performance</a></li> <li><a class="reference internal" href="#references">References</a></li> <li><a class="reference internal" href="#copyright">Copyright</a></li> </ul> <br> <a id="source" href="https://github.com/python/peps/blob/main/peps/pep-0473.rst">Page Source (GitHub)</a> </nav> </section> <script src="../_static/colour_scheme.js"></script> <script src="../_static/wrap_tables.js"></script> <script src="../_static/sticky_banner.js"></script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10