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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41734836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 01:32:27  来源:igfitidea点击:

What does "i" represent in Python .pyi extension?

python

提问by ChrisFreeman

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. So does the "i" mean "Include"? "Implementation"? "Interface"?

PEP-484 中,它提到 .pyi 是“存根文件”,但没有关于扩展名的助记符帮助。那么“我”是指“包括”吗?“执行”?“界面”?

采纳答案by Kruup?s

I think the iin .pyistands for "Interface"

我认为iin.pyi代表“接口”

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 编程语言中的接口是一种抽象类型,用于指定类必须实现的行为

  • 来自 Python typeshedgithub 存储库:

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.

每个 Python 模块都由一个.pyi“存根”表示。这是一个普通的 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 interfaceof 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 问题)我认为设计者打算为它专门提供一个特殊的扩展。

pyiimplements "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 .pyirather than .pysto avoid unnecessary confusion.

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

回答by Ribo

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. 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

PyCharm 和其他开发工具使用 *.pyi 文件来提供更多信息,例如 PEP 484 类型提示,而不是从扩展类型和方法的内省中收集到的信息。除了向工具提供信息外,它们不应被导入、执行或用于任何其他目的。如果您不使用使用 .pyi 文件的工具,那么您可以安全地忽略此文件。

参见: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