ST006: HasPyTyped
Overview
| Property | Value |
|---|---|
| ID | ST006 |
| Name | HasPyTyped |
| Group | structure |
| Severity | NOTE |
Description
Checks that a py.typed marker file exists in the package directory.
The py.typed marker is required by PEP 561 for packages that include inline type annotations to be recognized by type checkers.
What it checks
The check verifies that a py.typed file exists in your package directory:
- For src layout:
src/<package_name>/py.typed - For flat layout:
<package_name>/py.typed
The package name is derived from pyproject.toml, with hyphens converted to underscores.
Why it matters
Without py.typed, type checkers like mypy, pyright, and ty will not use your package’s type annotations:
- Type checking - Users cannot type-check code that uses your package
- IDE support - Autocomplete and type hints may not work properly
- Documentation - Type annotations serve as inline documentation
Example
Without py.typed:
# mypy: error: Skipping analyzing "your_package": module is installed,
# but missing library stubs or py.typed markerWith py.typed:
# mypy uses your package's type annotations
# IDE shows proper type hints and autocompleteHow to fix
Step 1: Create the py.typed file
The file should be empty (or can contain a comment). Create it in your package directory:
For src layout:
touch src/my_package/py.typedFor flat layout:
touch my_package/py.typedStep 2: Ensure it’s included in the distribution
Most build backends include py.typed automatically. If not, add it explicitly:
For Hatchling (pyproject.toml):
[tool.hatch.build.targets.wheel]
include = ["src/my_package/py.typed"]For Setuptools (pyproject.toml):
[tool.setuptools.package-data]
my_package = ["py.typed"]For Setuptools (MANIFEST.in):
include src/my_package/py.typed
Step 3: Verify installation
After installing your package:
pip install -e .
python -c "import my_package; import pathlib; print(pathlib.Path(my_package.__file__).parent / 'py.typed')"Check that the py.typed file exists at the printed path.
When to skip this check
You may want to skip this check if:
- Your package intentionally does not provide type annotations
- Your package uses stub files (
.pyi) distributed separately - You’re targeting Python versions that don’t support type hints
Configuration
Skip this check
[tool.pycmdcheck]
skip = ["ST006"]CLI
pycmdcheck --skip ST006