Questions tagged [pyi]

Tags for questions about Python Information (pyi). The python package for scraping pypi endpoints to retrieve python package information.

PYthon Information is a CLI that scrapes pypi json endpoints to retrieve python package data.

It can be used to easily get basic stats on a package without the need to go to pypi to look it up.

Read more about pyi package here

16 questions
13
votes
1 answer

What the code '_T = TypeVar('_T')' means in a *.pyi file?

I'm new to Python annotation (type hints). I noticed that many of the class definitions in pyi files inherit to Generic[_T], and _T = TypeVar('_T'). I am confused, what does the _T mean here? from typing import Generic, TypeVar _T =…
EvinK
  • 131
  • 1
  • 7
12
votes
0 answers

How can I add type hints to my monkey-patched function to an existing module's class?

I want to know how I can add type hints (for PyCharm IDE code completion support) to a method def links(self) -> List[str] that I monkey-patched to an existing module's class: My function def issue_links(self) -> List[str]: links = [] # ... …
Christopher Graf
  • 1,929
  • 1
  • 17
  • 34
11
votes
2 answers

Import a pyi (type stub file) into a normal python module

I have a program (like a macro) that runs within a parent program and imports an API module from that program (lets call it foo). The problem is that that module only exists within that program, so I can't do things like run pydocmd outside the…
Ian
  • 5,704
  • 6
  • 40
  • 72
9
votes
1 answer

Partial stub in PyCharm

I would like to introduce partial type annotation to my project. For example for overloading. I found that pep561 introduce partial stub file support. I develop my project with PyCharm and I add corresponding *.pyi file. And got expected…
Grzegorz Bokota
  • 1,736
  • 11
  • 19
4
votes
1 answer

Merging .py file and .txt files into .exe file using pyinstaller

I have a python program that takes in as input two text files. I have converted this python program(a .py file) to a .exe file using pyinstaller. The .exe file when run gives FileNotFoundError. But when the .txt file is copied to the path where…
Varsha
  • 55
  • 1
  • 9
2
votes
1 answer

Using Mypy with `.pyi` stub files

Lets say I have a simple function inside the file home/func.py, and I make one call to it. def f(x): return x print(f("example")) Now lets say I want to type check this function using a stub, home/stubs/func.pyi which looks like: def f(x: int):…
j-hil
  • 115
  • 10
2
votes
1 answer

How to create Python Stub Files and where to put?

I have a compiled a Python extension. The resulting binary mylib.so file can be imported in the Python script and works fine. Now I am wondering how to write the interface stub file mylib.pyi such, that pylint and the Python language server used in…
Matthias
  • 1,055
  • 2
  • 14
  • 26
1
vote
1 answer

Why there spread operator (...) is use in the .pyi file in the function definition?

I often encounter spread (...) in the source code of many programs. I google about it but I did not find any relevant answer. I am wondering why spread operator are use in the file. Here is the example. class HelpFormatter: def __init__(self,…
1
vote
1 answer

xmlsec is broken in new version due to __init__.pyi file

I was using xmlsec in my project, which was using latest release, with new release today, it's failing. # .tox/unittest/bin/pip install xmlsec Collecting xmlsec Using cached xmlsec-1.3.7.tar.gz (59 kB) …
Nilesh
  • 20,521
  • 16
  • 92
  • 148
1
vote
0 answers

Exclude *.pyd files from go to definition (with ctrl+click)

I have a small problem with my Eclipse IDE PyDev plugin - when I'm developing a program using Python with libraries in *.pyd format, I can't go to definition, because It's binary format. But there are corresponding *.pyi files with source code. How…
KhazAkar
  • 11
  • 2
1
vote
1 answer

What's the underlying implementation for most_common method of Counter?

I found a pyi file which has the following def def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... How could this happen? List is not defined, and no implementation? Just highlight some valuable suggestions here for…
Pythoner
  • 5,265
  • 5
  • 33
  • 49
1
vote
1 answer

python stub property "Unresolved Attribute Reference" in Class Implementation

I made a Class Interface in my pyi module (scheme.pyi): class Catalog: @property def elements(self) -> List[Element]: ... and in my scheme.py I implemented the class like this: class Catalog: def __init__(self, element_collection): …
0
votes
0 answers

Can not import pyi file

The file structure is like this project --idl --__init__.py --a.thrift --a_thrift.pyi --b.py --main.py in main.py, there is sth like from idl.a_thrift import xxx when running python main.py, it will complain…
shakalaka
  • 151
  • 1
  • 7
0
votes
1 answer

generate visual studio code's like .pyi file

.pyi file in visual studio code (python extension) in my case _csv.pyi file has more details on type hints compared to the .pyi file generated by mypy stubgen for example, in the code below you can see both .pyi file visual studio code…
SinaMobasheri
  • 729
  • 8
  • 17
0
votes
1 answer

flake8 conditional with python version in stub file

I need to support both python 3.8 and versions lower that 3.8, but the package I need to import into my stub (*.pyi) file had different name in <3.8 import sys if sys.version_info.minor < 8: import xyz else: import zyx In general this…
z0idb3rg
  • 461
  • 1
  • 6
  • 12
1
2