<p>我认为<code>.pyi</code>中的<code>i</code>代表“接口”</p>
<p><a href="https://en.wikipedia.org/wiki/Interface_(Java)" rel="noreferrer">Java</a>中接口的定义:</p>
<blockquote>
<p>An interface in the Java programming language is an abstract type that
is used to specify a behaviour that classes must implement</p>
</blockquote>
<ul>
<li>从Python<a href="https://github.com/python/typeshed#format" rel="noreferrer">typeshed</a>github存储库:</li>
</ul>
<blockquote>
<p>Each Python module is represented by a <code>.pyi</code> "stub". This is a normal
Python file (i.e., it can be interpreted by Python 3), <strong>except all the
methods are empty</strong>.</p>
</blockquote>
<ul>
<li>在<a href="https://github.com/python/mypy/wiki/Creating-Stubs-For-Python-Modules" rel="noreferrer">'Mypy'</a>存储库中,它们明确提到“存根”文件作为公共接口:</li>
</ul>
<blockquote>
<p>A stubs file only contains a description of the <strong>public interface</strong> of
the module without any implementations.</p>
</blockquote>
<p>因为“接口”在Python中不存在(参见本文<a href="https://stackoverflow.com/questions/372042/difference-between-abstract-class-and-interface-in-python">SO question between Abstract class and Interface</a>),所以我认为设计人员打算专门为它提供一个特殊的扩展。</p>
<p><code>pyi</code>实现“存根”文件(来自<a href="https://martinfowler.com/articles/mocksArentStubs.html" rel="noreferrer">Martin Fowler</a>的定义)</p>
<blockquote>
<p><strong>Stubs</strong>: provide canned answers to calls made during the test, usually
not responding at all to anything outside what's programmed in for the
test.</p>
</blockquote>
<p>但是人们对接口比“存根”文件更熟悉,因此选择<code>.pyi</code>而不是<code>.pys</code>更容易避免不必要的混淆。</p>