简体   繁体   English

“i”在 Python .pyi 扩展名中代表什么?

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

In Python, what does "i" represent in .pyi extension?在 Python 中,“i”在.pyi扩展名中代表什么?

In PEP-484 , it mentions .pyi is "a stub file" but no mnemonic help on the extension.PEP-484 中,它提到.pyi是“存根文件”,但没有关于扩展名的助记符帮助。 So does the "i" mean "Include"?那么“我”是指“包括”吗? "Implementation"? “执行”? "Interface"? “界面”?

I think the i in .pyi stands for "Interface"我认为.pyii代表“接口”

Definition for Interface in Java : Java中接口的定义:

An interface in the Java programming language is an abstract type that is used to specify a behaviour that classes must implement Java 编程语言中的接口是一种抽象类型,用于指定类必须实现的行为

  • From Python typeshed github repository:来自 Python typeshed github 存储库:

Each Python module is represented by a .pyi "stub".每个 Python 模块都由一个.pyi “存根”表示。 This is a normal Python file (ie, it can be interpreted by Python 3), except all the methods are empty .这是一个普通的 Python 文件(即它可以被 Python 3 解释),除了所有方法都是空的

  • In 'Mypy' repository, they explicitly mention "stub" files as public interfaces:“Mypy”存储库中,他们明确提到“存根”文件是公共接口:

A stubs file only contains a description of the public interface of the module without any implementations.存根文件只包含模块公共接口的描述,没有任何实现。

Because "Interfaces" do not exist in Python (see this SO question between Abstract class and Interface ) I think the designers intended to dedicate a special extension for it.因为 Python 中不存在“接口”(请参阅Abstract class 和 Interface 之间的这个SO 问题)我认为设计者打算为它专门提供一个特殊的扩展。

pyi implements "stub" file (definition from Martin Fowler ) 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.存根:为测试期间拨打的电话提供预设答案,通常对测试编程之外的任何内容完全不响应。

But people are more familiar with Interfaces than "stub" files, therefore it was easier to choose .pyi rather than .pys to avoid unnecessary confusion.但是人们对接口比“存根”文件更熟悉,因此选择.pyi而不是.pys更容易避免不必要的混淆。

Apparently PyCharm creates .pyi file for its own purposes:显然 PyCharm 为自己的目的创建了 .pyi 文件:

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. PyCharm 和其他开发工具使用 *.pyi 文件来提供更多信息,例如 PEP 484 类型提示,而不是从扩展类型和方法的内省中收集到的信息。 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.如果您不使用使用 .pyi 文件的工具,那么您可以安全地忽略此文件。

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

This comment was found in: python27/Lib/site-packages/wx/core.pyi此评论位于: python27/Lib/site-packages/wx/core.pyi

The i in .pyi stands for 'interface'. .pyii代表“接口”。

The .pyi extension was first mentioned in this GitHub issue thread where JukkaL says:这个 GitHub 问题线程中首次提到了.pyi扩展名,其中 JukkaL 说:

I'd probably prefer an extension with just a single dot.我可能更喜欢只有一个点的扩展名。 It also needs to be something that is not in use (it should not be used by cython, etc.).它还需要是未使用的东西(不应被 cython 等使用)。 .pys seems to be used in Windows (or was). .pys 似乎在 Windows 中使用(或曾经使用过)。 Maybe .pyi, where i stands for an interface definition?也许.pyi,我代表接口定义?

Another way to explain the contents of a module that Wing can't figure out is with a pyi Python Interface file.另一种解释 Wing 无法弄清楚的模块内容的方法是使用 pyi Python 接口文件。 This file is merely a Python skeleton with the proper structure, call signature, and return values to correspond to the functions, attributes, classes, and methods specified in a module.该文件只是一个 Python 框架,具有适当的结构、调用签名和返回值,以对应于模块中指定的函数、属性、类和方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM