types-click
types-click is a PEP 561 type stub package providing external type annotations for the popular Click library. It allows type-checking tools like MyPy, PyCharm, and Pyright to analyze code that uses Click, enabling static analysis, type inference, and autocompletion. Maintained as part of the broader typeshed project, its releases generally follow the versions of the Click library it stubs, with an additional datestamp suffix.
Warnings
- breaking Click versions 8.0 and newer include inline type annotations. If you are using `click` version 8.0 or later, `types-click` is no longer necessary and should be uninstalled. Installing both can lead to type checking conflicts or incorrect type information.
- gotcha The `types-click` package provides stubs for specific versions of the `click` library. While its version attempts to match the `click` version (e.g., `types-click==7.1.x` for `click==7.1.x`), discrepancies can occur. Using `types-click` with a significantly different `click` version than it was designed for can lead to inaccurate or misleading type checking results.
- gotcha As a PEP 561 stub-only package, `types-click` contains no runtime code. It only provides `.pyi` files for type checkers. Attempting to import symbols directly from `types_click` at runtime will result in a `ModuleNotFoundError`.
Install
-
pip install types-click
Imports
- click
import click
- command
from click import command, option
Quickstart
import click
@click.command()
@click.option('--name', default='World', help='The name to greet.')
@click.option('--count', default=1, type=int, help='Number of greetings.')
@click.argument('message', default='Hello', type=str)
def greet(name: str, count: int, message: str):
"""
Simple program that greets NAME for COUNT times with a MESSAGE.
"""
for _ in range(count):
click.echo(f"{message}, {name}!")
if __name__ == '__main__':
# Type checkers will use types-click for 'click' objects and functions.
greet() # type: ignore