在python.pyi扩展中,”i”代表什么?

What does “i” represent in Python .pyi extension?

在python中,"i"在.pyi扩展中表示什么?

在PEP-484中,它提到.pyi是一个"存根文件",但是扩展名没有助记键。那么"i"是指"include"?实施"?"接口?


我认为.pyi中的i代表"接口"。

Java接口定义

An interface in the Java programming language is an abstract type that
is used to specify a behaviour that classes must implement

  • 从python类型化的github存储库:

Each Python module is represented by a .pyi"stub". This is a normal
Python file (i.e., it can be interpreted by Python 3), except all the
methods are empty.

  • 在"mypy"存储库中,它们明确地将"存根"文件称为公共接口:

A stubs file only contains a description of the public interface of
the module without any implementations.

因为"接口"在python中不存在(参见抽象类和接口之间的这个问题),我认为设计者打算为它专门提供一个特殊的扩展。

pyi实现"存根"文件(定义来自martin fowler)

Stubs: provide canned answers to calls made during the test, usually
not responding at all to anything outside what's programmed in for the
test.

但是人们更熟悉接口而不是"存根"文件,因此选择.pyi而不是.pys更容易避免不必要的混淆。


显然,pycharm创建.pyi文件的目的是:

1
2
3
4
5
6
7
8
9
The *.pyi files are used by PyCharm and other development tools to provide
more information, such as PEP 484 type hints, than it is able to glean from
introspection of extension types and methods.  They are not intended to be
imported, executed or used for any other purpose other than providing info
to the tools. If you don't use use a tool that makes use of .pyi files then
you can safely ignore this file.

See: https://www.python.org/dev/peps/pep-0484/
     https://www.jetbrains.com/help/pycharm/2016.1/type-hinting-in-pycharm.html

此评论位于:python27/lib/site packages/wx/core.pyi中