gpt4 book ai didi

python - "i"在 Python .pyi 扩展中代表什么?

转载 作者:IT老高 更新时间:2023-10-28 22:12:36 24 4
gpt4 key购买 nike

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

PEP-484 ,它提到 .pyi 是“ stub 文件”,但没有关于扩展的助记符帮助。那么“i”是否意味着“包括”? “执行”? “接口(interface)”?

最佳答案

我认为 .pyi 中的 i 代表“接口(interface)”

Java 中的接口(interface)定义:

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

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'存储库,他们明确提到“ stub ”文件作为公共(public)接口(interface):

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

因为 Python 中不存在“接口(interface)”(参见 SO question between Abstract class and Interface),我认为设计者打算为其专门提供一个特殊的扩展。

pyi 实现“ stub ”文件(定义来自 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.

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

关于python - "i"在 Python .pyi 扩展中代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41734836/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com