5

I'm splitting my code into multiple packages, which are installable via PyPI. Then these packages are used in a child package, where I want type information from "library" packages to be fully used. In order to have complete type checking, I'd like to use pyright / pylance, locally and in CI.

What is the recommended way to document types for a python library? I'm currently partially annotating types in the source code. Do I have to provide stubs? When using my library in other project, I get warnings like Stub file not found in vscode.

Specific questions:

  1. Is having stubs a must for a python library if I want users to have access to typing?
  2. Do stubs take precedence over source code of library if both have types?
Boschie
  • 467
  • 3
  • 13

1 Answers1

3

I have an answer for 1.; you don't have to have a stub file. If your library includes a file named exactly py.typed, then everything in the same folder and it's children is proclaimed to be typed.

References:

  1. https://peps.python.org/pep-0561/
  2. https://blog.whtsky.me/tech/2021/dont-forget-py.typed-for-your-typed-python-package/
Yodogawa Mikio
  • 413
  • 3
  • 9