What does "i" mean in the Python.pyi extension?

In Python, what does “i” mean in the .pyi extension?

In PEP-484 he mentions .pyi - this is a "stub", but I do not need mnemonic help for the extension. So does "I" mean "enable"? "Implementation"? "Interface"?

+32
source share
2 answers

I think i in .pyi means "Interface"

Definition for an interface in Java :

An interface in the Java programming language is an abstract type that is used to define the behavior that classes should implement.

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

  • In the Mypy repository , they explicitly mention stubs as public interfaces:

The stub file contains only a description of the open interface of the module without any implementations.

Since “Interfaces” do not exist in Python (see this SO question between the Abstract and Interface class ), I think the designers intended to provide a special extension for it.

pyi implements a stub file (definition from Martin Fowler )

Stubs : Provide constant answers to calls made during the test, usually not responding at all, except for what is programmed for the test.

But people are more familiar with interfaces than with stubs, so it was easier to choose .pyi than .pys to avoid unnecessary confusion.

+22
source

Obviously, PyCharm creates a .pyi file for its own purposes:

* .Pyi files are used by PyCharm and other development tools to provide more information, such as tips like PEP 484, than it can draw from Introspection of extension types and methods. They are not intended to be imported, executed or used for any other purpose than providing information to the tools. If you do not use a tool that uses .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

This comment was found in: python27/Lib/site-packages/wx/core.pyi

+6
source

Source: https://habr.com/ru/post/1014206/


All Articles