CINXE.COM
PEP 328 – Imports: Multi-Line and Absolute/Relative | 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 328 – Imports: Multi-Line and Absolute/Relative | peps.python.org</title> <link rel="shortcut icon" href="../_static/py.png"> <link rel="canonical" href="https://peps.python.org/pep-0328/"> <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 328 – Imports: Multi-Line and Absolute/Relative | peps.python.org'> <meta property="og:description" content="The import statement has two problems:"> <meta property="og:type" content="website"> <meta property="og:url" content="https://peps.python.org/pep-0328/"> <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="The import statement has two problems:"> <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> » </li> <li><a href="../pep-0000/">PEP Index</a> » </li> <li>PEP 328</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 328 – Imports: Multi-Line and Absolute/Relative</h1> <dl class="rfc2822 field-list simple"> <dt class="field-odd">Author<span class="colon">:</span></dt> <dd class="field-odd">Aahz <aahz at pythoncraft.com></dd> <dt class="field-even">Status<span class="colon">:</span></dt> <dd class="field-even"><abbr title="Accepted and implementation complete, or no longer active">Final</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">21-Dec-2003</dd> <dt class="field-odd">Python-Version<span class="colon">:</span></dt> <dd class="field-odd">2.4, 2.5, 2.6</dd> <dt class="field-even">Post-History<span class="colon">:</span></dt> <dd class="field-even">08-Mar-2004</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="#timeline">Timeline</a></li> <li><a class="reference internal" href="#rationale-for-parentheses">Rationale for Parentheses</a></li> <li><a class="reference internal" href="#rationale-for-absolute-imports">Rationale for Absolute Imports</a></li> <li><a class="reference internal" href="#rationale-for-relative-imports">Rationale for Relative Imports</a></li> <li><a class="reference internal" href="#guido-s-decision">Guido’s Decision</a></li> <li><a class="reference internal" href="#relative-imports-and-name">Relative Imports and __name__</a></li> <li><a class="reference internal" href="#relative-imports-and-indirection-entries-in-sys-modules">Relative Imports and Indirection Entries in sys.modules</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>The <code class="docutils literal notranslate"><span class="pre">import</span></code> statement has two problems:</p> <ul class="simple"> <li>Long <code class="docutils literal notranslate"><span class="pre">import</span></code> statements can be difficult to write, requiring various contortions to fit Pythonic style guidelines.</li> <li>Imports can be ambiguous in the face of packages; within a package, it’s not clear whether <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">foo</span></code> refers to a module within the package or some module outside the package. (More precisely, a local module or package can shadow another hanging directly off <code class="docutils literal notranslate"><span class="pre">sys.path</span></code>.)</li> </ul> <p>For the first problem, it is proposed that parentheses be permitted to enclose multiple names, thus allowing Python’s standard mechanisms for multi-line values to apply. For the second problem, it is proposed that all <code class="docutils literal notranslate"><span class="pre">import</span></code> statements be absolute by default (searching <code class="docutils literal notranslate"><span class="pre">sys.path</span></code> only) with special syntax (leading dots) for accessing package-relative imports.</p> </section> <section id="timeline"> <h2><a class="toc-backref" href="#timeline" role="doc-backlink">Timeline</a></h2> <p>In Python 2.5, you must enable the new absolute import behavior with</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">absolute_import</span> </pre></div> </div> <p>You may use relative imports freely. In Python 2.6, any <code class="docutils literal notranslate"><span class="pre">import</span></code> statement that results in an intra-package import will raise <code class="docutils literal notranslate"><span class="pre">DeprecationWarning</span></code> (this also applies to <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre"><></span> <span class="pre">import</span></code> that fails to use the relative import syntax).</p> </section> <section id="rationale-for-parentheses"> <h2><a class="toc-backref" href="#rationale-for-parentheses" role="doc-backlink">Rationale for Parentheses</a></h2> <p>Currently, if you want to import a lot of names from a module or package, you have to choose one of several unpalatable options:</p> <ul> <li>Write a long line with backslash continuations:<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">Tkinter</span> <span class="kn">import</span> <span class="n">Tk</span><span class="p">,</span> <span class="n">Frame</span><span class="p">,</span> <span class="n">Button</span><span class="p">,</span> <span class="n">Entry</span><span class="p">,</span> <span class="n">Canvas</span><span class="p">,</span> <span class="n">Text</span><span class="p">,</span> \ <span class="n">LEFT</span><span class="p">,</span> <span class="n">DISABLED</span><span class="p">,</span> <span class="n">NORMAL</span><span class="p">,</span> <span class="n">RIDGE</span><span class="p">,</span> <span class="n">END</span> </pre></div> </div> </li> <li>Write multiple <code class="docutils literal notranslate"><span class="pre">import</span></code> statements:<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">Tkinter</span> <span class="kn">import</span> <span class="n">Tk</span><span class="p">,</span> <span class="n">Frame</span><span class="p">,</span> <span class="n">Button</span><span class="p">,</span> <span class="n">Entry</span><span class="p">,</span> <span class="n">Canvas</span><span class="p">,</span> <span class="n">Text</span> <span class="kn">from</span> <span class="nn">Tkinter</span> <span class="kn">import</span> <span class="n">LEFT</span><span class="p">,</span> <span class="n">DISABLED</span><span class="p">,</span> <span class="n">NORMAL</span><span class="p">,</span> <span class="n">RIDGE</span><span class="p">,</span> <span class="n">END</span> </pre></div> </div> </li> </ul> <p>(<code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">*</span></code> is <em>not</em> an option ;-)</p> <p>Instead, it should be possible to use Python’s standard grouping mechanism (parentheses) to write the <code class="docutils literal notranslate"><span class="pre">import</span></code> statement:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">Tkinter</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Tk</span><span class="p">,</span> <span class="n">Frame</span><span class="p">,</span> <span class="n">Button</span><span class="p">,</span> <span class="n">Entry</span><span class="p">,</span> <span class="n">Canvas</span><span class="p">,</span> <span class="n">Text</span><span class="p">,</span> <span class="n">LEFT</span><span class="p">,</span> <span class="n">DISABLED</span><span class="p">,</span> <span class="n">NORMAL</span><span class="p">,</span> <span class="n">RIDGE</span><span class="p">,</span> <span class="n">END</span><span class="p">)</span> </pre></div> </div> <p>This part of the proposal had BDFL approval from the beginning.</p> <p>Parentheses support was added to Python 2.4.</p> </section> <section id="rationale-for-absolute-imports"> <h2><a class="toc-backref" href="#rationale-for-absolute-imports" role="doc-backlink">Rationale for Absolute Imports</a></h2> <p>In Python 2.4 and earlier, if you’re reading a module located inside a package, it is not clear whether</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">foo</span> </pre></div> </div> <p>refers to a top-level module or to another module inside the package. As Python’s library expands, more and more existing package internal modules suddenly shadow standard library modules by accident. It’s a particularly difficult problem inside packages because there’s no way to specify which module is meant. To resolve the ambiguity, it is proposed that <code class="docutils literal notranslate"><span class="pre">foo</span></code> will always be a module or package reachable from <code class="docutils literal notranslate"><span class="pre">sys.path</span></code>. This is called an absolute import.</p> <p>The python-dev community chose absolute imports as the default because they’re the more common use case and because absolute imports can provide all the functionality of relative (intra-package) imports – albeit at the cost of difficulty when renaming package pieces higher up in the hierarchy or when moving one package inside another.</p> <p>Because this represents a change in semantics, absolute imports will be optional in Python 2.5 and 2.6 through the use of</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">absolute_import</span> </pre></div> </div> <p>This part of the proposal had BDFL approval from the beginning.</p> </section> <section id="rationale-for-relative-imports"> <h2><a class="toc-backref" href="#rationale-for-relative-imports" role="doc-backlink">Rationale for Relative Imports</a></h2> <p>With the shift to absolute imports, the question arose whether relative imports should be allowed at all. Several use cases were presented, the most important of which is being able to rearrange the structure of large packages without having to edit sub-packages. In addition, a module inside a package can’t easily import itself without relative imports.</p> <p>Guido approved of the idea of relative imports, but there has been a lot of disagreement on the spelling (syntax). There does seem to be agreement that relative imports will require listing specific names to import (that is, <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">foo</span></code> as a bare term will always be an absolute import).</p> <p>Here are the contenders:</p> <ul> <li>One from Guido:<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">.foo</span> <span class="kn">import</span> <span class="n">bar</span> </pre></div> </div> <p>and</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">...foo</span> <span class="kn">import</span> <span class="n">bar</span> </pre></div> </div> <p>These two forms have a couple of different suggested semantics. One semantic is to make each dot represent one level. There have been many complaints about the difficulty of counting dots. Another option is to only allow one level of relative import. That misses a lot of functionality, and people still complained about missing the dot in the one-dot form. The final option is to define an algorithm for finding relative modules and packages; the objection here is “Explicit is better than implicit”. (The algorithm proposed is “search up from current package directory until the ultimate package parent gets hit”.)</p> <p>Some people have suggested other punctuation as the separator, such as “-” or “^”.</p> <p>Some people have suggested using “*”:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="o">*.</span><span class="n">foo</span> <span class="kn">import</span> <span class="nn">bar</span> </pre></div> </div> </li> <li>The next set of options is conflated from several posters:<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__pkg__.__pkg__</span> <span class="kn">import</span> </pre></div> </div> <p>and</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">.__parent__.__parent__</span> <span class="kn">import</span> </pre></div> </div> <p>Many people (Guido included) think these look ugly, but they <em>are</em> clear and explicit. Overall, more people prefer <code class="docutils literal notranslate"><span class="pre">__pkg__</span></code> as the shorter option.</p> </li> <li>One suggestion was to allow only sibling references. In other words, you would not be able to use relative imports to refer to modules higher in the package tree. You would then be able to do either<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">.spam</span> <span class="kn">import</span> <span class="n">eggs</span> </pre></div> </div> <p>or</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">.spam.eggs</span> </pre></div> </div> </li> <li>Some people favor allowing indexed parents:<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="o">-</span><span class="mf">2.</span><span class="n">spam</span> <span class="kn">import</span> <span class="nn">eggs</span> </pre></div> </div> <p>In this scenario, importing from the current directory would be a simple</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">.spam</span> <span class="kn">import</span> <span class="n">eggs</span> </pre></div> </div> </li> <li>Finally, some people dislike the way you have to change <code class="docutils literal notranslate"><span class="pre">import</span></code> to <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">...</span> <span class="pre">import</span></code> when you want to dig inside a package. They suggest completely rewriting the <code class="docutils literal notranslate"><span class="pre">import</span></code> syntax:<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">MODULE</span> <span class="kn">import</span> <span class="n">NAMES</span> <span class="k">as</span> <span class="n">RENAME</span> <span class="n">searching</span> <span class="n">HOW</span> </pre></div> </div> <p>or</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">NAMES</span> <span class="k">as</span> <span class="nn">RENAME</span> <span class="kn">from</span> <span class="nn">MODULE</span> <span class="n">searching</span> <span class="n">HOW</span> <span class="p">[</span><span class="kn">from</span> <span class="nn">NAMES</span><span class="p">]</span> <span class="p">[</span><span class="ow">in</span> <span class="n">WHERE</span><span class="p">]</span> <span class="kn">import</span> <span class="nn">...</span> </pre></div> </div> <p>However, this most likely could not be implemented for Python 2.5 (too big a change), and allowing relative imports is sufficiently critical that we need something now (given that the standard <code class="docutils literal notranslate"><span class="pre">import</span></code> will change to absolute import). More than that, this proposed syntax has several open questions:</p> <ul> <li>What is the precise proposed syntax? (Which clauses are optional under which circumstances?)</li> <li>How strongly does the <code class="docutils literal notranslate"><span class="pre">searching</span></code> clause bind? In other words, do you write:<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">foo</span> <span class="k">as</span> <span class="nn">bar</span> <span class="n">searching</span> <span class="n">XXX</span><span class="p">,</span> <span class="n">spam</span> <span class="k">as</span> <span class="n">ham</span> <span class="n">searching</span> <span class="n">XXX</span> </pre></div> </div> <p>or:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">foo</span> <span class="k">as</span> <span class="nn">bar</span><span class="o">,</span> <span class="nn">spam</span> <span class="k">as</span> <span class="nn">ham</span> <span class="n">searching</span> <span class="n">XXX</span> </pre></div> </div> </li> </ul> </li> </ul> </section> <section id="guido-s-decision"> <h2><a class="toc-backref" href="#guido-s-decision" role="doc-backlink">Guido’s Decision</a></h2> <p>Guido has Pronounced <a class="footnote-reference brackets" href="#id3" id="id1">[1]</a> that relative imports will use leading dots. A single leading dot indicates a relative import, starting with the current package. Two or more leading dots give a relative import to the parent(s) of the current package, one level per dot after the first. Here’s a sample package layout:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">package</span><span class="o">/</span> <span class="fm">__init__</span><span class="o">.</span><span class="n">py</span> <span class="n">subpackage1</span><span class="o">/</span> <span class="fm">__init__</span><span class="o">.</span><span class="n">py</span> <span class="n">moduleX</span><span class="o">.</span><span class="n">py</span> <span class="n">moduleY</span><span class="o">.</span><span class="n">py</span> <span class="n">subpackage2</span><span class="o">/</span> <span class="fm">__init__</span><span class="o">.</span><span class="n">py</span> <span class="n">moduleZ</span><span class="o">.</span><span class="n">py</span> <span class="n">moduleA</span><span class="o">.</span><span class="n">py</span> </pre></div> </div> <p>Assuming that the current file is either <code class="docutils literal notranslate"><span class="pre">moduleX.py</span></code> or <code class="docutils literal notranslate"><span class="pre">subpackage1/__init__.py</span></code>, following are correct usages of the new syntax:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">.moduleY</span> <span class="kn">import</span> <span class="n">spam</span> <span class="kn">from</span> <span class="nn">.moduleY</span> <span class="kn">import</span> <span class="n">spam</span> <span class="k">as</span> <span class="n">ham</span> <span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">moduleY</span> <span class="kn">from</span> <span class="nn">..subpackage1</span> <span class="kn">import</span> <span class="n">moduleY</span> <span class="kn">from</span> <span class="nn">..subpackage2.moduleZ</span> <span class="kn">import</span> <span class="n">eggs</span> <span class="kn">from</span> <span class="nn">..moduleA</span> <span class="kn">import</span> <span class="n">foo</span> <span class="kn">from</span> <span class="nn">...package</span> <span class="kn">import</span> <span class="n">bar</span> <span class="kn">from</span> <span class="nn">...sys</span> <span class="kn">import</span> <span class="n">path</span> </pre></div> </div> <p>Note that while that last case is legal, it is certainly discouraged (“insane” was the word Guido used).</p> <p>Relative imports must always use <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre"><></span> <span class="pre">import</span></code>; <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre"><></span></code> is always absolute. Of course, absolute imports can use <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre"><></span> <span class="pre">import</span></code> by omitting the leading dots. The reason <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">.foo</span></code> is prohibited is because after</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">XXX.YYY.ZZZ</span> </pre></div> </div> <p>then</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">XXX</span><span class="o">.</span><span class="n">YYY</span><span class="o">.</span><span class="n">ZZZ</span> </pre></div> </div> <p>is usable in an expression. But</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">.</span><span class="n">moduleY</span> </pre></div> </div> <p>is not usable in an expression.</p> </section> <section id="relative-imports-and-name"> <h2><a class="toc-backref" href="#relative-imports-and-name" role="doc-backlink">Relative Imports and __name__</a></h2> <p>Relative imports use a module’s __name__ attribute to determine that module’s position in the package hierarchy. If the module’s name does not contain any package information (e.g. it is set to ‘__main__’) then relative imports are resolved as if the module were a top level module, regardless of where the module is actually located on the file system.</p> </section> <section id="relative-imports-and-indirection-entries-in-sys-modules"> <h2><a class="toc-backref" href="#relative-imports-and-indirection-entries-in-sys-modules" role="doc-backlink">Relative Imports and Indirection Entries in sys.modules</a></h2> <p>When packages were introduced, the concept of an indirection entry in sys.modules came into existence <a class="footnote-reference brackets" href="#id4" id="id2">[2]</a>. When an entry in sys.modules for a module within a package had a value of None, it represented that the module actually referenced the top-level module. For instance, ‘Sound.Effects.string’ might have a value of None in sys.modules. That meant any import that resolved to that name actually was to import the top-level ‘string’ module.</p> <p>This introduced an optimization for when a relative import was meant to resolve to an absolute import. But since this PEP makes a very clear delineation between absolute and relative imports, this optimization is no longer needed. When absolute/relative imports become the only import semantics available then indirection entries in sys.modules will no longer be supported.</p> </section> <section id="references"> <h2><a class="toc-backref" href="#references" role="doc-backlink">References</a></h2> <p>For more background, see the following python-dev threads:</p> <ul class="simple"> <li><a class="reference external" href="https://mail.python.org/pipermail/python-dev/2003-December/040973.html">Re: Christmas Wishlist</a></li> <li><a class="reference external" href="https://mail.python.org/pipermail/python-dev/2003-December/041078.html">Re: Python-Dev Digest, Vol 5, Issue 57</a></li> <li><a class="reference external" href="https://mail.python.org/pipermail/python-dev/2003-December/041065.html">Relative import</a></li> <li><a class="reference external" href="https://mail.python.org/pipermail/python-dev/2003-December/041418.html">Another Strategy for Relative Import</a></li> </ul> <aside class="footnote-list brackets"> <aside class="footnote brackets" id="id3" role="doc-footnote"> <dt class="label" id="id3">[<a href="#id1">1</a>]</dt> <dd><a class="reference external" href="https://mail.python.org/pipermail/python-dev/2004-March/043739.html">https://mail.python.org/pipermail/python-dev/2004-March/043739.html</a></aside> <aside class="footnote brackets" id="id4" role="doc-footnote"> <dt class="label" id="id4">[<a href="#id2">2</a>]</dt> <dd><a class="reference external" href="https://www.python.org/doc/essays/packages/">https://www.python.org/doc/essays/packages/</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-0328.rst">https://github.com/python/peps/blob/main/peps/pep-0328.rst</a></p> <p>Last modified: <a class="reference external" href="https://github.com/python/peps/commits/main/peps/pep-0328.rst">2023-09-09 17:39:29 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="#timeline">Timeline</a></li> <li><a class="reference internal" href="#rationale-for-parentheses">Rationale for Parentheses</a></li> <li><a class="reference internal" href="#rationale-for-absolute-imports">Rationale for Absolute Imports</a></li> <li><a class="reference internal" href="#rationale-for-relative-imports">Rationale for Relative Imports</a></li> <li><a class="reference internal" href="#guido-s-decision">Guido’s Decision</a></li> <li><a class="reference internal" href="#relative-imports-and-name">Relative Imports and __name__</a></li> <li><a class="reference internal" href="#relative-imports-and-indirection-entries-in-sys-modules">Relative Imports and Indirection Entries in sys.modules</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-0328.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>